public class DefaultRotatingTokenServices extends Object implements org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices, org.springframework.security.oauth2.provider.token.ResourceServerTokenServices, org.springframework.security.oauth2.provider.token.ConsumerTokenServices, org.springframework.beans.factory.InitializingBean
DefaultTokenServices
. Honors refresh token rotation behavior.
Broadleaf primarily supports the notion of oauth refresh tokens in the context of the auth code flow, and only through the use of rotation. This means that, when enabled, a new refresh token is returned with every acquisition of access token from the auth server. Furthermore, each of these refresh tokens may be used only once, with the exception of the boundary defined in
RefreshToken.getRotationExpiration()
.
There are several requirements to use refresh token rotation:
JpaAuthorizedClient.getGrantTypes()
list must include refresh_token
when
that client is targeted in an oauth flowbroadleaf.auth.token.support-refresh-token-rotation
must be set to true
in your application property fileOFFLINE_ACCESS
scopeConstructor and Description |
---|
DefaultRotatingTokenServices(TokenProperties properties) |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Initialize these token services.
|
org.springframework.security.oauth2.common.OAuth2AccessToken |
createAccessToken(org.springframework.security.oauth2.provider.OAuth2Authentication authentication) |
org.springframework.security.oauth2.common.OAuth2AccessToken |
getAccessToken(org.springframework.security.oauth2.provider.OAuth2Authentication authentication) |
protected int |
getAccessTokenValiditySeconds(org.springframework.security.oauth2.provider.OAuth2Request clientAuth)
The access token validity period in seconds
|
String |
getClientId(String tokenValue) |
protected int |
getRefreshTokenValiditySeconds(org.springframework.security.oauth2.provider.OAuth2Request clientAuth)
The refresh token validity period in seconds
|
protected void |
invalidateLine(org.springframework.security.oauth2.common.OAuth2RefreshToken refreshToken)
Delete a refresh token and any associated members in the line
|
protected boolean |
isExpired(org.springframework.security.oauth2.common.OAuth2RefreshToken refreshToken)
Whether or not the refresh token is expired
|
protected boolean |
isSupportRefreshToken(org.springframework.security.oauth2.provider.OAuth2Request clientAuth)
Is a refresh token supported for this client (or the global setting if
clientDetailsService is not set. |
org.springframework.security.oauth2.provider.OAuth2Authentication |
loadAuthentication(String accessTokenValue) |
org.springframework.security.oauth2.common.OAuth2AccessToken |
readAccessToken(String accessToken) |
org.springframework.security.oauth2.common.OAuth2AccessToken |
refreshAccessToken(String refreshTokenValue,
org.springframework.security.oauth2.provider.TokenRequest tokenRequest) |
boolean |
revokeToken(String tokenValue)
Revoke a refresh token
|
protected void |
rotate(org.springframework.security.oauth2.common.OAuth2RefreshToken refreshToken)
Given a refresh token that is being used to request a new access token, perform rotation
setup on it.
|
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(org.springframework.security.oauth2.provider.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 |
setTokenEnhancer(org.springframework.security.oauth2.provider.token.TokenEnhancer accessTokenEnhancer)
An access token enhancer that will be applied to a new token before it is saved in the token
store.
|
void |
setTokenStore(RotatableTokenStore tokenStore)
The persistence strategy for token storage.
|
public DefaultRotatingTokenServices(TokenProperties properties)
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
@Transactional public org.springframework.security.oauth2.common.OAuth2AccessToken createAccessToken(org.springframework.security.oauth2.provider.OAuth2Authentication authentication) throws org.springframework.security.core.AuthenticationException
createAccessToken
in interface org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices
org.springframework.security.core.AuthenticationException
@Transactional(noRollbackFor={org.springframework.security.oauth2.common.exceptions.InvalidTokenException.class,org.springframework.security.oauth2.common.exceptions.InvalidGrantException.class}) public org.springframework.security.oauth2.common.OAuth2AccessToken refreshAccessToken(String refreshTokenValue, org.springframework.security.oauth2.provider.TokenRequest tokenRequest) throws org.springframework.security.core.AuthenticationException
refreshAccessToken
in interface org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices
org.springframework.security.core.AuthenticationException
public org.springframework.security.oauth2.provider.OAuth2Authentication loadAuthentication(String accessTokenValue) throws org.springframework.security.core.AuthenticationException, org.springframework.security.oauth2.common.exceptions.InvalidTokenException
loadAuthentication
in interface org.springframework.security.oauth2.provider.token.ResourceServerTokenServices
org.springframework.security.core.AuthenticationException
org.springframework.security.oauth2.common.exceptions.InvalidTokenException
public boolean revokeToken(String tokenValue)
revokeToken
in interface org.springframework.security.oauth2.provider.token.ConsumerTokenServices
tokenValue
- Refresh tokenpublic org.springframework.security.oauth2.common.OAuth2AccessToken getAccessToken(org.springframework.security.oauth2.provider.OAuth2Authentication authentication)
getAccessToken
in interface org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices
public org.springframework.security.oauth2.common.OAuth2AccessToken readAccessToken(String accessToken)
readAccessToken
in interface org.springframework.security.oauth2.provider.token.ResourceServerTokenServices
public void setTokenEnhancer(org.springframework.security.oauth2.provider.token.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 setTokenStore(RotatableTokenStore 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(org.springframework.security.oauth2.provider.ClientDetailsService clientDetailsService)
setAccessTokenValiditySeconds(int)
.clientDetailsService
- the client details serviceprotected int getAccessTokenValiditySeconds(org.springframework.security.oauth2.provider.OAuth2Request clientAuth)
clientAuth
- the current authorization requestprotected int getRefreshTokenValiditySeconds(org.springframework.security.oauth2.provider.OAuth2Request clientAuth)
clientAuth
- the current authorization requestprotected boolean isSupportRefreshToken(org.springframework.security.oauth2.provider.OAuth2Request clientAuth)
clientDetailsService
is not set.clientAuth
- the current authorization requestprotected void rotate(org.springframework.security.oauth2.common.OAuth2RefreshToken refreshToken)
refreshToken
- A Spring-specific representation of the refresh tokenprotected void invalidateLine(org.springframework.security.oauth2.common.OAuth2RefreshToken refreshToken)
refreshToken
- A Spring-specific representation of the refresh tokenprotected boolean isExpired(org.springframework.security.oauth2.common.OAuth2RefreshToken refreshToken)
refreshToken
- A Spring-specific representation of the refresh tokenCopyright © 2021. All rights reserved.