11<?php
22namespace net \authorize \util ;
33
4+ use JMS \Serializer \SerializerBuilder ;
5+
46define ("ANET_SENSITIVE_XMLTAGS_JSON_FILE " ,"AuthorizedNetSensitiveTagsConfig.json " );
7+ define ("ANET_SENSITIVE_DATE_CONFIG_CLASS " ,'net\authorize\util\SensitiveDataConfigType ' );
58
69class ANetSensitiveFields
710{
811 private static $ applySensitiveTags = NULL ;
912 private static $ sensitiveStringRegexes = NULL ;
1013
1114 private static function fetchFromConfigFiles (){
12- $ configFilePath = dirname (__FILE__ ) . "/ " . ANET_SENSITIVE_XMLTAGS_JSON_FILE ;
15+ if (!class_exists (ANET_SENSITIVE_DATE_CONFIG_CLASS ))
16+ exit ("Class ( " .ANET_SENSITIVE_DATE_CONFIG_CLASS .") doesn't exist; can't deserialize json; can't log. Exiting. " );
17+
18+ $ serializer = SerializerBuilder::create ()->build ();
19+
1320 $ userConfigFile = ANET_SENSITIVE_XMLTAGS_JSON_FILE ;
21+ $ configFilePath = dirname (__FILE__ ) . "/ " . ANET_SENSITIVE_XMLTAGS_JSON_FILE ;
22+
1423 $ presentUserConfigFile = file_exists ($ userConfigFile );
24+ $ useDefaultConfigFile = !$ presentUserConfigFile ;
1525 if ($ presentUserConfigFile ) { //client config for tags
16- //read list of tags(and associate regex-patterns and replacements) from .json file
17- $ jsonFileObejct = json_decode (file_get_contents ($ userConfigFile ));
18- $ sensitiveTags = $ jsonFileObejct ->sensitiveTags ;
19- self ::$ sensitiveStringRegexes = $ jsonFileObejct ->sensitiveStringRegexes ;
26+ //read list of tags (and associated regex-patterns and replacements) from .json file
27+ $ jsonFileData =file_get_contents ($ userConfigFile );
28+ $ sensitiveDataConfig = $ serializer ->deserialize ($ jsonFileData , ANET_SENSITIVE_DATE_CONFIG_CLASS , 'json ' );
29+
30+ $ sensitiveTags = $ sensitiveDataConfig ->sensitiveTags ;
31+ self ::$ sensitiveStringRegexes = $ sensitiveDataConfig ->sensitiveStringRegexes ;
32+
2033 if (json_last_error () === JSON_ERROR_NONE ) {// JSON is valid
2134 }
2235 else {
2336 echo "ERROR: Invalid json in: " . $ userConfigFile . " json_last_error_msg : " . json_last_error_msg ();
24- $ presentUserConfigFile = false ;
37+ $ useDefaultConfigFile = true ;
2538 }
2639 }
27- if (!$ presentUserConfigFile ) { //default sdk config for tags
40+
41+ if ($ useDefaultConfigFile ) { //default sdk config for tags
2842 if (!file_exists ($ configFilePath )){
2943 exit ("ERROR: No config file: " . $ configFilePath );
3044 }
31- $ jsonFileObejct = json_decode (file_get_contents ($ configFilePath ));
32- $ sensitiveTags = $ jsonFileObejct ->sensitiveTags ;
33- self ::$ sensitiveStringRegexes = $ jsonFileObejct ->sensitiveStringRegexes ;
45+
46+ //read list of tags (and associated regex-patterns and replacements) from .json file
47+ $ jsonFileData =file_get_contents ($ configFilePath );
48+ $ sensitiveDataConfig = $ serializer ->deserialize ($ jsonFileData , ANET_SENSITIVE_DATE_CONFIG_CLASS , 'json ' );
49+
50+ $ sensitiveTags = $ sensitiveDataConfig ->sensitiveTags ;
51+ self ::$ sensitiveStringRegexes = $ sensitiveDataConfig ->sensitiveStringRegexes ;
52+
3453 if (json_last_error () === JSON_ERROR_NONE ) {
3554 }
3655 else {
3756 exit ("ERROR: Invalid json in: " . $ configFilePath . " json_last_error_msg : " . json_last_error_msg ());
3857 }
3958 }
59+
4060 //Check for disableMask flag in case of client json.
4161 self ::$ applySensitiveTags = array ();
4262 foreach ($ sensitiveTags as $ sensitiveTag ){
@@ -48,12 +68,14 @@ private static function fetchFromConfigFiles(){
4868 }
4969 }
5070 }
71+
5172 public static function getSensitiveStringRegexes (){
5273 if (NULL == self ::$ sensitiveStringRegexes ) {
5374 self ::fetchFromConfigFiles ();
5475 }
5576 return self ::$ sensitiveStringRegexes ;
5677 }
78+
5779 public static function getSensitiveXmlTags (){
5880 if (NULL == self ::$ applySensitiveTags ) {
5981 self ::fetchFromConfigFiles ();
0 commit comments