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
FieldsModifier and TypeFieldDescriptionprivate final org.springframework.security.web.AuthenticationEntryPointEntry point that discards the stale authentication and sends the user to the login page.private final org.springframework.security.web.RedirectStrategyStrategy that redirects, honouring the context path.private final org.springframework.security.web.AuthenticationEntryPointEntry point that sends the user to the second-factor page. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidonAuthenticationFailure(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException exception) Handles a failed authorization request.private static StringredirectUriOf(org.springframework.security.core.AuthenticationException exception) Finds the redirect URI of the request that failed.private static org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationTokenrequestOf(org.springframework.security.core.AuthenticationException exception) Finds the authorization request that failed.private static StringstateOf(org.springframework.security.core.AuthenticationException exception) Finds the state of the request that failed.
-
Field Details
-
redirectStrategy
private final org.springframework.security.web.RedirectStrategy redirectStrategyStrategy that redirects, honouring the context path. -
secondFactorEntryPoint
private final org.springframework.security.web.AuthenticationEntryPoint secondFactorEntryPointEntry point that sends the user to the second-factor page. -
reauthenticationEntryPoint
private final org.springframework.security.web.AuthenticationEntryPoint reauthenticationEntryPointEntry 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:
onAuthenticationFailurein interfaceorg.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
nullwhen the failure does not carry one.
-
stateOf
Finds the state of the request that failed.- Parameters:
exception- the failure.- Returns:
- the state, or
nullwhen 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
nullwhen the failure does not carry one.
-