Skip to content

Commit 472f1b6

Browse files
committed
Merge with Future branch.
Conflicts: lib/net/authorize/util/ANetSensitiveFields.php
2 parents c89c21c + 572d2c5 commit 472f1b6

3 files changed

Lines changed: 33 additions & 22 deletions

File tree

lib/net/authorize/api/controller/base/ApiOperationBase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use \net\authorize\util\HttpClient;
1111
use \net\authorize\util\Helpers;
1212
use \net\authorize\util\LogFactory as LogFactory;
13-
//use \net\authorize\util\LogHelper;
14-
use \net\authorize\util\Log;
1513

1614

1715
abstract class ApiOperationBase implements IApiOperation

lib/net/authorize/util/ANetSensitiveFields.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ private static function fetchFromConfigFiles(){
1616
exit("Class (".ANET_SENSITIVE_DATE_CONFIG_CLASS.") doesn't exist; can't deserialize json; can't log. Exiting.");
1717

1818
$serializer = SerializerBuilder::create()->build();
19+
20+
$userConfigFilePath = ANET_SENSITIVE_XMLTAGS_JSON_FILE;
21+
$presentUserConfigFile = file_exists($userConfigFilePath);
1922

20-
$userConfigFile = ANET_SENSITIVE_XMLTAGS_JSON_FILE;
2123
$configFilePath = dirname(__FILE__) . "/" . ANET_SENSITIVE_XMLTAGS_JSON_FILE;
22-
23-
$presentUserConfigFile = file_exists($userConfigFile);
2424
$useDefaultConfigFile = !$presentUserConfigFile;
25+
2526
if ($presentUserConfigFile) { //client config for tags
2627
//read list of tags (and associated regex-patterns and replacements) from .json file
27-
$jsonFileData=file_get_contents($userConfigFile);
28+
$jsonFileData=file_get_contents($userConfigFilePath);
2829
$sensitiveDataConfig = $serializer->deserialize($jsonFileData, ANET_SENSITIVE_DATE_CONFIG_CLASS, 'json');
2930

3031
$sensitiveTags = $sensitiveDataConfig->sensitiveTags;
@@ -33,7 +34,7 @@ private static function fetchFromConfigFiles(){
3334
if (json_last_error() === JSON_ERROR_NONE) {// JSON is valid
3435
}
3536
else{
36-
echo "ERROR: Invalid json in: " . $userConfigFile . " json_last_error_msg : " . json_last_error_msg();
37+
echo "ERROR: Invalid json in: " . $userConfigFilePath . " json_last_error_msg : " . json_last_error_msg();
3738
$useDefaultConfigFile = true;
3839
}
3940
}

lib/net/authorize/util/Log.php

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function getPropertiesInclBase($reflClass)
132132
}
133133

134134
/**
135-
* private function checkAndMask($prop, $obj).
135+
* private function checkPropertyAndMask($prop, $obj).
136136
*
137137
* Receives a ReflectionProperty and an object, and returns a masked object if the ReflectionProperty corresponds to a sensitive field, else returns false.
138138
*
@@ -141,22 +141,22 @@ private function getPropertiesInclBase($reflClass)
141141
*
142142
* @return string|bool
143143
*/
144-
private function checkAndMask($prop, $obj){
145-
foreach($this->sensitiveXmlTags as $i => $sensitiveTag)
144+
private function checkPropertyAndMask($prop, $obj){
145+
foreach($this->sensitiveXmlTags as $i => $sensitiveField)
146146
{
147147
$inputPattern = "(.+)";
148148
$inputReplacement = "xxxx";
149149

150-
if(trim($sensitiveTag->pattern)) {
151-
$inputPattern = $sensitiveTag->pattern;
150+
if(trim($sensitiveField->pattern)) {
151+
$inputPattern = $sensitiveField->pattern;
152152
}
153153
$inputPattern = $this->addDelimiterFwdSlash($inputPattern);
154154

155-
if(trim($sensitiveTag->replacement)) {
156-
$inputReplacement = $sensitiveTag->replacement;
155+
if(trim($sensitiveField->replacement)) {
156+
$inputReplacement = $sensitiveField->replacement;
157157
}
158158

159-
if(strcmp($prop->getName(),$sensitiveTag->tagName)==0)
159+
if(strcmp($prop->getName(),$sensitiveField->tagName)==0)
160160
{
161161
$prop->setValue($obj,preg_replace($inputPattern,$inputReplacement,$prop->getValue($obj)));
162162
return $prop->getValue($obj);
@@ -196,7 +196,7 @@ private function maskSensitiveProperties ($obj)
196196
}
197197
// else check if the property represents a sensitive field. If so, mask.
198198
else{
199-
$res=$this->checkAndMask($prop, $obj);
199+
$res=$this->checkPropertyAndMask($prop, $obj);
200200
if($res)
201201
$prop->setValue($obj, $res);
202202
}
@@ -222,15 +222,27 @@ private function getMasked($raw)
222222
{ //always returns string
223223
$messageType = gettype($raw);
224224
$message="";
225-
if ($messageType == "string") {
226-
$maskedXml = $this->maskSensitiveXmlString($raw);
227-
//mask credit card numbers
228-
$message = $this->maskCreditCards($maskedXml);
229-
}
230-
else if($messageType == "object"){
225+
if($messageType == "object"){
231226
$obj = unserialize(serialize($raw)); // deep copying the object
232227
$message = print_r($this->maskSensitiveProperties($obj), true); //object to string
233228
}
229+
else if($messageType == "array"){
230+
$copyArray = unserialize(serialize($raw));
231+
foreach($copyArray as $i => $element){
232+
$copyArray[$i] = $this->getMasked($element);
233+
}
234+
$message = print_r($copyArray, true); // returns string
235+
}
236+
else { //$messageType == "string")
237+
$primtiveTypeAsString = strval($raw);
238+
239+
$maskedXml = $primtiveTypeAsString;
240+
if($messageType == "string") {
241+
$maskedXml = $this->maskSensitiveXmlString($primtiveTypeAsString);
242+
}
243+
//mask credit card numbers
244+
$message = $this->maskCreditCards($maskedXml);
245+
}
234246
return $message;
235247
}
236248

0 commit comments

Comments
 (0)