Skip to content

Commit 9520e3a

Browse files
philsttrjgrandja
authored andcommitted
Make UnAuthenticatedServerOAuth2AuthorizedClientRepository threadsafe
Previously UnAuthenticatedServerOAuth2AuthorizedClientRepository used a HashMap for storing OAuth2AuthorizedClients. UnAuthenticatedServerOAuth2AuthorizedClientRepository and its HashMap are potentially accessed by multiple threads without any synchronization. Since HashMap is not threadsafe itself, this makes UnAuthenticatedServerOAuth2AuthorizedClientRepository not threadsafe. Now UnAuthenticatedServerOAuth2AuthorizedClientRepository uses a ConcurrentHashMap for storing OAuth2AuthorizedClients. Since ConcurrentHashMap is threadsafe, UnAuthenticatedServerOAuth2AuthorizedClientRepository will now be threadsafe as well. Fixes gh-6717
1 parent 9593f9c commit 9520e3a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/server/UnAuthenticatedServerOAuth2AuthorizedClientRepository.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
2424
import org.springframework.web.server.ServerWebExchange;
2525
import reactor.core.publisher.Mono;
2626

27-
import java.util.HashMap;
27+
import java.util.concurrent.ConcurrentHashMap;
2828
import java.util.Map;
2929

3030
/**
@@ -38,7 +38,7 @@
3838
public class UnAuthenticatedServerOAuth2AuthorizedClientRepository implements ServerOAuth2AuthorizedClientRepository {
3939
private final AuthenticationTrustResolver trustResolver = new AuthenticationTrustResolverImpl();
4040

41-
private Map<String, OAuth2AuthorizedClient> clientRegistrationIdToAuthorizedClient = new HashMap<>();
41+
private final Map<String, OAuth2AuthorizedClient> clientRegistrationIdToAuthorizedClient = new ConcurrentHashMap<>();
4242

4343
@Override
4444
public <T extends OAuth2AuthorizedClient> Mono<T> loadAuthorizedClient(String clientRegistrationId,

0 commit comments

Comments
 (0)