Merge pull request #11233 from Johnny Lim

* gh-11233:
  Use volatile for ReactiveTokenValidator.cacheTokenKeys
pull/11233/merge
Andy Wilkinson 7 years ago
commit 082a96776d

@ -25,6 +25,7 @@ import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import reactor.core.publisher.Mono;
@ -43,7 +44,7 @@ class ReactiveTokenValidator {
private final ReactiveCloudFoundrySecurityService securityService;
private Map<String, String> cachedTokenKeys = new ConcurrentHashMap<>();
private volatile ConcurrentMap<String, String> cachedTokenKeys = new ConcurrentHashMap<>();
ReactiveTokenValidator(ReactiveCloudFoundrySecurityService securityService) {
this.securityService = securityService;
@ -91,8 +92,7 @@ class ReactiveTokenValidator {
}
private void cacheTokenKeys(Map<String, String> tokenKeys) {
this.cachedTokenKeys.clear();
this.cachedTokenKeys.putAll(tokenKeys);
this.cachedTokenKeys = new ConcurrentHashMap<>(tokenKeys);
}
private boolean hasValidSignature(Token token, String key) {

@ -26,8 +26,8 @@ import java.security.Signature;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.codec.binary.Base64;
import org.junit.Before;
@ -80,9 +80,9 @@ public class ReactiveTokenValidatorTests {
+ "r3F7aM9YpErzeYLrl0GhQr9BVJxOvXcVd4kmY+XkiCcrkyS1cnghnllh+LCwQu1s\n"
+ "YwIDAQAB\n-----END PUBLIC KEY-----";
private static final Map<String, String> INVALID_KEYS = new LinkedHashMap<>();
private static final Map<String, String> INVALID_KEYS = new ConcurrentHashMap<>();
private static final Map<String, String> VALID_KEYS = new LinkedHashMap<>();
private static final Map<String, String> VALID_KEYS = new ConcurrentHashMap<>();
@Before
public void setup() throws Exception {

Loading…
Cancel
Save