Class StepUpAuthorizationRequestConverter

java.lang.Object
com.irurueta.authserver.authorization.api.web.mfa.StepUpAuthorizationRequestConverter
All Implemented Interfaces:
org.springframework.security.web.authentication.AuthenticationConverter

public class StepUpAuthorizationRequestConverter extends Object implements org.springframework.security.web.authentication.AuthenticationConverter
Applies the OpenID Connect step-up parameters of an authorization request to the authentication of the session. It is installed first among the converters of /oauth2/authorize and never converts anything: it either lets the request go on (returning null) or refuses it. The factors and their instants are read through the FactorTimeline, so a remembered (trusted) device never counts here.
  • max_age: when the primary factor was presented more than that many whole seconds ago, a ReauthenticationRequiredException makes the user sign in again. A session whose factors are unknown (no counted factor of the registry) is left alone, because it could never satisfy the request and the user would loop through the login page.
  • acr_values: when the request asks only for classes of AuthenticationContextClass that the session has not reached, a step-up SecondFactorRequiredException sends the user to the second-factor page, which then asks for a real second factor even on a trusted device. The multi-factor class also satisfies a request for the password class. Classes this server does not know are ignored, as the specification makes acr_values voluntary.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name of the request parameter with the space-separated authentication context classes asked for.
    private final Clock
    Clock the age of the authentication is measured with.
    private final FactorTimeline
    Reads the counted factors of the session and their instants.
    static final String
    Name of the request parameter with the maximum age, in seconds, of the authentication.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static boolean
    acrReached(String acrValues, boolean multiFactor)
    Tells whether the session reached any of the requested classes.
    org.springframework.security.core.Authentication
    convert(jakarta.servlet.http.HttpServletRequest request)
    Checks the step-up parameters of a request.
    private boolean
    maxAgeExceeded(String maxAge, Instant authTime)
    Tells whether the authentication is older than the request tolerates.

    Methods inherited from class java.lang.Object

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

    • MAX_AGE_PARAMETER

      public static final String MAX_AGE_PARAMETER
      Name of the request parameter with the maximum age, in seconds, of the authentication.
      See Also:
    • ACR_VALUES_PARAMETER

      public static final String ACR_VALUES_PARAMETER
      Name of the request parameter with the space-separated authentication context classes asked for.
      See Also:
    • factorTimeline

      private final FactorTimeline factorTimeline
      Reads the counted factors of the session and their instants.
    • clock

      private final Clock clock
      Clock the age of the authentication is measured with.
  • Constructor Details

    • StepUpAuthorizationRequestConverter

      public StepUpAuthorizationRequestConverter()
  • Method Details

    • convert

      public org.springframework.security.core.Authentication convert(jakarta.servlet.http.HttpServletRequest request)
      Checks the step-up parameters of a request.
      Specified by:
      convert in interface org.springframework.security.web.authentication.AuthenticationConverter
      Parameters:
      request - the request.
      Returns:
      always null: this converter only vetoes requests.
      Throws:
      ReauthenticationRequiredException - if max_age is exceeded.
      SecondFactorRequiredException - if the requested acr_values are not reached.
    • maxAgeExceeded

      private boolean maxAgeExceeded(String maxAge, Instant authTime)
      Tells whether the authentication is older than the request tolerates.
      Parameters:
      maxAge - the max_age parameter, may be null; a value that is not a non-negative integer is ignored.
      authTime - the instant the primary factor was presented.
      Returns:
      true when more than maxAge whole seconds have elapsed.
    • acrReached

      private static boolean acrReached(String acrValues, boolean multiFactor)
      Tells whether the session reached any of the requested classes.
      Parameters:
      acrValues - the space-separated acr_values parameter, may be null.
      multiFactor - whether the session presented at least two distinct factors.
      Returns:
      true when no known class is requested or one of them is reached.