Revert "Add configurable authorities split regex"
This reverts commit e93ed6d94c
.
This can't be merged until after the 6.0 release
This commit is contained in:
parent
e93ed6d94c
commit
5fe59cc635
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -45,14 +45,10 @@ public final class JwtGrantedAuthoritiesConverter implements Converter<Jwt, Coll
|
|||
|
||||
private static final String DEFAULT_AUTHORITY_PREFIX = "SCOPE_";
|
||||
|
||||
private static final String DEFAULT_AUTHORITIES_SPLIT_REGEX = " ";
|
||||
|
||||
private static final Collection<String> WELL_KNOWN_AUTHORITIES_CLAIM_NAMES = Arrays.asList("scope", "scp");
|
||||
|
||||
private String authorityPrefix = DEFAULT_AUTHORITY_PREFIX;
|
||||
|
||||
private String authoritiesSplitRegex = DEFAULT_AUTHORITIES_SPLIT_REGEX;
|
||||
|
||||
private String authoritiesClaimName;
|
||||
|
||||
/**
|
||||
|
@ -81,18 +77,6 @@ public final class JwtGrantedAuthoritiesConverter implements Converter<Jwt, Coll
|
|||
this.authorityPrefix = authorityPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the regex to use for splitting the value of the authorities claim into
|
||||
* {@link GrantedAuthority authorities}. Defaults to
|
||||
* {@link JwtGrantedAuthoritiesConverter#DEFAULT_AUTHORITIES_SPLIT_REGEX}.
|
||||
* @param authoritiesSplitRegex The regex used to split the authorities
|
||||
* @since 6.1
|
||||
*/
|
||||
public void setAuthoritiesSplitRegex(String authoritiesSplitRegex) {
|
||||
Assert.notNull(authoritiesSplitRegex, "authoritiesSplitRegex cannot be null");
|
||||
this.authoritiesSplitRegex = authoritiesSplitRegex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of token claim to use for mapping {@link GrantedAuthority
|
||||
* authorities} by this converter. Defaults to
|
||||
|
@ -129,7 +113,7 @@ public final class JwtGrantedAuthoritiesConverter implements Converter<Jwt, Coll
|
|||
Object authorities = jwt.getClaim(claimName);
|
||||
if (authorities instanceof String) {
|
||||
if (StringUtils.hasText((String) authorities)) {
|
||||
return Arrays.asList(((String) authorities).split(this.authoritiesSplitRegex));
|
||||
return Arrays.asList(((String) authorities).split(" "));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -256,18 +256,4 @@ public class JwtGrantedAuthoritiesConverterTests {
|
|||
assertThat(authorities).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertWithCustomAuthoritiesSplitRegexWhenTokenHasScopeAttributeThenTranslatedToAuthorities() {
|
||||
// @formatter:off
|
||||
Jwt jwt = TestJwts.jwt()
|
||||
.claim("scope", "message:read,message:write")
|
||||
.build();
|
||||
// @formatter:on
|
||||
JwtGrantedAuthoritiesConverter jwtGrantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
|
||||
jwtGrantedAuthoritiesConverter.setAuthoritiesSplitRegex(",");
|
||||
Collection<GrantedAuthority> authorities = jwtGrantedAuthoritiesConverter.convert(jwt);
|
||||
assertThat(authorities).containsExactly(new SimpleGrantedAuthority("SCOPE_message:read"),
|
||||
new SimpleGrantedAuthority("SCOPE_message:write"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue