Skip to content

Commit 01f299f

Browse files
committed
Merge branch '6.1.x' into 6.2.x
Closes gh-14848
2 parents 16e2bdc + ef00312 commit 01f299f

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/SpringOpaqueTokenIntrospector.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Arrays;
2323
import java.util.Collection;
2424
import java.util.Collections;
25+
import java.util.LinkedHashMap;
2526
import java.util.Map;
2627

2728
import org.apache.commons.logging.Log;
@@ -179,16 +180,17 @@ private Map<String, Object> adaptToNimbusResponse(ResponseEntity<Map<String, Obj
179180
}
180181

181182
private OAuth2AuthenticatedPrincipal convertClaimsSet(Map<String, Object> claims) {
182-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.AUD, (k, v) -> {
183+
Map<String, Object> converted = new LinkedHashMap<>(claims);
184+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.AUD, (k, v) -> {
183185
if (v instanceof String) {
184186
return Collections.singletonList(v);
185187
}
186188
return v;
187189
});
188-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.CLIENT_ID, (k, v) -> v.toString());
189-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.EXP,
190+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.CLIENT_ID, (k, v) -> v.toString());
191+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.EXP,
190192
(k, v) -> Instant.ofEpochSecond(((Number) v).longValue()));
191-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.IAT,
193+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.IAT,
192194
(k, v) -> Instant.ofEpochSecond(((Number) v).longValue()));
193195
// RFC-7662 page 7 directs users to RFC-7519 for defining the values of these
194196
// issuer fields.
@@ -208,11 +210,11 @@ private OAuth2AuthenticatedPrincipal convertClaimsSet(Map<String, Object> claims
208210
// may be awkward to debug, we do not want to manipulate this value. Previous
209211
// versions of Spring Security
210212
// would *only* allow valid URLs, which is not what we wish to achieve here.
211-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.ISS, (k, v) -> v.toString());
212-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.NBF,
213+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.ISS, (k, v) -> v.toString());
214+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.NBF,
213215
(k, v) -> Instant.ofEpochSecond(((Number) v).longValue()));
214216
Collection<GrantedAuthority> authorities = new ArrayList<>();
215-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.SCOPE, (k, v) -> {
217+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.SCOPE, (k, v) -> {
216218
if (v instanceof String) {
217219
Collection<String> scopes = Arrays.asList(((String) v).split(" "));
218220
for (String scope : scopes) {
@@ -222,7 +224,7 @@ private OAuth2AuthenticatedPrincipal convertClaimsSet(Map<String, Object> claims
222224
}
223225
return v;
224226
});
225-
return new OAuth2IntrospectionAuthenticatedPrincipal(claims, authorities);
227+
return new OAuth2IntrospectionAuthenticatedPrincipal(converted, authorities);
226228
}
227229

228230
}

oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/SpringReactiveOpaqueTokenIntrospector.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Arrays;
2323
import java.util.Collection;
2424
import java.util.Collections;
25+
import java.util.LinkedHashMap;
2526
import java.util.Map;
2627

2728
import reactor.core.publisher.Mono;
@@ -136,16 +137,17 @@ private Mono<Map<String, Object>> adaptToNimbusResponse(ClientResponse responseE
136137
}
137138

138139
private OAuth2AuthenticatedPrincipal convertClaimsSet(Map<String, Object> claims) {
139-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.AUD, (k, v) -> {
140+
Map<String, Object> converted = new LinkedHashMap<>(claims);
141+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.AUD, (k, v) -> {
140142
if (v instanceof String) {
141143
return Collections.singletonList(v);
142144
}
143145
return v;
144146
});
145-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.CLIENT_ID, (k, v) -> v.toString());
146-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.EXP,
147+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.CLIENT_ID, (k, v) -> v.toString());
148+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.EXP,
147149
(k, v) -> Instant.ofEpochSecond(((Number) v).longValue()));
148-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.IAT,
150+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.IAT,
149151
(k, v) -> Instant.ofEpochSecond(((Number) v).longValue()));
150152
// RFC-7662 page 7 directs users to RFC-7519 for defining the values of these
151153
// issuer fields.
@@ -165,11 +167,11 @@ private OAuth2AuthenticatedPrincipal convertClaimsSet(Map<String, Object> claims
165167
// may be awkward to debug, we do not want to manipulate this value. Previous
166168
// versions of Spring Security
167169
// would *only* allow valid URLs, which is not what we wish to achieve here.
168-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.ISS, (k, v) -> v.toString());
169-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.NBF,
170+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.ISS, (k, v) -> v.toString());
171+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.NBF,
170172
(k, v) -> Instant.ofEpochSecond(((Number) v).longValue()));
171173
Collection<GrantedAuthority> authorities = new ArrayList<>();
172-
claims.computeIfPresent(OAuth2TokenIntrospectionClaimNames.SCOPE, (k, v) -> {
174+
converted.computeIfPresent(OAuth2TokenIntrospectionClaimNames.SCOPE, (k, v) -> {
173175
if (v instanceof String) {
174176
Collection<String> scopes = Arrays.asList(((String) v).split(" "));
175177
for (String scope : scopes) {
@@ -179,7 +181,7 @@ private OAuth2AuthenticatedPrincipal convertClaimsSet(Map<String, Object> claims
179181
}
180182
return v;
181183
});
182-
return new OAuth2IntrospectionAuthenticatedPrincipal(claims, authorities);
184+
return new OAuth2IntrospectionAuthenticatedPrincipal(converted, authorities);
183185
}
184186

185187
private OAuth2IntrospectionException onError(Throwable ex) {

0 commit comments

Comments
 (0)