Skip to content

Commit 92a13c2

Browse files
committed
Remove unnecessary isExplicitlySet flag
The isExplicitlySet flag was used to ensure that an explicitly configured authoritiesClaimName is always returned. However, in the current implementation, if the claim is not present in the JWT, no authorities are added regardless of whether the name is explicitly set or not. Since there is no fallback to other claim names, the presence of this flag does not change the outcome and can be safely removed. Signed-off-by: chanbinme <[email protected]>
1 parent 37c4d4c commit 92a13c2

File tree

1 file changed

+0
-6
lines changed

1 file changed

+0
-6
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ public final class JwtGrantedAuthoritiesConverter implements Converter<Jwt, Coll
5555

5656
private Collection<String> authoritiesClaimNames = WELL_KNOWN_AUTHORITIES_CLAIM_NAMES;
5757

58-
private boolean isExplicitlySet = false;
59-
6058
/**
6159
* Extract {@link GrantedAuthority}s from the given {@link Jwt}.
6260
* @param jwt The {@link Jwt} token
@@ -105,13 +103,9 @@ public void setAuthoritiesClaimDelimiter(String authoritiesClaimDelimiter) {
105103
public void setAuthoritiesClaimName(String authoritiesClaimName) {
106104
Assert.hasText(authoritiesClaimName, "authoritiesClaimName cannot be empty");
107105
this.authoritiesClaimNames = Collections.singletonList(authoritiesClaimName);
108-
this.isExplicitlySet = true;
109106
}
110107

111108
private String getAuthoritiesClaimName(Jwt jwt) {
112-
if (this.isExplicitlySet) {
113-
return this.authoritiesClaimNames.iterator().next();
114-
}
115109
for (String claimName : this.authoritiesClaimNames) {
116110
if (jwt.hasClaim(claimName)) {
117111
return claimName;

0 commit comments

Comments
 (0)