Skip to content

Commit 5fe59cc

Browse files
committed
Revert "Add configurable authorities split regex"
This reverts commit e93ed6d. This can't be merged until after the 6.0 release
1 parent e93ed6d commit 5fe59cc

File tree

2 files changed

+3
-33
lines changed

2 files changed

+3
-33
lines changed

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,14 +45,10 @@ 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 = " ";
49-
5048
private static final Collection<String> WELL_KNOWN_AUTHORITIES_CLAIM_NAMES = Arrays.asList("scope", "scp");
5149

5250
private String authorityPrefix = DEFAULT_AUTHORITY_PREFIX;
5351

54-
private String authoritiesSplitRegex = DEFAULT_AUTHORITIES_SPLIT_REGEX;
55-
5652
private String authoritiesClaimName;
5753

5854
/**
@@ -81,18 +77,6 @@ public void setAuthorityPrefix(String authorityPrefix) {
8177
this.authorityPrefix = authorityPrefix;
8278
}
8379

84-
/**
85-
* Sets the regex to use for splitting the value of the authorities claim into
86-
* {@link GrantedAuthority authorities}. Defaults to
87-
* {@link JwtGrantedAuthoritiesConverter#DEFAULT_AUTHORITIES_SPLIT_REGEX}.
88-
* @param authoritiesSplitRegex The regex used to split the authorities
89-
* @since 6.1
90-
*/
91-
public void setAuthoritiesSplitRegex(String authoritiesSplitRegex) {
92-
Assert.notNull(authoritiesSplitRegex, "authoritiesSplitRegex cannot be null");
93-
this.authoritiesSplitRegex = authoritiesSplitRegex;
94-
}
95-
9680
/**
9781
* Sets the name of token claim to use for mapping {@link GrantedAuthority
9882
* authorities} by this converter. Defaults to
@@ -129,7 +113,7 @@ private Collection<String> getAuthorities(Jwt jwt) {
129113
Object authorities = jwt.getClaim(claimName);
130114
if (authorities instanceof String) {
131115
if (StringUtils.hasText((String) authorities)) {
132-
return Arrays.asList(((String) authorities).split(this.authoritiesSplitRegex));
116+
return Arrays.asList(((String) authorities).split(" "));
133117
}
134118
return Collections.emptyList();
135119
}

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -256,18 +256,4 @@ public void convertWhenTokenHasNoCustomClaimNameThenCustomClaimNameAttributeIsTr
256256
assertThat(authorities).isEmpty();
257257
}
258258

259-
@Test
260-
public void convertWithCustomAuthoritiesSplitRegexWhenTokenHasScopeAttributeThenTranslatedToAuthorities() {
261-
// @formatter:off
262-
Jwt jwt = TestJwts.jwt()
263-
.claim("scope", "message:read,message:write")
264-
.build();
265-
// @formatter:on
266-
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
267-
jwtGrantedAuthoritiesConverter.setAuthoritiesSplitRegex(",");
268-
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
269-
assertThat(authorities).containsExactly(new SimpleGrantedAuthority("SCOPE_message:read"),
270-
new SimpleGrantedAuthority("SCOPE_message:write"));
271-
}
272-
273259
}

0 commit comments

Comments
 (0)