Class TokenAuthenticationConverter
java.lang.Object
com.sap.cloud.security.xsuaa.token.TokenAuthenticationConverter
- All Implemented Interfaces:
org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,org.springframework.security.authentication.AbstractAuthenticationToken>
public class TokenAuthenticationConverter
extends Object
implements org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,org.springframework.security.authentication.AbstractAuthenticationToken>
An authentication converter that extracts authorization related information
from the Jwt token. For example the
LocalAuthoritiesExtractor can
remove the ugly application id prefix (e.g.my-application-demo!t1229) from
the scopes in the JWT.-
Constructor Summary
ConstructorsConstructorDescriptionTokenAuthenticationConverter(AuthoritiesExtractor authoritiesExtractor) Creates a new converter with the givenAuthoritiesExtractor.TokenAuthenticationConverter(XsuaaServiceConfiguration xsuaaServiceConfiguration) Creates a new converter with a newDefaultAuthoritiesExtractorinstance as default authorities extractor.Creates a new converter with a newDefaultAuthoritiesExtractorinstance as default authorities extractor. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.security.authentication.AbstractAuthenticationTokenconvert(org.springframework.security.oauth2.jwt.Jwt jwt) setLocalScopeAsAuthorities(boolean extractLocalScopesOnly) This method allows to overwrite the default behavior of theToken.getAuthorities()implementation.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
-
TokenAuthenticationConverter
Creates a new converter with the givenAuthoritiesExtractor.- Parameters:
authoritiesExtractor- - the extractor used to turn Jwt scopes into Spring Security authorities.
-
TokenAuthenticationConverter
Creates a new converter with a newDefaultAuthoritiesExtractorinstance as default authorities extractor.- Parameters:
appId- e.g. myXsAppname!t123
-
TokenAuthenticationConverter
Creates a new converter with a newDefaultAuthoritiesExtractorinstance as default authorities extractor.- Parameters:
xsuaaServiceConfiguration- the xsuaa configuration
-
-
Method Details
-
convert
public org.springframework.security.authentication.AbstractAuthenticationToken convert(org.springframework.security.oauth2.jwt.Jwt jwt) - Specified by:
convertin interfaceorg.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,org.springframework.security.authentication.AbstractAuthenticationToken>
-
setLocalScopeAsAuthorities
This method allows to overwrite the default behavior of theToken.getAuthorities()implementation.- Parameters:
extractLocalScopesOnly- true whenToken.getAuthorities()should only extract local scopes. Local scopes means that non-application specific scopes are filtered out and scopes are returned without appId prefix, e.g. "Display". Creates a new converter with a newLocalAuthoritiesExtractor- Returns:
- the token authenticator itself
-