2222import java .util .Arrays ;
2323import java .util .Collection ;
2424import java .util .Collections ;
25+ import java .util .LinkedHashMap ;
2526import java .util .Map ;
2627
2728import 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