Class ReplayRejectingJwtValidator

java.lang.Object
com.irurueta.authserver.authorization.api.web.clientauth.ReplayRejectingJwtValidator
All Implemented Interfaces:
org.springframework.security.oauth2.core.OAuth2TokenValidator<org.springframework.security.oauth2.jwt.Jwt>

public class ReplayRejectingJwtValidator extends Object implements org.springframework.security.oauth2.core.OAuth2TokenValidator<org.springframework.security.oauth2.jwt.Jwt>
Validates what the framework's default assertion validators leave out: the assertion must carry a jti, an iat no later than now (within the same clock skew the framework's timestamp validator allows) and an exp no more than the configured maximum lifetime after it, so a future iat cannot stretch the window, and its jti must not have been used before by the same client (RFC 7523, section 3). The use is recorded last, only for an assertion that passed the other checks, so a refused assertion never consumes its identifier. The record is made through RegisterClientAssertionUseCase, so the replay protection is shared by every instance of the server.
  • Field Details

    • DESCRIPTION_PREFIX

      private static final String DESCRIPTION_PREFIX
      Description of the failures.
      See Also:
    • CLOCK_SKEW

      private static final Duration CLOCK_SKEW
      Clock skew tolerated for iat, the default of the framework's JwtTimestampValidator.
    • registerClientAssertion

      private final RegisterClientAssertionUseCase registerClientAssertion
      Remembers the assertions that were accepted.
    • properties

      private final ClientAssertionProperties properties
      Settings of the client assertions, for the longest lifetime.
    • clock

      private final Clock clock
      Source of the current instant.
  • Constructor Details

    • ReplayRejectingJwtValidator

      public ReplayRejectingJwtValidator()
  • Method Details

    • validate

      public org.springframework.security.oauth2.core.OAuth2TokenValidatorResult validate(org.springframework.security.oauth2.jwt.Jwt jwt)
      Checks the assertion and records its use.
      Specified by:
      validate in interface org.springframework.security.oauth2.core.OAuth2TokenValidator<org.springframework.security.oauth2.jwt.Jwt>
      Parameters:
      jwt - the assertion, already verified for signature, issuer, subject, audience and expiry.
      Returns:
      success, or a failure when the jti, iat or exp is missing, iat is in the future, the lifetime is longer than allowed or the jti was already used.
    • failure

      private static org.springframework.security.oauth2.core.OAuth2TokenValidatorResult failure(String reason)
      Builds a failure.
      Parameters:
      reason - what is wrong with the assertion.
      Returns:
      the failed result.