Class SecondFactorErrorResponseHandler

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

public class SecondFactorErrorResponseHandler extends Object implements org.springframework.security.web.authentication.AuthenticationFailureHandler
Error handler of the authorization endpoint: a SecondFactorRequiredException goes to the entry point of the second-factor page, a ReauthenticationRequiredException to the one that forces a new sign-in, and any other error is answered as Spring Authorization Server's own handler does (a redirect to the client's redirect URI carrying the error, or a 400 when there is none). Installing a handler replaces the framework's, which is not reachable, so the default behaviour is reproduced here.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final org.springframework.security.web.AuthenticationEntryPoint
    Entry point that discards the stale authentication and sends the user to the login page.
    private final org.springframework.security.web.RedirectStrategy
    Strategy that redirects, honouring the context path.
    private final org.springframework.security.web.AuthenticationEntryPoint
    Entry point that sends the user to the second-factor 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 authorization request.
    private static String
    redirectUriOf(org.springframework.security.core.AuthenticationException exception)
    Finds the redirect URI of the request that failed.
    private static org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken
    requestOf(org.springframework.security.core.AuthenticationException exception)
    Finds the authorization request that failed.
    private static String
    stateOf(org.springframework.security.core.AuthenticationException exception)
    Finds the state of the request that failed.

    Methods inherited from class java.lang.Object

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

    • redirectStrategy

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

      private final org.springframework.security.web.AuthenticationEntryPoint secondFactorEntryPoint
      Entry point that sends the user to the second-factor page.
    • reauthenticationEntryPoint

      private final org.springframework.security.web.AuthenticationEntryPoint reauthenticationEntryPoint
      Entry point that discards the stale authentication and sends the user to the login page.
  • Constructor Details

    • SecondFactorErrorResponseHandler

      public SecondFactorErrorResponseHandler()
  • 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 authorization 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 entry point fails.
    • redirectUriOf

      private static String redirectUriOf(org.springframework.security.core.AuthenticationException exception)
      Finds the redirect URI of the request that failed.
      Parameters:
      exception - the failure.
      Returns:
      the redirect URI, or null when the failure does not carry one.
    • stateOf

      private static String stateOf(org.springframework.security.core.AuthenticationException exception)
      Finds the state of the request that failed.
      Parameters:
      exception - the failure.
      Returns:
      the state, or null when the failure does not carry one.
    • requestOf

      private static org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken requestOf(org.springframework.security.core.AuthenticationException exception)
      Finds the authorization request that failed.
      Parameters:
      exception - the failure.
      Returns:
      the request, or null when the failure does not carry one.