Skip to content

Commit 259ff00

Browse files
singhbaljitjzheaux
authored andcommitted
improve performance of Jwt issuer resolvers
1 parent 3088c15 commit 259ff00

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/authentication/JwtIssuerAuthenticationManagerResolver.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616

1717
package org.springframework.security.oauth2.server.resource.authentication;
1818

19-
import java.util.Arrays;
2019
import java.util.Collection;
21-
import java.util.Collections;
2220
import java.util.Map;
21+
import java.util.Set;
2322
import java.util.concurrent.ConcurrentHashMap;
2423
import java.util.function.Predicate;
2524

@@ -49,7 +48,7 @@
4948
*
5049
* To use, this class must be able to determine whether the `iss` claim is trusted. Recall
5150
* that anyone can stand up an authorization server and issue valid tokens to a resource
52-
* server. The simplest way to achieve this is to supply a list of trusted issuers in the
51+
* server. The simplest way to achieve this is to supply a set of trusted issuers in the
5352
* constructor.
5453
*
5554
* This class derives the Issuer from the `iss` claim found in the
@@ -70,7 +69,7 @@ public final class JwtIssuerAuthenticationManagerResolver implements Authenticat
7069
* @param trustedIssuers an array of trusted issuers
7170
*/
7271
public JwtIssuerAuthenticationManagerResolver(String... trustedIssuers) {
73-
this(Arrays.asList(trustedIssuers));
72+
this(Set.of(trustedIssuers));
7473
}
7574

7675
/**
@@ -81,8 +80,7 @@ public JwtIssuerAuthenticationManagerResolver(String... trustedIssuers) {
8180
public JwtIssuerAuthenticationManagerResolver(Collection<String> trustedIssuers) {
8281
Assert.notEmpty(trustedIssuers, "trustedIssuers cannot be empty");
8382
this.authenticationManager = new ResolvingAuthenticationManager(
84-
new TrustedIssuerJwtAuthenticationManagerResolver(
85-
Collections.unmodifiableCollection(trustedIssuers)::contains));
83+
new TrustedIssuerJwtAuthenticationManagerResolver(Set.copyOf(trustedIssuers)::contains));
8684
}
8785

8886
/**
@@ -91,7 +89,7 @@ public JwtIssuerAuthenticationManagerResolver(Collection<String> trustedIssuers)
9189
*
9290
* Note that the {@link AuthenticationManagerResolver} provided in this constructor
9391
* will need to verify that the issuer is trusted. This should be done via an allowed
94-
* list of issuers.
92+
* set of issuers.
9593
*
9694
* One way to achieve this is with a {@link Map} where the keys are the known issuers:
9795
* <pre>

oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/authentication/JwtIssuerReactiveAuthenticationManagerResolver.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
package org.springframework.security.oauth2.server.resource.authentication;
1818

1919
import java.time.Duration;
20-
import java.util.ArrayList;
21-
import java.util.Arrays;
2220
import java.util.Collection;
2321
import java.util.Map;
22+
import java.util.Set;
2423
import java.util.concurrent.ConcurrentHashMap;
2524
import java.util.function.Predicate;
2625

@@ -51,7 +50,7 @@
5150
*
5251
* To use, this class must be able to determine whether the `iss` claim is trusted. Recall
5352
* that anyone can stand up an authorization server and issue valid tokens to a resource
54-
* server. The simplest way to achieve this is to supply a list of trusted issuers in the
53+
* server. The simplest way to achieve this is to supply a set of trusted issuers in the
5554
* constructor.
5655
*
5756
* This class derives the Issuer from the `iss` claim found in the
@@ -74,7 +73,7 @@ public final class JwtIssuerReactiveAuthenticationManagerResolver
7473
* @param trustedIssuers an array of trusted issuers
7574
*/
7675
public JwtIssuerReactiveAuthenticationManagerResolver(String... trustedIssuers) {
77-
this(Arrays.asList(trustedIssuers));
76+
this(Set.of(trustedIssuers));
7877
}
7978

8079
/**
@@ -85,7 +84,7 @@ public JwtIssuerReactiveAuthenticationManagerResolver(String... trustedIssuers)
8584
public JwtIssuerReactiveAuthenticationManagerResolver(Collection<String> trustedIssuers) {
8685
Assert.notEmpty(trustedIssuers, "trustedIssuers cannot be empty");
8786
this.authenticationManager = new ResolvingAuthenticationManager(
88-
new TrustedIssuerJwtAuthenticationManagerResolver(new ArrayList<>(trustedIssuers)::contains));
87+
new TrustedIssuerJwtAuthenticationManagerResolver(Set.copyOf(trustedIssuers)::contains));
8988
}
9089

9190
/**
@@ -94,7 +93,7 @@ public JwtIssuerReactiveAuthenticationManagerResolver(Collection<String> trusted
9493
*
9594
* Note that the {@link ReactiveAuthenticationManagerResolver} provided in this
9695
* constructor will need to verify that the issuer is trusted. This should be done via
97-
* an allowed list of issuers.
96+
* an allowed set of issuers.
9897
*
9998
* One way to achieve this is with a {@link Map} where the keys are the known issuers:
10099
* <pre>

0 commit comments

Comments
 (0)