-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0053498
commit d6f17ad
Showing
22 changed files
with
1,222 additions
and
827 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
24 changes: 22 additions & 2 deletions
24
...liance-logging-common/src/main/java/com/slalom/logging/compliance/common/MaskService.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 |
---|---|---|
@@ -1,5 +1,25 @@ | ||
/** | ||
* MIT License | ||
* | ||
* <p>Copyright (c) 2020 Slalom LLC | ||
* | ||
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* <p>The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package com.slalom.logging.compliance.common; | ||
|
||
public interface MaskService { | ||
String maskMessage(String message); | ||
} | ||
String maskMessage(String message); | ||
} |
28 changes: 24 additions & 4 deletions
28
compliance-logging-common/src/main/java/com/slalom/logging/compliance/common/MaskType.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 |
---|---|---|
@@ -1,11 +1,31 @@ | ||
/** | ||
* MIT License | ||
* | ||
* <p>Copyright (c) 2020 Slalom LLC | ||
* | ||
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* <p>The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package com.slalom.logging.compliance.common; | ||
|
||
import org.slf4j.Marker; | ||
import org.slf4j.MarkerFactory; | ||
|
||
public class MaskType { | ||
public static String JSON_MARKER_NAME = "JSON-COMPLIANCE"; | ||
public static String LOMBOK_MARKER_NAME = "LOMBOK-COMPLIANCE"; | ||
public static Marker JSON = MarkerFactory.getMarker(JSON_MARKER_NAME); | ||
public static Marker LOMBOK = MarkerFactory.getMarker(LOMBOK_MARKER_NAME); | ||
public static String JSON_MARKER_NAME = "JSON-COMPLIANCE"; | ||
public static String LOMBOK_MARKER_NAME = "LOMBOK-COMPLIANCE"; | ||
public static Marker JSON = MarkerFactory.getMarker(JSON_MARKER_NAME); | ||
public static Marker LOMBOK = MarkerFactory.getMarker(LOMBOK_MARKER_NAME); | ||
} |
58 changes: 39 additions & 19 deletions
58
...gging-common/src/main/java/com/slalom/logging/compliance/common/impl/AbstractService.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 |
---|---|---|
@@ -1,32 +1,52 @@ | ||
/** | ||
* MIT License | ||
* | ||
* <p>Copyright (c) 2020 Slalom LLC | ||
* | ||
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* <p>The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package com.slalom.logging.compliance.common.impl; | ||
|
||
import com.slalom.logging.compliance.common.MaskService; | ||
|
||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
abstract class AbstractService implements MaskService { | ||
|
||
protected static final String DEFAULT_MASK = "***********"; | ||
protected static final String DEFAULT_MASK = "***********"; | ||
|
||
protected final String fieldRegex; | ||
protected final String fieldRegex; | ||
|
||
protected AbstractService(final List<String> fields) { | ||
fieldRegex = String.join("|", fields); | ||
} | ||
protected AbstractService(final List<String> fields) { | ||
fieldRegex = String.join("|", fields); | ||
} | ||
|
||
protected String maskMessage(final String message, final Pattern pattern, final String replacementRegex) { | ||
try { | ||
final StringBuffer buffer = new StringBuffer(); | ||
final Matcher matcher = pattern.matcher(message); | ||
while (matcher.find()) { | ||
matcher.appendReplacement(buffer, replacementRegex); | ||
} | ||
matcher.appendTail(buffer); | ||
return buffer.toString(); | ||
} catch (Exception e) { | ||
return message; | ||
} | ||
protected String maskMessage( | ||
final String message, final Pattern pattern, final String replacementRegex) { | ||
try { | ||
final StringBuffer buffer = new StringBuffer(); | ||
final Matcher matcher = pattern.matcher(message); | ||
while (matcher.find()) { | ||
matcher.appendReplacement(buffer, replacementRegex); | ||
} | ||
matcher.appendTail(buffer); | ||
return buffer.toString(); | ||
} catch (Exception e) { | ||
return message; | ||
} | ||
} | ||
} | ||
} |
42 changes: 31 additions & 11 deletions
42
...gging-common/src/main/java/com/slalom/logging/compliance/common/impl/JsonMaskService.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 |
---|---|---|
@@ -1,22 +1,42 @@ | ||
/** | ||
* MIT License | ||
* | ||
* <p>Copyright (c) 2020 Slalom LLC | ||
* | ||
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* <p>The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package com.slalom.logging.compliance.common.impl; | ||
|
||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
public class JsonMaskService extends AbstractService { | ||
|
||
private static final String JSON_REPLACEMENT_REGEX = "\"$1\":$2\"" + DEFAULT_MASK + "\""; | ||
private static final String JSON_PATTERN = "\"(%s)\":([ ]*)\"([^\"]+)\""; | ||
private static final String JSON_REPLACEMENT_REGEX = "\"$1\":$2\"" + DEFAULT_MASK + "\""; | ||
private static final String JSON_PATTERN = "\"(%s)\":([ ]*)\"([^\"]+)\""; | ||
|
||
private final Pattern pattern; | ||
private final Pattern pattern; | ||
|
||
public JsonMaskService(final List<String> fields) { | ||
super(fields); | ||
this.pattern = Pattern.compile(String.format(JSON_PATTERN, fieldRegex)); | ||
} | ||
public JsonMaskService(final List<String> fields) { | ||
super(fields); | ||
this.pattern = Pattern.compile(String.format(JSON_PATTERN, fieldRegex)); | ||
} | ||
|
||
@Override | ||
public String maskMessage(String message) { | ||
return maskMessage(message, pattern, JSON_REPLACEMENT_REGEX); | ||
} | ||
@Override | ||
public String maskMessage(String message) { | ||
return maskMessage(message, pattern, JSON_REPLACEMENT_REGEX); | ||
} | ||
} |
44 changes: 32 additions & 12 deletions
44
...ing-common/src/main/java/com/slalom/logging/compliance/common/impl/LombokMaskService.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 |
---|---|---|
@@ -1,22 +1,42 @@ | ||
/** | ||
* MIT License | ||
* | ||
* <p>Copyright (c) 2020 Slalom LLC | ||
* | ||
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* <p>The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package com.slalom.logging.compliance.common.impl; | ||
|
||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
public class LombokMaskService extends AbstractService { | ||
|
||
private static final String LOMBOK_REPLACEMENT_REGEX = "$1=" + DEFAULT_MASK + "$3"; | ||
private static final String LOMBOK_PATTERN = "(%s)=([^\"]+?(, |\\)))"; | ||
private static final String LOMBOK_REPLACEMENT_REGEX = "$1=" + DEFAULT_MASK + "$3"; | ||
private static final String LOMBOK_PATTERN = "(%s)=([^\"]+?(, |\\)))"; | ||
|
||
private final Pattern pattern; | ||
private final Pattern pattern; | ||
|
||
public LombokMaskService(List<String> fields) { | ||
super(fields); | ||
this.pattern = Pattern.compile(String.format(LOMBOK_PATTERN, fieldRegex)); | ||
} | ||
public LombokMaskService(List<String> fields) { | ||
super(fields); | ||
this.pattern = Pattern.compile(String.format(LOMBOK_PATTERN, fieldRegex)); | ||
} | ||
|
||
@Override | ||
public String maskMessage(String message) { | ||
return maskMessage(message, pattern, LOMBOK_REPLACEMENT_REGEX); | ||
} | ||
} | ||
@Override | ||
public String maskMessage(String message) { | ||
return maskMessage(message, pattern, LOMBOK_REPLACEMENT_REGEX); | ||
} | ||
} |
Oops, something went wrong.