Class DefaultRotatingTokenStore
- java.lang.Object
-
- org.springframework.security.oauth2.provider.token.store.JwtTokenStore
-
- com.broadleafcommerce.auth.token.service.DefaultRotatingTokenStore
-
- All Implemented Interfaces:
RotatableTokenStore,org.springframework.security.oauth2.provider.token.TokenStore
public class DefaultRotatingTokenStore extends org.springframework.security.oauth2.provider.token.store.JwtTokenStore implements RotatableTokenStore
A specializedTokenStoreconcept used to support the refresh token rotation concept in Broadleaf. Used in close conjunction withDefaultRotatingTokenServicesandDefaultTokenCleanupServices.
-
-
Constructor Summary
Constructors Constructor Description DefaultRotatingTokenStore(org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter jwtTokenEnhancer, List<RefreshTokenRepository<RefreshToken>> repositories, TokenProperties properties, org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringcleanupBatch(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.intgetPartition()Randomly retrieve a partition number with the bounds of the partitions currently available to the system.intgetPartition(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 systemprotected RefreshTokenRepository<RefreshToken>getRepository(int partition)Find the correct handling repository for a given partition identifierStringgetRootId(String tokenValue)Given an encoded refresh token string, find the root tokenJTIfor the inheritance line.voidisolatedRemoveRefreshTokenById(int partition, String tokenId)Remove a specific refresh token using its primary key and partitionorg.springframework.security.oauth2.common.OAuth2RefreshTokenreadRefreshToken(String tokenValue)RefreshTokenreadRefreshTokenEntity(String tokenValue)Given an encoded refresh token string, return theRefreshTokeninstance matching from the datastore.protected voidremoveRefreshToken(String tokenValue)Given an encoded refresh token string, remove the refresh token from the datastorevoidremoveRefreshToken(org.springframework.security.oauth2.common.OAuth2RefreshToken token)voidrotate(String tokenValue)Given an encoded refresh token string, find that refresh token in the datastore and perform rotation setup on it.voidstoreRefreshToken(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 theJTIvalue of the original, root refresh token in the line.-
Methods inherited from class org.springframework.security.oauth2.provider.token.store.JwtTokenStore
findTokensByClientId, findTokensByClientIdAndUserName, getAccessToken, readAccessToken, readAuthentication, readAuthentication, readAuthenticationForRefreshToken, removeAccessToken, removeAccessTokenUsingRefreshToken, setApprovalStore, setTokenEnhancer, storeAccessToken, storeRefreshToken
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.broadleafcommerce.auth.token.service.RotatableTokenStore
storeRefreshToken
-
Methods inherited from interface org.springframework.security.oauth2.provider.token.TokenStore
findTokensByClientId, findTokensByClientIdAndUserName, getAccessToken, readAccessToken, readAuthentication, readAuthentication, readAuthenticationForRefreshToken, removeAccessToken, removeAccessTokenUsingRefreshToken, storeAccessToken
-
-
-
-
Field Detail
-
OID
public static final String OID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultRotatingTokenStore
public DefaultRotatingTokenStore(org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter jwtTokenEnhancer, List<RefreshTokenRepository<RefreshToken>> repositories, TokenProperties properties, org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
-
-
Method Detail
-
storeRefreshToken
@Transactional public void storeRefreshToken(org.springframework.security.oauth2.common.OAuth2RefreshToken refreshToken, org.springframework.security.oauth2.provider.OAuth2Authentication authentication, String ancestor)Description copied from interface:RotatableTokenStoreStore a refresh token in the datastore, and include theJTIvalue of the original, root refresh token in the line.- Specified by:
storeRefreshTokenin interfaceRotatableTokenStore- Parameters:
refreshToken- The refresh token to storeauthentication- The current authentication associated with the tokenancestor- The original, root refresh token JTI
-
readRefreshToken
public org.springframework.security.oauth2.common.OAuth2RefreshToken readRefreshToken(String tokenValue)
- Specified by:
readRefreshTokenin interfaceorg.springframework.security.oauth2.provider.token.TokenStore- Overrides:
readRefreshTokenin classorg.springframework.security.oauth2.provider.token.store.JwtTokenStore
-
readRefreshTokenEntity
public RefreshToken readRefreshTokenEntity(@NonNull String tokenValue)
Description copied from interface:RotatableTokenStoreGiven an encoded refresh token string, return theRefreshTokeninstance matching from the datastore.- Specified by:
readRefreshTokenEntityin interfaceRotatableTokenStore- Parameters:
tokenValue- The encoded refresh token string- Returns:
- The
RefreshTokeninstance matching from the datastore
-
removeRefreshToken
@Transactional public void removeRefreshToken(org.springframework.security.oauth2.common.OAuth2RefreshToken token)
- Specified by:
removeRefreshTokenin interfaceorg.springframework.security.oauth2.provider.token.TokenStore- Overrides:
removeRefreshTokenin classorg.springframework.security.oauth2.provider.token.store.JwtTokenStore
-
rotate
@Transactional(noRollbackFor=org.springframework.security.oauth2.common.exceptions.InvalidTokenException.class) public void rotate(@NonNull String tokenValue)Description copied from interface:RotatableTokenStoreGiven an encoded refresh token string, find that refresh token in the datastore and perform rotation setup on it. Specifically, mark the token as rotation and set its rotation expiration.- Specified by:
rotatein interfaceRotatableTokenStore- Parameters:
tokenValue- The refresh token to rotate
-
cleanupBatch
@Transactional(propagation=REQUIRES_NEW) public String cleanupBatch(String startingId, int partition)
Description copied from interface:RotatableTokenStoreGiven a refresh token primary key from which to start (i.e.RefreshToken.getId(), delete all refresh tokens that have expired (either token expiration or rotation expiration) in a batch. The size of the batch is governed byTokenProperties.getCleanupBatchSize(). The intent is to call this method in succession until the response is null, indicating the whole table has been traversed.- Specified by:
cleanupBatchin interfaceRotatableTokenStore- Parameters:
startingId- 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 (thestartingIdshould be available in this partition)- Returns:
- The last member of the batch. Use this value in the next call to cleanupBatch. This can be null if no records are available, only one record is available, or if the end of the batch is reached.
-
findByAncestor
public List<RefreshToken> findByAncestor(@NonNull String tokenValue)
Description copied from interface:RotatableTokenStoreFind all refresh token instances derived from the original, root refresh token.- Specified by:
findByAncestorin interfaceRotatableTokenStore- Parameters:
tokenValue- The original, root refresh token- Returns:
- All refresh token instances derived from the original, root refresh token
- See Also:
RefreshTokenRepository.findByAncestor(String)
-
isolatedRemoveRefreshTokenById
@Transactional(propagation=REQUIRES_NEW) public void isolatedRemoveRefreshTokenById(int partition, @NonNull String tokenId)Description copied from interface:RotatableTokenStoreRemove a specific refresh token using its primary key and partition- Specified by:
isolatedRemoveRefreshTokenByIdin interfaceRotatableTokenStore- Parameters:
partition- The partition shard in which the refresh token entity existstokenId- The primary key value of the refresh token
-
getPartition
public int getPartition()
Description copied from interface:RotatableTokenStoreRandomly retrieve a partition number with the bounds of the partitions currently available to the system. This is the primary load balancing measure for distributing members across the available shards.- Specified by:
getPartitionin interfaceRotatableTokenStore- Returns:
- Random partition number with the bounds of the partitions currently available
-
getPartition
public int getPartition(@NonNull String tokenValue)Description copied from interface:RotatableTokenStoreGiven an encoded refresh token string, find the partition on which that token is stored.- Specified by:
getPartitionin interfaceRotatableTokenStore- Parameters:
tokenValue- The encoded refresh token string- Returns:
- The partition on which that token is stored
-
getPartitions
public List<Integer> getPartitions()
Description copied from interface:RotatableTokenStoreList all the partitions known to the system- Specified by:
getPartitionsin interfaceRotatableTokenStore- Returns:
- All the partitions known to the system
-
getRootId
@NonNull public String getRootId(@NonNull String tokenValue)
Description copied from interface:RotatableTokenStoreGiven an encoded refresh token string, find the root tokenJTIfor the inheritance line.- Specified by:
getRootIdin interfaceRotatableTokenStore- Parameters:
tokenValue- The encoded refresh token string- Returns:
- The the root token
JTIfor the inheritance line. If this token is itself the root, then the response will be this token's ownJTI.
-
getRepository
protected RefreshTokenRepository<RefreshToken> getRepository(int partition)
Find the correct handling repository for a given partition identifier- Parameters:
partition- The partition identifier- Returns:
- The handling repository
-
removeRefreshToken
protected void removeRefreshToken(String tokenValue)
Given an encoded refresh token string, remove the refresh token from the datastore- Parameters:
tokenValue- The encoded refresh token string
-
-