1
|
|
|
<?php |
2
|
|
|
namespace net\authorize\util; |
3
|
|
|
|
4
|
|
|
use JMS\Serializer\SerializerBuilder; |
5
|
|
|
|
6
|
1 |
|
define("ANET_SENSITIVE_XMLTAGS_JSON_FILE","AuthorizedNetSensitiveTagsConfig.json"); |
7
|
1 |
|
define("ANET_SENSITIVE_DATE_CONFIG_CLASS",'net\authorize\util\SensitiveDataConfigType'); |
8
|
|
|
|
9
|
|
|
class ANetSensitiveFields |
10
|
|
|
{ |
11
|
|
|
private static $applySensitiveTags = NULL; |
12
|
|
|
private static $sensitiveStringRegexes = NULL; |
13
|
|
|
|
14
|
1 |
|
private static function fetchFromConfigFiles(){ |
15
|
1 |
|
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
|
1 |
|
$serializer = SerializerBuilder::create()->build(); |
19
|
|
|
|
20
|
1 |
|
$userConfigFilePath = ANET_SENSITIVE_XMLTAGS_JSON_FILE; |
21
|
1 |
|
$presentUserConfigFile = file_exists($userConfigFilePath); |
22
|
|
|
|
23
|
1 |
|
$configFilePath = dirname(__FILE__) . "/" . ANET_SENSITIVE_XMLTAGS_JSON_FILE; |
24
|
1 |
|
$useDefaultConfigFile = !$presentUserConfigFile; |
25
|
|
|
|
26
|
1 |
|
if ($presentUserConfigFile) { //client config for tags |
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; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
catch(Exception $e){ |
|
|
|
|
37
|
|
|
echo "ERROR deserializing json from : " . $userConfigFilePath . "; Exception : " . $e->getMessage(); |
38
|
|
|
$useDefaultConfigFile = true; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
if ($useDefaultConfigFile) { //default sdk config for tags |
43
|
1 |
|
if(!file_exists($configFilePath)){ |
44
|
|
|
exit("ERROR: No config file: " . $configFilePath); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
//read list of tags (and associated regex-patterns and replacements) from .json file |
48
|
|
|
try{ |
49
|
1 |
|
$jsonFileData=file_get_contents($configFilePath); |
50
|
1 |
|
$sensitiveDataConfig = $serializer->deserialize($jsonFileData, ANET_SENSITIVE_DATE_CONFIG_CLASS, 'json'); |
51
|
|
|
|
52
|
1 |
|
$sensitiveTags = $sensitiveDataConfig->sensitiveTags; |
53
|
1 |
|
self::$sensitiveStringRegexes = $sensitiveDataConfig->sensitiveStringRegexes; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
catch(Exception $e){ |
|
|
|
|
57
|
|
|
exit( "ERROR deserializing json from : " . $configFilePath . "; Exception : " . $e->getMessage()); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
//Check for disableMask flag in case of client json. |
62
|
1 |
|
self::$applySensitiveTags = array(); |
63
|
1 |
|
foreach($sensitiveTags as $sensitiveTag){ |
|
|
|
|
64
|
1 |
|
if($sensitiveTag->disableMask){ |
|
|
|
|
65
|
|
|
//skip masking continue; |
66
|
|
|
} |
67
|
|
|
else{ |
68
|
1 |
|
array_push(self::$applySensitiveTags,$sensitiveTag); |
69
|
|
|
} |
70
|
|
|
} |
71
|
1 |
|
} |
72
|
|
|
|
73
|
1 |
|
public static function getSensitiveStringRegexes(){ |
74
|
1 |
|
if(NULL == self::$sensitiveStringRegexes) { |
75
|
|
|
self::fetchFromConfigFiles(); |
76
|
|
|
} |
77
|
1 |
|
return self::$sensitiveStringRegexes; |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
public static function getSensitiveXmlTags(){ |
81
|
1 |
|
if(NULL == self::$applySensitiveTags) { |
82
|
1 |
|
self::fetchFromConfigFiles(); |
83
|
|
|
} |
84
|
1 |
|
return self::$applySensitiveTags; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.