Skip to content

Commit 9dd3c27

Browse files
authored
Merge pull request #147 from AuthorizeNet/future
Changes for Release 1.9.8
2 parents 46bd7a1 + 574d1ff commit 9dd3c27

File tree

4 files changed

+47
-37
lines changed

4 files changed

+47
-37
lines changed

.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
1313
<classpathentry kind="lib" path="lib/hamcrest-library-1.3.jar"/>
1414
<classpathentry kind="lib" path="lib/jmock-2.6.0.jar"/>
15+
<classpathentry kind="lib" path="lib/gson-2.3.1.jar" />
1516
<classpathentry kind="output" path="target/classes"/>
1617
</classpath>

lib/gson-2.3.1.jar

206 KB
Binary file not shown.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<groupId>com.google.code.gson</groupId>
8686
<artifactId>gson</artifactId>
8787
<version>2.3.1</version>
88+
<scope>compile</scope>
8889
</dependency>
8990
</dependencies>
9091
<properties>

src/main/java/net/authorize/util/SensitiveFilterLayout.java

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,56 @@ public class SensitiveFilterLayout extends PatternLayout{
2424
private static Gson gson;
2525

2626
public SensitiveFilterLayout() throws UnsupportedEncodingException, FileNotFoundException, IOException {
27-
GsonBuilder gsonBuilder = new GsonBuilder();
28-
gsonBuilder.registerTypeAdapter(SensitiveDataConfigType.class, new SensitiveTagsDeserializer());
29-
gson = gsonBuilder.create();
30-
31-
InputStream in = getClass().getResourceAsStream("/AuthorizedNetSensitiveTagsConfig.json");
32-
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
33-
SensitiveDataConfigType configType = gson.fromJson(reader, SensitiveDataConfigType.class);
34-
cardPatterns = new Pattern[configType.sensitiveStringRegexes.length];
27+
try {
28+
GsonBuilder gsonBuilder = new GsonBuilder();
29+
gsonBuilder.registerTypeAdapter(SensitiveDataConfigType.class, new SensitiveTagsDeserializer());
30+
gson = gsonBuilder.create();
31+
32+
InputStream in = getClass().getResourceAsStream("/AuthorizedNetSensitiveTagsConfig.json");
33+
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
34+
SensitiveDataConfigType configType = gson.fromJson(reader, SensitiveDataConfigType.class);
35+
cardPatterns = new Pattern[configType.sensitiveStringRegexes.length];
3536

36-
for(int i = 0; i < configType.sensitiveStringRegexes.length; i++) {
37-
cardPatterns[i] = Pattern.compile(configType.sensitiveStringRegexes[i]);
38-
}
39-
40-
int noOfSensitiveTags = configType.sensitiveTags.length;
41-
tagPatterns = new Pattern[noOfSensitiveTags];
42-
tagReplacements = new String[noOfSensitiveTags];
43-
44-
for(int j=0; j<noOfSensitiveTags; j++) {
45-
String tagName = configType.sensitiveTags[j].tagName;
46-
String pattern = configType.sensitiveTags[j].pattern;
47-
String replacement = configType.sensitiveTags[j].replacement;
48-
49-
if(pattern != null && !pattern.isEmpty())
50-
tagPatterns[j] = Pattern.compile("<"+tagName+">"+pattern+"</"+tagName+">");
51-
else
52-
tagPatterns[j] = Pattern.compile("<"+tagName+">"+".+"+"</"+tagName+">");
53-
tagReplacements[j] = "<"+tagName+">"+replacement+"</"+tagName+">";
54-
}
55-
if(reader!=null)
56-
reader.close();
37+
for(int i = 0; i < configType.sensitiveStringRegexes.length; i++) {
38+
cardPatterns[i] = Pattern.compile(configType.sensitiveStringRegexes[i]);
39+
}
40+
41+
int noOfSensitiveTags = configType.sensitiveTags.length;
42+
tagPatterns = new Pattern[noOfSensitiveTags];
43+
tagReplacements = new String[noOfSensitiveTags];
44+
45+
for(int j=0; j<noOfSensitiveTags; j++) {
46+
String tagName = configType.sensitiveTags[j].tagName;
47+
String pattern = configType.sensitiveTags[j].pattern;
48+
String replacement = configType.sensitiveTags[j].replacement;
49+
50+
if(pattern != null && !pattern.isEmpty())
51+
tagPatterns[j] = Pattern.compile("<"+tagName+">"+pattern+"</"+tagName+">");
52+
else
53+
tagPatterns[j] = Pattern.compile("<"+tagName+">"+".+"+"</"+tagName+">");
54+
tagReplacements[j] = "<"+tagName+">"+replacement+"</"+tagName+">";
55+
}
56+
if(reader!=null)
57+
reader.close();
58+
}
59+
catch(Exception e){
60+
}
5761
}
5862

5963
@Override
6064
public String format(LoggingEvent event) {
61-
if(event.getMessage() instanceof String) {
62-
String message = event.getRenderedMessage();
63-
String maskXmlMessage = SensitiveFilterLayout.maskSensitiveXmlString(message);
64-
String maskCardNumber = SensitiveFilterLayout.maskCreditCards(maskXmlMessage);
65-
66-
Throwable throwable = event.getThrowableInformation() != null ? event.getThrowableInformation().getThrowable() : null;
67-
LoggingEvent maskedEvent = new LoggingEvent(event.fqnOfCategoryClass, Logger.getLogger(event.getLoggerName()), event.timeStamp, event.getLevel(), maskCardNumber, throwable);
68-
return super.format(maskedEvent);
65+
try {
66+
if(event.getMessage() instanceof String) {
67+
String message = event.getRenderedMessage();
68+
String maskXmlMessage = SensitiveFilterLayout.maskSensitiveXmlString(message);
69+
String maskCardNumber = SensitiveFilterLayout.maskCreditCards(maskXmlMessage);
70+
71+
Throwable throwable = event.getThrowableInformation() != null ? event.getThrowableInformation().getThrowable() : null;
72+
LoggingEvent maskedEvent = new LoggingEvent(event.fqnOfCategoryClass, Logger.getLogger(event.getLoggerName()), event.timeStamp, event.getLevel(), maskCardNumber, throwable);
73+
return super.format(maskedEvent);
74+
}
75+
}
76+
catch(Exception e){
6977
}
7078
return null;
7179
}

0 commit comments

Comments
 (0)