Skip to content

Commit 1c441e8

Browse files
author
Vladimir Kotal
committed
use ConfigurationChangedListener
1 parent e9a23d1 commit 1c441e8

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/ConfigurationChangedListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.configuration;
2424

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package org.opengrok.web.api.v1.filter;
2424

25+
import org.opengrok.indexer.configuration.ConfigurationChangedListener;
2526
import org.opengrok.indexer.configuration.RuntimeEnvironment;
2627
import org.opengrok.indexer.logger.LoggerFactory;
2728
import org.opengrok.web.api.v1.controller.AnnotationController;
@@ -56,7 +57,7 @@
5657
*/
5758
@Provider
5859
@PreMatching
59-
public class IncomingFilter implements ContainerRequestFilter {
60+
public class IncomingFilter implements ContainerRequestFilter, ConfigurationChangedListener {
6061

6162
private static final Logger logger = LoggerFactory.getLogger(IncomingFilter.class);
6263

@@ -82,6 +83,14 @@ public class IncomingFilter implements ContainerRequestFilter {
8283

8384
private Set<String> tokens;
8485

86+
private Set<String> getTokens() {
87+
return tokens;
88+
}
89+
90+
private void setTokens(Set<String> tokens) {
91+
this.tokens = tokens;
92+
}
93+
8594
@PostConstruct
8695
public void init() {
8796
try {
@@ -94,7 +103,14 @@ public void init() {
94103
}
95104

96105
// Cache the tokens to avoid locking.
97-
tokens = RuntimeEnvironment.getInstance().getAuthenticationTokens();
106+
setTokens(RuntimeEnvironment.getInstance().getAuthenticationTokens());
107+
108+
RuntimeEnvironment.getInstance().registerListener(this);
109+
}
110+
111+
@Override
112+
public void onConfigurationChanged() {
113+
setTokens(RuntimeEnvironment.getInstance().getAuthenticationTokens());
98114
}
99115

100116
@Override
@@ -109,7 +125,7 @@ public void filter(final ContainerRequestContext context) {
109125
String authHeaderValue = request.getHeader(HttpHeaders.AUTHORIZATION);
110126
if (authHeaderValue != null && authHeaderValue.startsWith(BEARER)) {
111127
String tokenValue = authHeaderValue.substring(BEARER.length());
112-
if (tokens.contains(tokenValue)) {
128+
if (getTokens().contains(tokenValue)) {
113129
logger.log(Level.FINEST, "allowing request to {0} based on authentication header token", path);
114130
return;
115131
}

0 commit comments

Comments
 (0)