public class DefaultTokenServices extends Object implements AuthorizationServerTokenServices, ResourceServerTokenServices, ConsumerTokenServices, InitializingBean
TokenEnhancer
which will be called after the access and
refresh tokens have been generated but before they are stored.
Persistence is delegated to a TokenStore
implementation and customization of the access token to a
TokenEnhancer
.
Constructor and Description |
---|
DefaultTokenServices() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Initialize these token services.
|
OAuth2AccessToken |
createAccessToken(OAuth2Authentication authentication)
Create an access token associated with the specified credentials.
|
OAuth2AccessToken |
getAccessToken(OAuth2Authentication authentication)
Retrieve an access token stored against the provided authentication key, if it exists.
|
protected int |
getAccessTokenValiditySeconds(OAuth2Request clientAuth)
The access token validity period in seconds
|
String |
getClientId(String tokenValue) |
protected int |
getRefreshTokenValiditySeconds(OAuth2Request clientAuth)
The refresh token validity period in seconds
|
protected boolean |
isExpired(OAuth2RefreshToken refreshToken) |
protected boolean |
isSupportRefreshToken(OAuth2Request clientAuth)
Is a refresh token supported for this client (or the global setting if
clientDetailsService is not set. |
OAuth2Authentication |
loadAuthentication(String accessTokenValue)
Load the credentials for the specified access token.
|
OAuth2AccessToken |
readAccessToken(String accessToken)
Retrieve the full access token details from just the value.
|
OAuth2AccessToken |
refreshAccessToken(String refreshTokenValue,
TokenRequest tokenRequest)
Refresh an access token.
|
boolean |
revokeToken(String tokenValue) |
void |
setAccessTokenValiditySeconds(int accessTokenValiditySeconds)
The default validity (in seconds) of the access token.
|
void |
setAuthenticationManager(org.springframework.security.authentication.AuthenticationManager authenticationManager)
An authentication manager that will be used (if provided) to check the user authentication when a token is
refreshed.
|
void |
setClientDetailsService(ClientDetailsService clientDetailsService)
The client details service to use for looking up clients (if necessary).
|
void |
setRefreshTokenValiditySeconds(int refreshTokenValiditySeconds)
The validity (in seconds) of the refresh token.
|
void |
setReuseRefreshToken(boolean reuseRefreshToken)
Whether to reuse refresh tokens (until expired).
|
void |
setSupportRefreshToken(boolean supportRefreshToken)
Whether to support the refresh token.
|
void |
setTokenEnhancer(TokenEnhancer accessTokenEnhancer)
An access token enhancer that will be applied to a new token before it is saved in the token store.
|
void |
setTokenStore(TokenStore tokenStore)
The persistence strategy for token storage.
|
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
@Transactional public OAuth2AccessToken createAccessToken(OAuth2Authentication authentication) throws org.springframework.security.core.AuthenticationException
AuthorizationServerTokenServices
createAccessToken
in interface AuthorizationServerTokenServices
authentication
- The credentials associated with the access token.org.springframework.security.core.AuthenticationException
- If the credentials are inadequate.@Transactional(noRollbackFor={InvalidTokenException.class,InvalidGrantException.class}) public OAuth2AccessToken refreshAccessToken(String refreshTokenValue, TokenRequest tokenRequest) throws org.springframework.security.core.AuthenticationException
AuthorizationServerTokenServices
refreshAccessToken
in interface AuthorizationServerTokenServices
refreshTokenValue
- The details about the refresh token.tokenRequest
- The incoming token request.org.springframework.security.core.AuthenticationException
- If the refresh token is invalid or expired.public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication)
AuthorizationServerTokenServices
getAccessToken
in interface AuthorizationServerTokenServices
authentication
- the authentication key for the access tokenprotected boolean isExpired(OAuth2RefreshToken refreshToken)
public OAuth2AccessToken readAccessToken(String accessToken)
ResourceServerTokenServices
readAccessToken
in interface ResourceServerTokenServices
accessToken
- the token valuepublic OAuth2Authentication loadAuthentication(String accessTokenValue) throws org.springframework.security.core.AuthenticationException, InvalidTokenException
ResourceServerTokenServices
loadAuthentication
in interface ResourceServerTokenServices
accessTokenValue
- The access token value.org.springframework.security.core.AuthenticationException
- If the access token is expiredInvalidTokenException
- if the token isn't validpublic boolean revokeToken(String tokenValue)
revokeToken
in interface ConsumerTokenServices
protected int getAccessTokenValiditySeconds(OAuth2Request clientAuth)
clientAuth
- the current authorization requestprotected int getRefreshTokenValiditySeconds(OAuth2Request clientAuth)
clientAuth
- the current authorization requestprotected boolean isSupportRefreshToken(OAuth2Request clientAuth)
clientDetailsService
is not set.clientAuth
- the current authorization requestpublic void setTokenEnhancer(TokenEnhancer accessTokenEnhancer)
accessTokenEnhancer
- the access token enhancer to setpublic void setRefreshTokenValiditySeconds(int refreshTokenValiditySeconds)
refreshTokenValiditySeconds
- The validity (in seconds) of the refresh token.public void setAccessTokenValiditySeconds(int accessTokenValiditySeconds)
accessTokenValiditySeconds
- The validity (in seconds) of the access token.public void setSupportRefreshToken(boolean supportRefreshToken)
supportRefreshToken
- Whether to support the refresh token.public void setReuseRefreshToken(boolean reuseRefreshToken)
reuseRefreshToken
- Whether to reuse refresh tokens (until expired).public void setTokenStore(TokenStore tokenStore)
tokenStore
- the store for access and refresh tokens.public void setAuthenticationManager(org.springframework.security.authentication.AuthenticationManager authenticationManager)
authenticationManager
- the authenticationManager to setpublic void setClientDetailsService(ClientDetailsService clientDetailsService)
setAccessTokenValiditySeconds(int)
.clientDetailsService
- the client details serviceCopyright © 2019. All rights reserved.