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

    Fields
    Modifier and Type
    Field
    Description
    private final org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService
    Service that stores the authorizations.
    private static final String
    Query returning the authorization a rotated-out token belonged to.
    private static final String
    Algorithm that hashes the stored tokens.
    private static final String
    Statement recording a rotated-out token.
    private final org.springframework.jdbc.core.simple.JdbcClient
    JDBC client used to run the statements.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.security.oauth2.server.authorization.OAuth2Authorization
     
    org.springframework.security.oauth2.server.authorization.OAuth2Authorization
    findByToken(String token, org.springframework.security.oauth2.server.authorization.OAuth2TokenType tokenType)
     
    (package private) static String
    hash(String token)
    Hashes a token value, so that the stored values cannot be used as tokens.
    private static String
    refreshTokenValue(org.springframework.security.oauth2.server.authorization.OAuth2Authorization authorization)
    Reads the value of the refresh token of an authorization.
    void
    remove(org.springframework.security.oauth2.server.authorization.OAuth2Authorization authorization)
     
    void
    save(org.springframework.security.oauth2.server.authorization.OAuth2Authorization authorization)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • HASH_ALGORITHM

      private static final String HASH_ALGORITHM
      Algorithm that hashes the stored tokens.
      See Also:
    • INSERT_CONSUMED

      private static final String INSERT_CONSUMED
      Statement recording a rotated-out token.
      See Also:
    • FIND_CONSUMED

      private static final String FIND_CONSUMED
      Query returning the authorization a rotated-out token belonged to.
      See Also:
    • delegate

      private final org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService delegate
      Service that stores the authorizations.
    • jdbcClient

      private final org.springframework.jdbc.core.simple.JdbcClient jdbcClient
      JDBC 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:
      save in interface org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService
    • remove

      public void remove(org.springframework.security.oauth2.server.authorization.OAuth2Authorization authorization)
      Specified by:
      remove in interface org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService
    • findById

      public org.springframework.security.oauth2.server.authorization.OAuth2Authorization findById(String id)
      Specified by:
      findById in interface org.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:
      findByToken in interface org.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 null when the authorization has no refresh token.
    • hash

      static String hash(String token)
      Hashes a token value, so that the stored values cannot be used as tokens.
      Parameters:
      token - token value.
      Returns:
      the hexadecimal SHA-256 digest.