Class XsuaaToken
java.lang.Object
org.springframework.security.oauth2.core.AbstractOAuth2Token
org.springframework.security.oauth2.jwt.Jwt
com.sap.cloud.security.xsuaa.token.XsuaaToken
- All Implemented Interfaces:
Token,Serializable,org.springframework.security.core.userdetails.UserDetails,org.springframework.security.oauth2.core.ClaimAccessor,org.springframework.security.oauth2.core.OAuth2Token,org.springframework.security.oauth2.jwt.JwtClaimAccessor
Custom XSUAA token implementation.
This class inherits Spring Security's standard Jwt implementation and can be used interchangeably with it.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.security.oauth2.jwt.Jwt
org.springframework.security.oauth2.jwt.Jwt.Builder -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedXsuaaToken(org.springframework.security.oauth2.jwt.Jwt jwt) -
Method Summary
Modifier and TypeMethodDescriptiongetAdditionalAuthAttribute(String attributeName) Additional custom authentication attributes included by the OAuth client component.Get the encoded authentication token, e.g.Collection<? extends org.springframework.security.core.GrantedAuthority>Returns by default list of scopesToken.getScopes().Returns the OAuth2 client identifier of the authentication token if present.Returns the XSUAA clone instance ID, if present.getEmail()Returns the email address of the user, if present.Returns the moment in time when the token will be expired.Returns the family name of the user if present.Returns the given name of the user if present.Returns the OAuth2.0 grant type used for retrieving / creating this token.convenient access to other claimsReturns the user origin.Returns list of scopes with appId prefix, e.g.Return subaccount identifier which is in most cases same like the identity zone.Returns the subdomain of the calling tenant's subaccount.static StringgetUniquePrincipalName(String origin, String userLoginName) Get unique principal name of a user.String[]getXSUserAttribute(String attributeName) Returns the value of an attribute from the 'xs.user.attributes' claim.Return zone identifier which should be used as tenant discriminator (tenant id).booleanbooleanbooleanbooleantoString()Methods inherited from class org.springframework.security.oauth2.jwt.Jwt
getClaims, getHeaders, withTokenValueMethods inherited from class org.springframework.security.oauth2.core.AbstractOAuth2Token
equals, getExpiresAt, getIssuedAt, getTokenValue, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.security.oauth2.core.ClaimAccessor
getClaim, getClaimAsBoolean, getClaimAsInstant, getClaimAsMap, getClaimAsString, getClaimAsStringList, getClaimAsURL, hasClaimMethods inherited from interface org.springframework.security.oauth2.jwt.JwtClaimAccessor
getAudience, getExpiresAt, getId, getIssuedAt, getIssuer, getNotBefore, getSubject
-
Constructor Details
-
XsuaaToken
protected XsuaaToken(org.springframework.security.oauth2.jwt.Jwt jwt) - Parameters:
jwt- token
-
-
Method Details
-
getAuthorities
Description copied from interface:TokenReturns by default list of scopesToken.getScopes().The default behavior can be adapted as part of
TokenAuthenticationConverterclass- Specified by:
getAuthoritiesin interfaceToken- Specified by:
getAuthoritiesin interfaceorg.springframework.security.core.userdetails.UserDetails- Returns:
- all authorities such as scopes or an empty list
-
getExpiration
Description copied from interface:TokenReturns the moment in time when the token will be expired.- Specified by:
getExpirationin interfaceToken- Returns:
- the expiration point in time if present.
-
getPassword
- Specified by:
getPasswordin interfaceorg.springframework.security.core.userdetails.UserDetails
-
getUsername
- Specified by:
getUsernamein interfaceorg.springframework.security.core.userdetails.UserDetails
-
isAccountNonExpired
public boolean isAccountNonExpired()- Specified by:
isAccountNonExpiredin interfaceorg.springframework.security.core.userdetails.UserDetails
-
isAccountNonLocked
public boolean isAccountNonLocked()- Specified by:
isAccountNonLockedin interfaceorg.springframework.security.core.userdetails.UserDetails
-
isCredentialsNonExpired
public boolean isCredentialsNonExpired()- Specified by:
isCredentialsNonExpiredin interfaceorg.springframework.security.core.userdetails.UserDetails
-
isEnabled
public boolean isEnabled()- Specified by:
isEnabledin interfaceorg.springframework.security.core.userdetails.UserDetails
-
getUniquePrincipalName
Get unique principal name of a user.- Parameters:
origin- of the access tokenuserLoginName- of the access token- Returns:
- unique principal name
-
getLogonName
convenient access to other claims- Specified by:
getLogonNamein interfaceToken- Returns:
- unique principal name or null if it can not be determined.
-
getClientId
Description copied from interface:TokenReturns the OAuth2 client identifier of the authentication token if present. Following OpenID Connect 1.0 standard specifications, client identifier is obtained from "azp" claim if present or when "azp" is not present from "aud" claim, but only in case there is one audience.- Specified by:
getClientIdin interfaceToken- Returns:
- the OAuth client ID.
-
getGivenName
Description copied from interface:TokenReturns the given name of the user if present. Will try to find it first in theext_attr.given_nameclaim before trying to find agiven_nameclaim.- Specified by:
getGivenNamein interfaceToken- Returns:
- the given name if present.
-
getFamilyName
Description copied from interface:TokenReturns the family name of the user if present. Will try to find it first in theext_attr.family_nameclaim before trying to find afamily_nameclaim.- Specified by:
getFamilyNamein interfaceToken- Returns:
- the family name if present.
-
getEmail
Description copied from interface:TokenReturns the email address of the user, if present. -
getOrigin
Description copied from interface:TokenReturns the user origin. The origin is an alias that refers to a user store in which the user is persisted. For example, users that are authenticated by the UAA itself with a username / password combination have their origin set to the value "uaa".May be null in case this JWT was not created with OAuth 2.0 client credentials flow.
-
getGrantType
Description copied from interface:TokenReturns the OAuth2.0 grant type used for retrieving / creating this token.- Specified by:
getGrantTypein interfaceToken- Returns:
- the grant type
-
getSubaccountId
Description copied from interface:TokenReturn subaccount identifier which is in most cases same like the identity zone. DO only use this for metering purposes. DO NOT longer use this method to get the unique tenant id! For that useToken.getZoneId().- Specified by:
getSubaccountIdin interfaceToken- Returns:
- the subaccount identifier.
-
getZoneId
Description copied from interface:TokenReturn zone identifier which should be used as tenant discriminator (tenant id). For most of the old subaccounts this matches the id returned byToken.getSubaccountId(). -
getSubdomain
Description copied from interface:TokenReturns the subdomain of the calling tenant's subaccount.- Specified by:
getSubdomainin interfaceToken- Returns:
- the subdomain of the tenant the JWT belongs to.
-
toString
-
getXSUserAttribute
Description copied from interface:TokenReturns the value of an attribute from the 'xs.user.attributes' claim. Will first try to find the attribute in 'ext_ctx' claim.- Specified by:
getXSUserAttributein interfaceToken- Parameters:
attributeName- name of the attribute inside 'ext_ctx' or 'xs.user.attributes'.- Returns:
- the attribute values array or null if there exists no such attribute.
-
getAdditionalAuthAttribute
Description copied from interface:TokenAdditional custom authentication attributes included by the OAuth client component. Note: this is data controlled by the requester of a token. Might be not trustworthy.- Specified by:
getAdditionalAuthAttributein interfaceToken- Parameters:
attributeName- name of the authentication attribute- Returns:
- additional attribute value if present.
-
getCloneServiceInstanceId
Description copied from interface:TokenReturns the XSUAA clone instance ID, if present. This will only be set for tokens that were issued by an XSUAA with plan broker. Contains the service instance id if present.- Specified by:
getCloneServiceInstanceIdin interfaceToken- Returns:
- the XSUAA clone service instance id if present.
-
getAppToken
Description copied from interface:TokenGet the encoded authentication token, e.g. for token forwarding to another app.Never expose this token via log or via HTTP.
- Specified by:
getAppTokenin interfaceToken- Returns:
- token
-
getScopes
Description copied from interface:TokenReturns list of scopes with appId prefix, e.g. "<my-app!t123>.Display".
-