public class DefaultRotatingTokenStore extends org.springframework.security.oauth2.provider.token.store.JwtTokenStore implements RotatableTokenStore
TokenStore concept used to support the refresh token rotation concept in
Broadleaf. Used in close conjunction with DefaultRotatingTokenServices and
DefaultTokenCleanupServices.| Constructor and Description |
|---|
DefaultRotatingTokenStore(org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter jwtTokenEnhancer,
List<RefreshTokenRepository<RefreshToken>> repositories,
TokenProperties properties,
org.springframework.jdbc.core.JdbcTemplate jdbcTemplate) |
| Modifier and Type | Method and Description |
|---|---|
String |
cleanupBatch(String startingId,
int partition)
Given a refresh token primary key from which to start (i.e.
|
List<RefreshToken> |
findByAncestor(String tokenValue)
Find all refresh token instances derived from the original, root refresh token.
|
int |
getPartition()
Randomly retrieve a partition number with the bounds of the partitions currently available to
the system.
|
int |
getPartition(String tokenValue)
Given an encoded refresh token string, find the partition on which that token is stored.
|
List<Integer> |
getPartitions()
List all the partitions known to the system
|
protected RefreshTokenRepository<RefreshToken> |
getRepository(int partition)
Find the correct handling repository for a given partition identifier
|
String |
getRootId(String tokenValue)
Given an encoded refresh token string, find the root token
JTI for the inheritance
line. |
void |
isolatedRemoveRefreshTokenById(int partition,
String tokenId)
Remove a specific refresh token using its primary key and partition
|
org.springframework.security.oauth2.common.OAuth2RefreshToken |
readRefreshToken(String tokenValue) |
RefreshToken |
readRefreshTokenEntity(String tokenValue)
Given an encoded refresh token string, return the
RefreshToken instance matching from
the datastore. |
void |
removeRefreshToken(org.springframework.security.oauth2.common.OAuth2RefreshToken token) |
protected void |
removeRefreshToken(String tokenValue)
Given an encoded refresh token string, remove the refresh token from the datastore
|
void |
rotate(String tokenValue)
Given an encoded refresh token string, find that refresh token in the datastore and perform
rotation setup on it.
|
void |
storeRefreshToken(org.springframework.security.oauth2.common.OAuth2RefreshToken refreshToken,
org.springframework.security.oauth2.provider.OAuth2Authentication authentication,
String ancestor)
Store a refresh token in the datastore, and include the
JTI value of the original,
root refresh token in the line. |
findTokensByClientId, findTokensByClientIdAndUserName, getAccessToken, readAccessToken, readAuthentication, readAuthentication, readAuthenticationForRefreshToken, removeAccessToken, removeAccessTokenUsingRefreshToken, setApprovalStore, setTokenEnhancer, storeAccessToken, storeRefreshTokenclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitstoreRefreshTokenfindTokensByClientId, findTokensByClientIdAndUserName, getAccessToken, readAccessToken, readAuthentication, readAuthentication, readAuthenticationForRefreshToken, removeAccessToken, removeAccessTokenUsingRefreshToken, storeAccessTokenpublic static final String OID
public DefaultRotatingTokenStore(org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter jwtTokenEnhancer,
List<RefreshTokenRepository<RefreshToken>> repositories,
TokenProperties properties,
org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
@Transactional
public void storeRefreshToken(org.springframework.security.oauth2.common.OAuth2RefreshToken refreshToken,
org.springframework.security.oauth2.provider.OAuth2Authentication authentication,
String ancestor)
RotatableTokenStoreJTI value of the original,
root refresh token in the line.storeRefreshToken in interface RotatableTokenStorerefreshToken - The refresh token to storeauthentication - The current authentication associated with the tokenancestor - The original, root refresh token JTIpublic org.springframework.security.oauth2.common.OAuth2RefreshToken readRefreshToken(String tokenValue)
readRefreshToken in interface org.springframework.security.oauth2.provider.token.TokenStorereadRefreshToken in class org.springframework.security.oauth2.provider.token.store.JwtTokenStorepublic RefreshToken readRefreshTokenEntity(@NonNull String tokenValue)
RotatableTokenStoreRefreshToken instance matching from
the datastore.readRefreshTokenEntity in interface RotatableTokenStoretokenValue - The encoded refresh token stringRefreshToken instance matching from the datastore@Transactional public void removeRefreshToken(org.springframework.security.oauth2.common.OAuth2RefreshToken token)
removeRefreshToken in interface org.springframework.security.oauth2.provider.token.TokenStoreremoveRefreshToken in class org.springframework.security.oauth2.provider.token.store.JwtTokenStore@Transactional(noRollbackFor=org.springframework.security.oauth2.common.exceptions.InvalidTokenException.class)
public void rotate(@NonNull
String tokenValue)
RotatableTokenStorerotate in interface RotatableTokenStoretokenValue - The refresh token to rotate@Transactional(propagation=REQUIRES_NEW) public String cleanupBatch(String startingId, int partition)
RotatableTokenStoreRefreshToken.getId(),
delete all refresh tokens that have expired (either token expiration or rotation expiration)
in a batch. The size of the batch is governed by
TokenProperties.getCleanupBatchSize(). The intent is to call this method in
succession until the response is null, indicating the whole table has been traversed.cleanupBatch in interface RotatableTokenStorestartingId - The refresh token primary key from which to begin expiration detection and
cleanup. This value should be null when run the first time.partition - The partition on which to perform the check (the startingId should
be available in this partition)public List<RefreshToken> findByAncestor(@NonNull String tokenValue)
RotatableTokenStorefindByAncestor in interface RotatableTokenStoretokenValue - The original, root refresh tokenRefreshTokenRepository.findByAncestor(String)@Transactional(propagation=REQUIRES_NEW)
public void isolatedRemoveRefreshTokenById(int partition,
@NonNull
String tokenId)
RotatableTokenStoreisolatedRemoveRefreshTokenById in interface RotatableTokenStorepartition - The partition shard in which the refresh token entity existstokenId - The primary key value of the refresh tokenpublic int getPartition()
RotatableTokenStoregetPartition in interface RotatableTokenStorepublic int getPartition(@NonNull
String tokenValue)
RotatableTokenStoregetPartition in interface RotatableTokenStoretokenValue - The encoded refresh token stringpublic List<Integer> getPartitions()
RotatableTokenStoregetPartitions in interface RotatableTokenStore@NonNull public String getRootId(@NonNull String tokenValue)
RotatableTokenStoreJTI for the inheritance
line.getRootId in interface RotatableTokenStoretokenValue - The encoded refresh token stringJTI for the inheritance line. If this token is itself the
root, then the response will be this token's own JTI.protected RefreshTokenRepository<RefreshToken> getRepository(int partition)
partition - The partition identifierprotected void removeRefreshToken(String tokenValue)
tokenValue - The encoded refresh token stringCopyright © 2021. All rights reserved.