-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature]add mask key/value pair header value with secureParameterConfig
added other overload for HttpFeignClientLogger in AbstractFeignConfiguration. added httpReplaceHelperDecider for mask key/value pair header value. create bean of httpReplaceHelperDecider and use this new HttpFeignClientLogger overload and inject this bean to mask key/value pair header value.
- Loading branch information
A.Alimohammadi
authored and
A.Alimohammadi
committed
Nov 15, 2023
1 parent
81c96de
commit 836c57f
Showing
6 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ot-starter/src/main/java/com/tosan/client/http/starter/util/HttpReplaceHelperDecider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.tosan.client.http.starter.util; | ||
|
||
import com.tosan.tools.mask.starter.config.SecureParametersConfig; | ||
|
||
/** | ||
* @author Ali Alimohammadi | ||
* @since 11/15/2023 | ||
*/ | ||
public class HttpReplaceHelperDecider { | ||
|
||
private final KeyValueReplaceHelper keyValueReplaceHelper; | ||
private final SecureParametersConfig secureParametersConfig; | ||
|
||
public HttpReplaceHelperDecider(KeyValueReplaceHelper keyValueReplaceHelper, | ||
SecureParametersConfig secureParametersConfig) { | ||
this.keyValueReplaceHelper = keyValueReplaceHelper; | ||
this.secureParametersConfig = secureParametersConfig; | ||
} | ||
|
||
public String keyValueHeaderReplace(String keyValueString) { | ||
try { | ||
return this.keyValueReplaceHelper.replace(keyValueString, this.secureParametersConfig.getSecuredParametersMap()); | ||
} catch (Exception e) { | ||
return keyValueString; | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...-boot-starter/src/main/java/com/tosan/client/http/starter/util/KeyValueReplaceHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.tosan.client.http.starter.util; | ||
|
||
import com.tosan.tools.mask.starter.business.ComparisonTypeFactory; | ||
import com.tosan.tools.mask.starter.business.ValueMaskFactory; | ||
import com.tosan.tools.mask.starter.business.enumeration.MaskType; | ||
import com.tosan.tools.mask.starter.config.SecureParameter; | ||
import com.tosan.tools.mask.starter.replace.ReplaceHelper; | ||
|
||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* @author Ali Alimohammadi | ||
* @since 11/14/2023 | ||
*/ | ||
public class KeyValueReplaceHelper extends ReplaceHelper { | ||
|
||
public KeyValueReplaceHelper(ValueMaskFactory valueMaskFactory, ComparisonTypeFactory comparisonTypeFactory) { | ||
super(valueMaskFactory, comparisonTypeFactory); | ||
} | ||
|
||
@Override | ||
public String replace(String input, Map<String, SecureParameter> securedParameterNames) { | ||
Pattern pattern = Pattern.compile("([^\\s;]+)([ ]*[=][ ]*)([^;]+)"); | ||
Matcher matcher = pattern.matcher(input); | ||
|
||
while (matcher.find()) { | ||
String tag = matcher.group(1); | ||
MaskType maskType = this.checkAndGetMaskType(tag, securedParameterNames); | ||
if (maskType != null) { | ||
String originalTag = tag + matcher.group(2) + matcher.group(3); | ||
String value = matcher.group(3); | ||
String toBeReplacedTag; | ||
if (value == null) { | ||
toBeReplacedTag = tag + matcher.group(2) + "null"; | ||
} else { | ||
String maskedValue = this.maskValue(value, maskType); | ||
toBeReplacedTag = tag + matcher.group(2) + maskedValue; | ||
} | ||
|
||
input = input.replace(originalTag, toBeReplacedTag); | ||
} | ||
} | ||
|
||
return input; | ||
} | ||
} |