22
22
import java .util .Arrays ;
23
23
import java .util .Collection ;
24
24
import java .util .Collections ;
25
+ import java .util .LinkedHashMap ;
25
26
import java .util .Map ;
26
27
27
28
import reactor .core .publisher .Mono ;
@@ -136,16 +137,17 @@ private Mono<Map<String, Object>> adaptToNimbusResponse(ClientResponse responseE
136
137
}
137
138
138
139
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 ) -> {
140
142
if (v instanceof String ) {
141
143
return Collections .singletonList (v );
142
144
}
143
145
return v ;
144
146
});
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 ,
147
149
(k , v ) -> Instant .ofEpochSecond (((Number ) v ).longValue ()));
148
- claims .computeIfPresent (OAuth2TokenIntrospectionClaimNames .IAT ,
150
+ converted .computeIfPresent (OAuth2TokenIntrospectionClaimNames .IAT ,
149
151
(k , v ) -> Instant .ofEpochSecond (((Number ) v ).longValue ()));
150
152
// RFC-7662 page 7 directs users to RFC-7519 for defining the values of these
151
153
// issuer fields.
@@ -165,11 +167,11 @@ private OAuth2AuthenticatedPrincipal convertClaimsSet(Map<String, Object> claims
165
167
// may be awkward to debug, we do not want to manipulate this value. Previous
166
168
// versions of Spring Security
167
169
// 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 ,
170
172
(k , v ) -> Instant .ofEpochSecond (((Number ) v ).longValue ()));
171
173
Collection <GrantedAuthority > authorities = new ArrayList <>();
172
- claims .computeIfPresent (OAuth2TokenIntrospectionClaimNames .SCOPE , (k , v ) -> {
174
+ converted .computeIfPresent (OAuth2TokenIntrospectionClaimNames .SCOPE , (k , v ) -> {
173
175
if (v instanceof String ) {
174
176
Collection <String > scopes = Arrays .asList (((String ) v ).split (" " ));
175
177
for (String scope : scopes ) {
@@ -179,7 +181,7 @@ private OAuth2AuthenticatedPrincipal convertClaimsSet(Map<String, Object> claims
179
181
}
180
182
return v ;
181
183
});
182
- return new OAuth2IntrospectionAuthenticatedPrincipal (claims , authorities );
184
+ return new OAuth2IntrospectionAuthenticatedPrincipal (converted , authorities );
183
185
}
184
186
185
187
private OAuth2IntrospectionException onError (Throwable ex ) {
0 commit comments