Class DeviceVerificationRequestGuard

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

public class DeviceVerificationRequestGuard extends Object implements org.springframework.security.web.authentication.AuthenticationConverter
Guards the device verification endpoint. It is installed first among the converters of the endpoint and never converts anything: it either lets the request go on (returning null) or refuses it. Every request that carries a user code (the code typed on the verification page, a link that carries it, and the consent decision) is counted against the limit on the attempts, and the multi-factor policy of the account and of the client must be satisfied, as the authorization endpoint requires before it issues a code: a user who owes a second factor is sent to the second-factor page and resumes afterwards. The framework's own MFA customizer covers only /oauth2/authorize.

The client is the one the device authorization stored for the user code was issued to, because the code typed on the page (or carried by the link) is the only thing the request names: so a client that requires multi-factor authentication is enforced even when it skips the consent page. Only when no authorization holds the code (an unknown or expired one, which the endpoint refuses anyway) is the client_id of the consent decision used.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Applies the multi-factor policy.
    private final org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService
    Finds the device authorization of a user code.
    private static final Pattern
    Everything a user may type around the letters and digits of a code (dashes, spaces).
    Limits the attempts.
    private final org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository
    Finds the client of a device authorization.
    private static final int
    Position of the dash the framework stores a user code with.
    private static final int
    Number of letters and digits of a user code.
    (package private) static final org.springframework.security.oauth2.server.authorization.OAuth2TokenType
    Type of the token the user code is stored as.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private String
    clientIdOf(jakarta.servlet.http.HttpServletRequest request)
    Finds the client a request is about: the client of the device authorization stored for its user code, or the client_id parameter when no authorization holds that code.
    org.springframework.security.core.Authentication
    convert(jakarta.servlet.http.HttpServletRequest request)
    Checks the request.
    private static Optional<String>
    normalize(String userCode)
    Normalises a user code as the framework stores it: upper case letters and digits in two groups of four, separated by a dash.

    Methods inherited from class java.lang.Object

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

    • USER_CODE_TOKEN_TYPE

      static final org.springframework.security.oauth2.server.authorization.OAuth2TokenType USER_CODE_TOKEN_TYPE
      Type of the token the user code is stored as.
    • USER_CODE_LENGTH

      private static final int USER_CODE_LENGTH
      Number of letters and digits of a user code.
      See Also:
    • USER_CODE_GROUP

      private static final int USER_CODE_GROUP
      Position of the dash the framework stores a user code with.
      See Also:
    • NOT_ALPHANUMERIC

      private static final Pattern NOT_ALPHANUMERIC
      Everything a user may type around the letters and digits of a code (dashes, spaces).
    • rateLimiter

      private final DeviceVerificationRateLimiter rateLimiter
      Limits the attempts.
    • authorizationManager

      private final MfaAuthorizationManager authorizationManager
      Applies the multi-factor policy.
    • authorizationService

      private final org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService authorizationService
      Finds the device authorization of a user code.
    • registeredClientRepository

      private final org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository registeredClientRepository
      Finds the client of a device authorization.
  • Constructor Details

    • DeviceVerificationRequestGuard

      public DeviceVerificationRequestGuard()
  • Method Details

    • convert

      public org.springframework.security.core.Authentication convert(jakarta.servlet.http.HttpServletRequest request)
      Checks the 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:
      DeviceVerificationRateLimitedException - if the client address or the user made too many attempts.
      SecondFactorRequiredException - if the user still owes a second factor.
    • clientIdOf

      private String clientIdOf(jakarta.servlet.http.HttpServletRequest request)
      Finds the client a request is about: the client of the device authorization stored for its user code, or the client_id parameter when no authorization holds that code.
      Parameters:
      request - the request.
      Returns:
      the client id, or null when neither tells it.
    • normalize

      private static Optional<String> normalize(String userCode)
      Normalises a user code as the framework stores it: upper case letters and digits in two groups of four, separated by a dash.
      Parameters:
      userCode - the code as typed, may be null.
      Returns:
      the stored form, or empty when the value cannot be a user code.