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 $ userConfigFilePath = ANET_SENSITIVE_XMLTAGS_JSON_FILE ;
1421 $ presentUserConfigFile = file_exists ($ userConfigFilePath );
22+
23+ $ configFilePath = dirname (__FILE__ ) . "/ " . ANET_SENSITIVE_XMLTAGS_JSON_FILE ;
24+ $ useDefaultConfigFile = !$ presentUserConfigFile ;
25+
1526 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 ($ userConfigFilePath ));
18- $ sensitiveTags = $ jsonFileObejct ->sensitiveTags ;
19- self ::$ sensitiveStringRegexes = $ jsonFileObejct ->sensitiveStringRegexes ;
20- if (json_last_error () === JSON_ERROR_NONE ) {// JSON is valid
27+ //read list of tags (and associated regex-patterns and replacements) from .json file
28+ try {
29+ $ jsonFileData =file_get_contents ($ userConfigFilePath );
30+ $ sensitiveDataConfig = $ serializer ->deserialize ($ jsonFileData , ANET_SENSITIVE_DATE_CONFIG_CLASS , 'json ' );
31+
32+ $ sensitiveTags = $ sensitiveDataConfig ->sensitiveTags ;
33+ self ::$ sensitiveStringRegexes = $ sensitiveDataConfig ->sensitiveStringRegexes ;
2134 }
22- else {
23- echo "ERROR: Invalid json in: " . $ userConfigFilePath . " json_last_error_msg : " . json_last_error_msg ();
24- $ presentUserConfigFile = false ;
35+
36+ catch (Exception $ e ){
37+ echo "ERROR deserializing json from : " . $ userConfigFilePath . "; Exception : " . $ e ->getMessage ();
38+ $ useDefaultConfigFile = true ;
2539 }
2640 }
27- if (!$ presentUserConfigFile ) { //default sdk config for tags
41+
42+ if ($ useDefaultConfigFile ) { //default sdk config for tags
2843 if (!file_exists ($ configFilePath )){
2944 exit ("ERROR: No config file: " . $ configFilePath );
3045 }
31- $ jsonFileObejct = json_decode (file_get_contents ($ configFilePath ));
32- file_put_contents ($ userConfigFilePath , json_encode ($ jsonFileObejct , JSON_PRETTY_PRINT ));
33- $ sensitiveTags = $ jsonFileObejct ->sensitiveTags ;
34- self ::$ sensitiveStringRegexes = $ jsonFileObejct ->sensitiveStringRegexes ;
35- if (json_last_error () === JSON_ERROR_NONE ) {
46+
47+ //read list of tags (and associated regex-patterns and replacements) from .json file
48+ try {
49+ $ jsonFileData =file_get_contents ($ configFilePath );
50+ $ sensitiveDataConfig = $ serializer ->deserialize ($ jsonFileData , ANET_SENSITIVE_DATE_CONFIG_CLASS , 'json ' );
51+
52+ $ sensitiveTags = $ sensitiveDataConfig ->sensitiveTags ;
53+ self ::$ sensitiveStringRegexes = $ sensitiveDataConfig ->sensitiveStringRegexes ;
3654 }
37- else {
38- exit ("ERROR: Invalid json in: " . $ configFilePath . " json_last_error_msg : " . json_last_error_msg ());
55+
56+ catch (Exception $ e ){
57+ exit ( "ERROR deserializing json from : " . $ configFilePath . "; Exception : " . $ e ->getMessage ());
3958 }
4059 }
60+
4161 //Check for disableMask flag in case of client json.
4262 self ::$ applySensitiveTags = array ();
4363 foreach ($ sensitiveTags as $ sensitiveTag ){
@@ -49,12 +69,14 @@ private static function fetchFromConfigFiles(){
4969 }
5070 }
5171 }
72+
5273 public static function getSensitiveStringRegexes (){
5374 if (NULL == self ::$ sensitiveStringRegexes ) {
5475 self ::fetchFromConfigFiles ();
5576 }
5677 return self ::$ sensitiveStringRegexes ;
5778 }
79+
5880 public static function getSensitiveXmlTags (){
5981 if (NULL == self ::$ applySensitiveTags ) {
6082 self ::fetchFromConfigFiles ();
0 commit comments