Skip to content

Commit cd0f02d

Browse files
committed
Polish authorities claim delimiter
PR gh-12074
1 parent 9c9fd9f commit cd0f02d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public final class JwtGrantedAuthoritiesConverter implements Converter<Jwt, Coll
4545

4646
private static final String DEFAULT_AUTHORITY_PREFIX = "SCOPE_";
4747

48-
private static final String DEFAULT_AUTHORITIES_SPLIT_REGEX = " ";
48+
private static final String DEFAULT_AUTHORITIES_CLAIM_DELIMITER = " ";
4949

5050
private static final Collection<String> WELL_KNOWN_AUTHORITIES_CLAIM_NAMES = Arrays.asList("scope", "scp");
5151

5252
private String authorityPrefix = DEFAULT_AUTHORITY_PREFIX;
5353

54-
private String authoritiesSplitRegex = DEFAULT_AUTHORITIES_SPLIT_REGEX;
54+
private String authoritiesClaimDelimiter = DEFAULT_AUTHORITIES_CLAIM_DELIMITER;
5555

5656
private String authoritiesClaimName;
5757

@@ -84,13 +84,13 @@ public void setAuthorityPrefix(String authorityPrefix) {
8484
/**
8585
* Sets the regex to use for splitting the value of the authorities claim into
8686
* {@link GrantedAuthority authorities}. Defaults to
87-
* {@link JwtGrantedAuthoritiesConverter#DEFAULT_AUTHORITIES_SPLIT_REGEX}.
88-
* @param authoritiesSplitRegex The regex used to split the authorities
87+
* {@link JwtGrantedAuthoritiesConverter#DEFAULT_AUTHORITIES_CLAIM_DELIMITER}.
88+
* @param authoritiesClaimDelimiter The regex used to split the authorities
8989
* @since 6.1
9090
*/
91-
public void setAuthoritiesSplitRegex(String authoritiesSplitRegex) {
92-
Assert.notNull(authoritiesSplitRegex, "authoritiesSplitRegex cannot be null");
93-
this.authoritiesSplitRegex = authoritiesSplitRegex;
91+
public void setAuthoritiesClaimDelimiter(String authoritiesClaimDelimiter) {
92+
Assert.notNull(authoritiesClaimDelimiter, "authoritiesClaimDelimiter cannot be null");
93+
this.authoritiesClaimDelimiter = authoritiesClaimDelimiter;
9494
}
9595

9696
/**
@@ -129,7 +129,7 @@ private Collection<String> getAuthorities(Jwt jwt) {
129129
Object authorities = jwt.getClaim(claimName);
130130
if (authorities instanceof String) {
131131
if (StringUtils.hasText((String) authorities)) {
132-
return Arrays.asList(((String) authorities).split(this.authoritiesSplitRegex));
132+
return Arrays.asList(((String) authorities).split(this.authoritiesClaimDelimiter));
133133
}
134134
return Collections.emptyList();
135135
}

oauth2/oauth2-resource-server/src/test/java/org/springframework/security/oauth2/server/resource/authentication/JwtGrantedAuthoritiesConverterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public void convertWithCustomAuthoritiesSplitRegexWhenTokenHasScopeAttributeThen
264264
.build();
265265
// @formatter:on
266266
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
267-
jwtGrantedAuthoritiesConverter.setAuthoritiesSplitRegex(",");
267+
jwtGrantedAuthoritiesConverter.setAuthoritiesClaimDelimiter(",");
268268
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
269269
assertThat(authorities).containsExactly(new SimpleGrantedAuthority("SCOPE_message:read"),
270270
new SimpleGrantedAuthority("SCOPE_message:write"));

0 commit comments

Comments
 (0)