Class AbstractOAuth2TokenService
- java.lang.Object
-
- com.sap.cloud.security.xsuaa.client.AbstractOAuth2TokenService
-
- All Implemented Interfaces:
OAuth2TokenService,Cacheable
- Direct Known Subclasses:
DefaultOAuth2TokenService,XsuaaOAuth2TokenService
public abstract class AbstractOAuth2TokenService extends Object implements OAuth2TokenService, Cacheable
-
-
Constructor Summary
Constructors Constructor Description AbstractOAuth2TokenService()AbstractOAuth2TokenService(TokenCacheConfiguration tokenCacheConfiguration)Constructor used to overwrite the default cache configuration.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclearCache()Clears the cache of the component.TokenCacheConfigurationgetCacheConfiguration()Provides the cache configuration of the component.ObjectgetCacheStatistics()This returns an implementation specific statistics object if the underlying cache supports it and cache statistics have been enabled in theCacheConfiguration.protected ClockgetClock()By defaultClock.systemUTC()is used to determine of a cached token has reached its expiration (exp) point in time.protected abstract OAuth2TokenResponserequestAccessToken(URI tokenEndpointUri, HttpHeaders headers, Map<String,String> parameters)Implements the HTTP client specific logic to perform an HTTP request and handle the response.OAuth2TokenResponseretrieveAccessTokenViaClientCredentialsGrant(URI tokenEndpointUri, ClientIdentity clientIdentity, String zoneId, String subdomain, Map<String,String> optionalParameters, boolean disableCacheForRequest)Requests access token from OAuth Server with client credentials.OAuth2TokenResponseretrieveAccessTokenViaJwtBearerTokenGrant(URI tokenEndpoint, ClientIdentity clientIdentity, String token, String subdomain, Map<String,String> optionalParameters, boolean disableCacheForRequest)OAuth2TokenResponseretrieveAccessTokenViaJwtBearerTokenGrant(URI tokenEndpoint, ClientIdentity clientIdentity, String token, Map<String,String> optionalParameters, boolean disableCacheForRequest, String zoneId)OAuth2TokenResponseretrieveAccessTokenViaPasswordGrant(URI tokenEndpoint, ClientIdentity clientIdentity, String username, String password, String subdomain, Map<String,String> optionalParameters, boolean disableCacheForRequest)Requests access token from OAuth Server with user / password.OAuth2TokenResponseretrieveAccessTokenViaRefreshToken(URI tokenEndpointUri, ClientIdentity clientIdentity, String refreshToken, String subdomain, boolean disableCacheForRequest)Requests access token from OAuth Server with refresh-token.OAuth2TokenResponseretrieveAccessTokenViaUserTokenGrant(URI tokenEndpointUri, ClientIdentity clientIdentity, String token, String subdomain, Map<String,String> optionalParameters)Exchanges user access token from OAuth Server with user access token.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.sap.cloud.security.xsuaa.client.OAuth2TokenService
retrieveAccessTokenViaClientCredentialsGrant, retrieveAccessTokenViaClientCredentialsGrant, retrieveAccessTokenViaJwtBearerTokenGrant, retrieveAccessTokenViaPasswordGrant, retrieveAccessTokenViaRefreshToken
-
-
-
-
Constructor Detail
-
AbstractOAuth2TokenService
public AbstractOAuth2TokenService()
-
AbstractOAuth2TokenService
public AbstractOAuth2TokenService(TokenCacheConfiguration tokenCacheConfiguration)
Constructor used to overwrite the default cache configuration.- Parameters:
tokenCacheConfiguration- the cache configuration used to configure the cache.
-
-
Method Detail
-
clearCache
public void clearCache()
Description copied from interface:CacheableClears the cache of the component.- Specified by:
clearCachein interfaceCacheable
-
getCacheConfiguration
@Nonnull public TokenCacheConfiguration getCacheConfiguration()
Description copied from interface:CacheableProvides the cache configuration of the component. Must not be null.- Specified by:
getCacheConfigurationin interfaceCacheable- Returns:
- the cache configuration
-
retrieveAccessTokenViaClientCredentialsGrant
public OAuth2TokenResponse retrieveAccessTokenViaClientCredentialsGrant(@Nonnull URI tokenEndpointUri, @Nonnull ClientIdentity clientIdentity, @Nullable String zoneId, @Nullable String subdomain, @Nullable Map<String,String> optionalParameters, boolean disableCacheForRequest) throws OAuth2ServiceException
Description copied from interface:OAuth2TokenServiceRequests access token from OAuth Server with client credentials.- Specified by:
retrieveAccessTokenViaClientCredentialsGrantin interfaceOAuth2TokenService- Parameters:
tokenEndpointUri- the token endpoint URI.clientIdentity- the client identity of the OAuth client, the recipient of the token.zoneId- Zone identifier - tenant discriminatorsubdomain- optionally indicates what Identity Zone this request goes to by supplying a subdomain (tenant).optionalParameters- optional request parameters, can be null.disableCacheForRequest- set to true disables the token cache for this request.- Returns:
- the OAuth2AccessToken.
- Throws:
OAuth2ServiceException- in case of an error during the http request.
-
retrieveAccessTokenViaUserTokenGrant
public OAuth2TokenResponse retrieveAccessTokenViaUserTokenGrant(@Nonnull URI tokenEndpointUri, @Nonnull ClientIdentity clientIdentity, @Nonnull String token, @Nullable String subdomain, @Nullable Map<String,String> optionalParameters) throws OAuth2ServiceException
Description copied from interface:OAuth2TokenServiceExchanges user access token from OAuth Server with user access token. This endpoint returns only opaque access token, so that another call using {link #retrieveAccessTokenViaRefreshToken} is required.- Specified by:
retrieveAccessTokenViaUserTokenGrantin interfaceOAuth2TokenService- Parameters:
tokenEndpointUri- the token endpoint URI.clientIdentity- the client identity of the OAuth client, the recipient of the token.token- the user bearer token, that represents an authenticated user.subdomain- optionally indicates what Identity Zone this request goes to by supplying a subdomain (tenant).optionalParameters- optional request parameters, can be null.- Returns:
- the OAuth2AccessToken.
- Throws:
OAuth2ServiceException- in case of an error during the http request.
-
retrieveAccessTokenViaRefreshToken
public OAuth2TokenResponse retrieveAccessTokenViaRefreshToken(@Nonnull URI tokenEndpointUri, @Nonnull ClientIdentity clientIdentity, @Nonnull String refreshToken, String subdomain, boolean disableCacheForRequest) throws OAuth2ServiceException
Description copied from interface:OAuth2TokenServiceRequests access token from OAuth Server with refresh-token.- Specified by:
retrieveAccessTokenViaRefreshTokenin interfaceOAuth2TokenService- Parameters:
tokenEndpointUri- the token endpoint URI.clientIdentity- the client identity of the OAuth client, the recipient of the token.refreshToken- the refresh token that was returned along with the access token {link #OAuth2AccessToken}.subdomain- optionally indicates what Identity Zone this request goes to by supplying a subdomain (tenant).disableCacheForRequest- set to true disables the token cache for this request.- Returns:
- the OAuth2AccessToken
- Throws:
OAuth2ServiceException- in case of an error during the http request.
-
retrieveAccessTokenViaPasswordGrant
public OAuth2TokenResponse retrieveAccessTokenViaPasswordGrant(@Nonnull URI tokenEndpoint, @Nonnull ClientIdentity clientIdentity, @Nonnull String username, @Nonnull String password, @Nullable String subdomain, @Nullable Map<String,String> optionalParameters, boolean disableCacheForRequest) throws OAuth2ServiceException
Description copied from interface:OAuth2TokenServiceRequests access token from OAuth Server with user / password.- Specified by:
retrieveAccessTokenViaPasswordGrantin interfaceOAuth2TokenService- Parameters:
tokenEndpoint- the token endpoint URI.clientIdentity- the client identity of the OAuth client, the recipient of the token.username- the username for the user trying to get a tokenpassword- the password for the user trying to get a tokensubdomain- optionally indicates what Identity Zone this request goes to by supplying a subdomain (tenant).optionalParameters- optional request parameters, can be null.disableCacheForRequest- set to true disables the token cache for this request.- Returns:
- the OAuth2AccessToken
- Throws:
OAuth2ServiceException- in case of an error during the http request.
-
retrieveAccessTokenViaJwtBearerTokenGrant
public OAuth2TokenResponse retrieveAccessTokenViaJwtBearerTokenGrant(URI tokenEndpoint, ClientIdentity clientIdentity, String token, @Nullable String subdomain, @Nullable Map<String,String> optionalParameters, boolean disableCacheForRequest) throws OAuth2ServiceException
- Specified by:
retrieveAccessTokenViaJwtBearerTokenGrantin interfaceOAuth2TokenService- Parameters:
tokenEndpoint- the token endpoint URI.clientIdentity- the client identity of the OAuth client, the recipient of the token.token- the JWT token identifying representing the user to be authenticatedsubdomain- optionally indicates what Identity Zone this request goes to by supplying a subdomain (tenant).optionalParameters- optional request parameters, can be null.disableCacheForRequest- set to true disables the token cache for this request.- Returns:
- the OAuth2AccessToken
- Throws:
OAuth2ServiceException- in case of an error during the http request.
-
retrieveAccessTokenViaJwtBearerTokenGrant
public OAuth2TokenResponse retrieveAccessTokenViaJwtBearerTokenGrant(URI tokenEndpoint, ClientIdentity clientIdentity, @Nonnull String token, @Nullable Map<String,String> optionalParameters, boolean disableCacheForRequest, @Nonnull String zoneId) throws OAuth2ServiceException
- Specified by:
retrieveAccessTokenViaJwtBearerTokenGrantin interfaceOAuth2TokenService- Parameters:
tokenEndpoint- the token endpoint URI.clientIdentity- the client identity of the OAuth client, the recipient of the token.token- the JWT token identifying representing the user to be authenticatedoptionalParameters- optional request parameters, can be null.disableCacheForRequest- setting to true disables the token cache for this request.zoneId- zone id of the tenant- Returns:
- the OAuth2AccessToken
- Throws:
OAuth2ServiceException- in case of an error during the http request.
-
requestAccessToken
protected abstract OAuth2TokenResponse requestAccessToken(URI tokenEndpointUri, HttpHeaders headers, Map<String,String> parameters) throws OAuth2ServiceException
Implements the HTTP client specific logic to perform an HTTP request and handle the response.- Parameters:
tokenEndpointUri- the URI of the token endpoint the request must be sent to.headers- the HTTP headers that must be sent with the request.parameters- a map of request parameters that must be sent with the request.- Returns:
- the token response.
- Throws:
OAuth2ServiceException- when the request ot the token endpoint fails or returns an error code.
-
getClock
protected Clock getClock()
By defaultClock.systemUTC()is used to determine of a cached token has reached its expiration (exp) point in time. This method can be overridden for testing purposes.- Returns:
- the
Clock
-
getCacheStatistics
public Object getCacheStatistics()
Description copied from interface:CacheableThis returns an implementation specific statistics object if the underlying cache supports it and cache statistics have been enabled in theCacheConfiguration. Use with care. The type of the statistics object might change in later versions.- Specified by:
getCacheStatisticsin interfaceCacheable- Returns:
- the cache statistics object.
-
-