Skip to content

Commit 2954f64

Browse files
authored
Merge branch 'master' into bugfix/opphoerstidspunkt-etter-gyldighetstidspunkt
2 parents eb84706 + bfb27d2 commit 2954f64

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

libs/reactive-core/src/main/java/no/nav/testnav/libs/reactivecore/logging/TestnavLogbackEncoder.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
public class TestnavLogbackEncoder extends LogstashEncoder {
3434

3535
// matches exactly 11 digits (\\d{11}) that are not immediately preceded ((?<!\\d)) or followed ((?!\\d)) by another digit.
36-
private final Pattern identNummer = Pattern.compile("(?<!\\d)\\d{11}(?!\\d)");
37-
private final Pattern bearer = Pattern.compile("Bearer [a-zA-Z0-9\\-_.]+");
36+
private static final Pattern IDENT = Pattern.compile("(?<!\\d)\\d{11}(?!\\d)");
37+
private static final Pattern BEARER = Pattern.compile("Bearer [a-zA-Z0-9\\-_.]+");
3838
@Setter
3939
private int maxStackTraceLength = 480;
4040

@@ -113,15 +113,14 @@ private void appendStackTraceCauses(ThrowableProxy exception, StringWriter write
113113
}
114114

115115
private String formatMessage(String message) {
116-
message = identNummer.matcher(message).replaceAll(match -> {
117-
if (match.group().charAt(2) < '4') {
118-
return match.group().substring(0, 6) + "xxxxx";
119-
}
120-
return match.group();
121-
});
122116

123-
message = bearer.matcher(message).replaceAll("REDACTED_BEARER");
117+
message = IDENT.matcher(message).replaceAll(match ->
118+
119+
match.group().charAt(2) < '4' ?
120+
match.group().substring(0, 6) + "xxxxx" :
121+
match.group().substring(0, 11) + "x"
122+
);
124123

125-
return message;
124+
return BEARER.matcher(message).replaceAll("Bearer token");
126125
}
127126
}

libs/servlet-core/src/main/java/no/nav/testnav/libs/servletcore/logging/TestnavLogbackEncoder.java

+8-17
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
public class TestnavLogbackEncoder extends LogstashEncoder {
3434

3535
// matches exactly 11 digits (\\d{11}) that are not immediately preceded ((?<!\\d)) or followed ((?!\\d)) by another digit.
36-
private final Pattern pattern = Pattern.compile("(?<!\\d)\\d{11}(?!\\d)");
36+
private static final Pattern IDENT = Pattern.compile("(?<!\\d)\\d{11}(?!\\d)");
37+
private static final Pattern BEARER = Pattern.compile("Bearer [a-zA-Z0-9\\-_.]+");
3738

3839
@Setter
3940
private int maxStackTraceLength = 480;
@@ -113,24 +114,14 @@ private void appendStackTraceCauses(ThrowableProxy exception, StringWriter write
113114
}
114115

115116
private String formatMessage(String message) {
116-
var matcher = pattern.matcher(message);
117117

118-
if (!matcher.find()) {
119-
return message;
120-
}
121-
122-
matcher.reset();
123-
var result = new StringBuilder();
118+
message = IDENT.matcher(message).replaceAll(match ->
124119

125-
while (matcher.find()) {
126-
var match = matcher.group();
127-
if (match.charAt(2) == '0' || match.charAt(2) == '1') {
128-
var replacement = match.substring(0, 6) + "xxxxx";
129-
matcher.appendReplacement(result, replacement);
130-
}
131-
}
132-
matcher.appendTail(result);
120+
match.group().charAt(2) < '4' ?
121+
match.group().substring(0, 6) + "xxxxx" :
122+
match.group().substring(0, 11) + "x"
123+
);
133124

134-
return result.toString();
125+
return BEARER.matcher(message).replaceAll("Bearer token");
135126
}
136127
}

0 commit comments

Comments
 (0)