Class DelegatingJwtGrantedAuthoritiesConverter
- All Implemented Interfaces:
org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,Collection<org.springframework.security.core.GrantedAuthority>>
Jwt to GrantedAuthority Converter that is a composite of
converters.
This is handy when needing to read authorities from multiple locations in a JWT; each underlying converter is called in series and the results are aggregated into a single collection of authorities.
For example, you might have a claim called "scope" and another called "roles". With
DelegatingJwtGrantedAuthoritiesConverter, you can do:
JwtGrantedAuthoritiesConverter scopes = new JwtGrantedAuthoritiesConverter();
JwtGrantedAuthoritiesConverter roles = new JwtGrantedAUthoritiesConverter();
roles.setAuthoritiesClaimName("roles");
roles.setAuthorityPrefix("ROLE_");
return new DelegatingJwtGrantedAuthoritiesConverter(scopes, roles);
- Since:
- 5.5
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDelegatingJwtGrantedAuthoritiesConverter(Collection<org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt, Collection<org.springframework.security.core.GrantedAuthority>>> authoritiesConverters) DelegatingJwtGrantedAuthoritiesConverter(org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt, Collection<org.springframework.security.core.GrantedAuthority>>... authoritiesConverters) Constructs aDelegatingJwtGrantedAuthoritiesConverterusing the provided array ofConverters -
Method Summary
Modifier and TypeMethodDescriptionCollection<org.springframework.security.core.GrantedAuthority>convert(org.springframework.security.oauth2.jwt.Jwt jwt) ExtractGrantedAuthoritys from the givenJwt.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.core.convert.converter.Converter
andThen
-
Constructor Details
-
DelegatingJwtGrantedAuthoritiesConverter
public DelegatingJwtGrantedAuthoritiesConverter(Collection<org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt, Collection<org.springframework.security.core.GrantedAuthority>>> authoritiesConverters) - Parameters:
authoritiesConverters- theCollectionofConverters to use
-
DelegatingJwtGrantedAuthoritiesConverter
@SafeVarargs public DelegatingJwtGrantedAuthoritiesConverter(org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt, Collection<org.springframework.security.core.GrantedAuthority>>... authoritiesConverters) Constructs aDelegatingJwtGrantedAuthoritiesConverterusing the provided array ofConverters- Parameters:
authoritiesConverters- the array ofConverters to use
-
-
Method Details
-
convert
public Collection<org.springframework.security.core.GrantedAuthority> convert(org.springframework.security.oauth2.jwt.Jwt jwt) ExtractGrantedAuthoritys from the givenJwt.The authorities are extracted from each delegated
Converterone at a time. For each converter, its authorities are added in order, with duplicates removed.- Specified by:
convertin interfaceorg.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,Collection<org.springframework.security.core.GrantedAuthority>> - Parameters:
jwt- TheJwttoken- Returns:
- The
authoritiesread from the token scopes
-