public interface Token extends Serializable
| Modifier and Type | Field and Description |
|---|---|
static List<TokenFactory> |
services |
| Modifier and Type | Method and Description |
|---|---|
static Token |
create(String jwt)
Creates a token instance based on TokenFactory implementation.
|
default String |
getAttributeFromClaimAsString(String claimName,
String attributeName)
Returns the String value of a claim attribute.
|
default List<String> |
getAttributeFromClaimAsStringList(String claimName,
String attributeName)
Returns the String list of a claim attribute.
|
Set<String> |
getAudiences()
Returns the (empty) list of audiences the token is issued for.
|
JsonObject |
getClaimAsJsonObject(String claimName)
Extracts the value of the given as a JsonObject.
|
String |
getClaimAsString(String claimName)
Extracts the value as string for the given claim.
|
List<String> |
getClaimAsStringList(String claimName)
Extracts the value as a list of strings for the given claim.
|
default Map<String,Object> |
getClaims()
Returns the jwt claim set.
|
String |
getClientId()
Returns the OAuth2 client identifier of the authentication token if present.
|
Instant |
getExpiration()
Returns the moment in time when the token will be expired.
|
default GrantType |
getGrantType()
Returns the grant type of the jwt token.
|
String |
getHeaderParameterAsString(String headerName)
Returns the header parameter value as string for the given header parameter
name.
|
default Map<String,Object> |
getHeaders()
Returns the header(s).
|
Instant |
getNotBefore()
Returns the moment in time before which the token must not be accepted.
|
Principal |
getPrincipal()
Returns a principal, which can be used to represent any entity, such as an
individual, a corporation, and a login id.
|
Service |
getService()
Returns the identity service, the token is issued by.
|
String |
getTokenValue()
Get the encoded jwt token, e.g.
|
String |
getZoneId()
Returns the Zone identifier, which can be used as tenant discriminator
(tenant guid).
|
boolean |
hasClaim(String claimName)
Checks whether the token contains a given claim.
|
boolean |
hasHeaderParameter(String headerName)
Checks whether the token contains a given header parameter.
|
boolean |
isExpired()
Returns true if the token is expired.
|
static final List<TokenFactory> services
static Token create(String jwt)
jwt - encoded JWT token@Nullable String getHeaderParameterAsString(@Nonnull String headerName)
headerName - the name of the header parameter as defined here
TokenHeaderboolean hasHeaderParameter(@Nonnull String headerName)
headerName - the name of the header parameter as defined here
TokenHeaderboolean hasClaim(@Nonnull String claimName)
claimName - the name of the claim as defined here TokenClaims.@Nullable String getClaimAsString(@Nonnull String claimName)
JsonParsingException.claimName - the name of the claim as defined here TokenClaims.JsonParsingException - if the json object identified by the given claim is not a string.List<String> getClaimAsStringList(@Nonnull String claimName)
JsonParsingException.claimName - the name of the claim as defined here TokenClaims.@Nullable JsonObject getClaimAsJsonObject(@Nonnull String claimName)
JsonParsingException.claimName - the name of the claim for which the object should be extracted.JsonObject for the given claim.@Nullable Instant getExpiration()
boolean isExpired()
@Nullable Instant getNotBefore()
String getTokenValue()
Never expose this token via log or via HTTP.
Principal getPrincipal()
Service getService()
Set<String> getAudiences()
String getZoneId()
String getClientId()
@Nullable default GrantType getGrantType()
default Map<String,Object> getHeaders()
Map of the header(s)default Map<String,Object> getClaims()
Map of the jwt claim set@Nullable default String getAttributeFromClaimAsString(String claimName, String attributeName)
"claimName": {
"attributeName": "attributeValueAsString"
},
import static com.sap.cloud.security.token.TokenClaims.XSUAA.*;
token.getAttributeFromClaimAsString(EXTERNAL_ATTRIBUTE, EXTERNAL_ATTRIBUTE_SUBACCOUNTID);
@Nullable default List<String> getAttributeFromClaimAsStringList(String claimName, String attributeName)
"claimName": {
"attributeName": ["attributeValueAsString", "attributeValue2AsString"]
},
import static com.sap.cloud.security.token.TokenClaims.XSUAA.*;
token.getAttributeFromClaimAsString(XS_USER_ATTRIBUTES, "custom_role");
Copyright © 2021. All rights reserved.