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, storeRefreshToken
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
storeRefreshToken
findTokensByClientId, findTokensByClientIdAndUserName, getAccessToken, readAccessToken, readAuthentication, readAuthentication, readAuthenticationForRefreshToken, removeAccessToken, removeAccessTokenUsingRefreshToken, storeAccessToken
public 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)
RotatableTokenStore
JTI
value of the original,
root refresh token in the line.storeRefreshToken
in interface RotatableTokenStore
refreshToken
- 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.TokenStore
readRefreshToken
in class org.springframework.security.oauth2.provider.token.store.JwtTokenStore
public RefreshToken readRefreshTokenEntity(@NonNull String tokenValue)
RotatableTokenStore
RefreshToken
instance matching from
the datastore.readRefreshTokenEntity
in interface RotatableTokenStore
tokenValue
- 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.TokenStore
removeRefreshToken
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)
RotatableTokenStore
rotate
in interface RotatableTokenStore
tokenValue
- The refresh token to rotate@Transactional(propagation=REQUIRES_NEW) public String cleanupBatch(String startingId, int partition)
RotatableTokenStore
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 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 RotatableTokenStore
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 (the startingId
should
be available in this partition)public List<RefreshToken> findByAncestor(@NonNull String tokenValue)
RotatableTokenStore
findByAncestor
in interface RotatableTokenStore
tokenValue
- The original, root refresh tokenRefreshTokenRepository.findByAncestor(String)
@Transactional(propagation=REQUIRES_NEW) public void isolatedRemoveRefreshTokenById(int partition, @NonNull String tokenId)
RotatableTokenStore
isolatedRemoveRefreshTokenById
in interface RotatableTokenStore
partition
- The partition shard in which the refresh token entity existstokenId
- The primary key value of the refresh tokenpublic int getPartition()
RotatableTokenStore
getPartition
in interface RotatableTokenStore
public int getPartition(@NonNull String tokenValue)
RotatableTokenStore
getPartition
in interface RotatableTokenStore
tokenValue
- The encoded refresh token stringpublic List<Integer> getPartitions()
RotatableTokenStore
getPartitions
in interface RotatableTokenStore
@NonNull public String getRootId(@NonNull String tokenValue)
RotatableTokenStore
JTI
for the inheritance
line.getRootId
in interface RotatableTokenStore
tokenValue
- 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.