Class DeviceVerificationErrorHandler

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

public class DeviceVerificationErrorHandler extends Object implements org.springframework.security.web.authentication.AuthenticationFailureHandler
Error handler of the device verification endpoint. A user who owes a second factor goes where the authorization endpoint sends them (the secondFactorHandler); too many attempts are answered 429 with a Retry-After header; any other failure (an unknown, expired or already used code, a denied consent) sends the browser back to the verification page with ?error, which says nothing about the reason, so a code cannot be told apart from a wrong one. Installing a handler replaces the framework's, which only answers 400.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final String
    Name of the parameter that tells the verification page that the previous attempt failed.
    private final org.springframework.security.web.RedirectStrategy
    Strategy that redirects, honouring the context path.
    private final org.springframework.security.web.authentication.AuthenticationFailureHandler
    Handler of the failures that send the user to the second-factor page or to a new sign-in.
    private final String
    Path of the verification page.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onAuthenticationFailure(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException exception)
    Handles a failed verification request.
    private static long
    Rounds the wait up to whole seconds, at least one.

    Methods inherited from class java.lang.Object

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

    • ERROR_PARAMETER

      static final String ERROR_PARAMETER
      Name of the parameter that tells the verification page that the previous attempt failed.
      See Also:
    • redirectStrategy

      private final org.springframework.security.web.RedirectStrategy redirectStrategy
      Strategy that redirects, honouring the context path.
    • secondFactorHandler

      private final org.springframework.security.web.authentication.AuthenticationFailureHandler secondFactorHandler
      Handler of the failures that send the user to the second-factor page or to a new sign-in.
    • verificationPath

      private final String verificationPath
      Path of the verification page.
  • Constructor Details

    • DeviceVerificationErrorHandler

      public DeviceVerificationErrorHandler()
  • Method Details

    • onAuthenticationFailure

      public void onAuthenticationFailure(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException exception) throws IOException, jakarta.servlet.ServletException
      Handles a failed verification request.
      Specified by:
      onAuthenticationFailure in interface org.springframework.security.web.authentication.AuthenticationFailureHandler
      Parameters:
      request - the request.
      response - the response.
      exception - why the request failed.
      Throws:
      IOException - if the response cannot be written.
      jakarta.servlet.ServletException - if the second-factor handler fails.
    • retryAfterSeconds

      private static long retryAfterSeconds(DeviceVerificationRateLimitedException exception)
      Rounds the wait up to whole seconds, at least one.
      Parameters:
      exception - the failure.
      Returns:
      the seconds to wait.