Skip to content

Commit a687cd8

Browse files
author
Vladimir Kotal
committed
cache the tokens
needs ConfigurationChangeListener
1 parent cf00f66 commit a687cd8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

opengrok-web/src/main/java/org/opengrok/web/api/v1/filter/IncomingFilter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public class IncomingFilter implements ContainerRequestFilter {
8080

8181
static final String BEARER = "Bearer "; // Authorization header value prefix
8282

83+
private Set<String> tokens;
84+
8385
@PostConstruct
8486
public void init() {
8587
try {
@@ -90,6 +92,9 @@ public void init() {
9092
} catch (IOException e) {
9193
logger.log(Level.SEVERE, "Could not get localhost addresses", e);
9294
}
95+
96+
// Cache the tokens to avoid locking.
97+
tokens = RuntimeEnvironment.getInstance().getAuthenticationTokens();
9398
}
9499

95100
@Override
@@ -104,7 +109,7 @@ public void filter(final ContainerRequestContext context) {
104109
String authHeaderValue = request.getHeader(HttpHeaders.AUTHORIZATION);
105110
if (authHeaderValue != null && authHeaderValue.startsWith(BEARER)) {
106111
String tokenValue = authHeaderValue.substring(BEARER.length());
107-
if (RuntimeEnvironment.getInstance().getAuthenticationTokens().contains(tokenValue)) {
112+
if (tokens.contains(tokenValue)) {
108113
logger.log(Level.FINEST, "allowing request to {0} based on authentication header token", path);
109114
return;
110115
}

0 commit comments

Comments
 (0)