Class ReuseDetectingAuthorizationService
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.tokens.ReuseDetectingAuthorizationService
- All Implemented Interfaces:
org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService
public class ReuseDetectingAuthorizationService
extends Object
implements org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService
Decorator of an
OAuth2AuthorizationService that detects the reuse of rotated refresh tokens. When saving an
authorization whose refresh token changed, the hash of the old token is recorded; when a token that was already
rotated out is presented, the authorization it belonged to is revoked, because the token was either stolen or
replayed.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationServiceService that stores the authorizations.private static final StringQuery returning the authorization a rotated-out token belonged to.private static final StringAlgorithm that hashes the stored tokens.private static final StringStatement recording a rotated-out token.private final org.springframework.jdbc.core.simple.JdbcClientJDBC client used to run the statements. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.security.oauth2.server.authorization.OAuth2Authorizationorg.springframework.security.oauth2.server.authorization.OAuth2AuthorizationfindByToken(String token, org.springframework.security.oauth2.server.authorization.OAuth2TokenType tokenType) (package private) static StringHashes a token value, so that the stored values cannot be used as tokens.private static StringrefreshTokenValue(org.springframework.security.oauth2.server.authorization.OAuth2Authorization authorization) Reads the value of the refresh token of an authorization.voidremove(org.springframework.security.oauth2.server.authorization.OAuth2Authorization authorization) voidsave(org.springframework.security.oauth2.server.authorization.OAuth2Authorization authorization)
-
Field Details
-
HASH_ALGORITHM
Algorithm that hashes the stored tokens.- See Also:
-
INSERT_CONSUMED
Statement recording a rotated-out token.- See Also:
-
FIND_CONSUMED
Query returning the authorization a rotated-out token belonged to.- See Also:
-
delegate
private final org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService delegateService that stores the authorizations. -
jdbcClient
private final org.springframework.jdbc.core.simple.JdbcClient jdbcClientJDBC client used to run the statements.
-
-
Constructor Details
-
ReuseDetectingAuthorizationService
public ReuseDetectingAuthorizationService()
-
-
Method Details
-
save
public void save(org.springframework.security.oauth2.server.authorization.OAuth2Authorization authorization) - Specified by:
savein interfaceorg.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService
-
remove
public void remove(org.springframework.security.oauth2.server.authorization.OAuth2Authorization authorization) - Specified by:
removein interfaceorg.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService
-
findById
public org.springframework.security.oauth2.server.authorization.OAuth2Authorization findById(String id) - Specified by:
findByIdin interfaceorg.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService
-
findByToken
public org.springframework.security.oauth2.server.authorization.OAuth2Authorization findByToken(String token, org.springframework.security.oauth2.server.authorization.OAuth2TokenType tokenType) - Specified by:
findByTokenin interfaceorg.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService
-
refreshTokenValue
private static String refreshTokenValue(org.springframework.security.oauth2.server.authorization.OAuth2Authorization authorization) Reads the value of the refresh token of an authorization.- Parameters:
authorization- the authorization.- Returns:
- the token value, or
nullwhen the authorization has no refresh token.
-
hash
Hashes a token value, so that the stored values cannot be used as tokens.- Parameters:
token- token value.- Returns:
- the hexadecimal SHA-256 digest.
-