|
18 | 18 | import java.util.LinkedHashSet; |
19 | 19 | import java.util.Set; |
20 | 20 | import java.util.function.Consumer; |
21 | | -import java.util.stream.Collectors; |
22 | 21 |
|
23 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
24 | 23 | import org.springframework.security.authentication.AuthenticationProvider; |
|
34 | 33 | import org.springframework.security.oauth2.jwt.Jwt; |
35 | 34 | import org.springframework.security.oauth2.jwt.JwtClaimsSet; |
36 | 35 | import org.springframework.security.oauth2.jwt.JwtEncoder; |
| 36 | +import org.springframework.security.oauth2.server.authorization.JwtEncodingContext; |
37 | 37 | import org.springframework.security.oauth2.server.authorization.OAuth2Authorization; |
38 | 38 | import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService; |
| 39 | +import org.springframework.security.oauth2.server.authorization.OAuth2TokenCustomizer; |
39 | 40 | import org.springframework.security.oauth2.server.authorization.client.RegisteredClient; |
40 | 41 | import org.springframework.security.oauth2.server.authorization.config.ProviderSettings; |
41 | | -import org.springframework.security.oauth2.server.authorization.JwtEncodingContext; |
42 | | -import org.springframework.security.oauth2.server.authorization.OAuth2TokenCustomizer; |
43 | 42 | import org.springframework.util.Assert; |
44 | 43 | import org.springframework.util.CollectionUtils; |
45 | 44 |
|
@@ -112,11 +111,10 @@ public Authentication authenticate(Authentication authentication) throws Authent |
112 | 111 |
|
113 | 112 | Set<String> authorizedScopes = registeredClient.getScopes(); // Default to configured scopes |
114 | 113 | if (!CollectionUtils.isEmpty(clientCredentialsAuthentication.getScopes())) { |
115 | | - Set<String> unauthorizedScopes = clientCredentialsAuthentication.getScopes().stream() |
116 | | - .filter(requestedScope -> !registeredClient.getScopes().contains(requestedScope)) |
117 | | - .collect(Collectors.toSet()); |
118 | | - if (!CollectionUtils.isEmpty(unauthorizedScopes)) { |
119 | | - throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.INVALID_SCOPE)); |
| 114 | + for (String requestedScope : clientCredentialsAuthentication.getScopes()) { |
| 115 | + if (!registeredClient.getScopes().contains(requestedScope)) { |
| 116 | + throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.INVALID_SCOPE)); |
| 117 | + } |
120 | 118 | } |
121 | 119 | authorizedScopes = new LinkedHashSet<>(clientCredentialsAuthentication.getScopes()); |
122 | 120 | } |
|
0 commit comments