java.lang.Object
com.irurueta.authserver.authorization.api.web.mfa.StepUpGuard

@Component public class StepUpGuard extends Object
Guards the API operations that remove or reset a second factor (disabling the authenticator app, generating new recovery codes, revoking a trusted device): a stolen token, or a session left open, must not be enough to weaken the account. While the account has a confirmed second factor, the bearer token must show a multi-factor sign-in (acr "urn:irurueta:acr:mfa") whose auth_time is within authserver.mfa.step-up-max-age; otherwise an InsufficientUserAuthenticationException asks the client to step up (RFC 9470). An account without a second factor cannot step up, so it is not asked to. The controllers call it first; the /api/** chain itself is not changed.
  • Field Details

    • hasConfirmedSecondFactorUseCase

      private final HasConfirmedSecondFactorUseCase hasConfirmedSecondFactorUseCase
      Tells whether the account has a confirmed second factor.
    • mfaProperties

      private final MfaProperties mfaProperties
      Multi-factor settings, with the maximum age of the sign-in.
    • clock

      private final Clock clock
      Clock the age of the sign-in is measured with.
  • Constructor Details

    • StepUpGuard

      public StepUpGuard()
  • Method Details

    • requireRecentMultiFactor

      public void requireRecentMultiFactor(UUID userId)
      Requires a recent multi-factor sign-in from the bearer token of the current request.
      Parameters:
      userId - identifier of the account the operation acts on.
      Throws:
      InsufficientUserAuthenticationException - if the account has a confirmed second factor and the token does not show a recent enough multi-factor sign-in.
    • isRecentMultiFactor

      private boolean isRecentMultiFactor(org.springframework.security.oauth2.jwt.Jwt jwt, Duration maxAge)
      Tells whether a token shows a multi-factor sign-in that is recent enough.
      Parameters:
      jwt - the bearer token.
      maxAge - maximum age of the sign-in.
      Returns:
      true when acr is the multi-factor class and auth_time is at most maxAge old (and not in the future).