Class OAuth2LoginSystemAuthenticationFailureExceptionMapping
java.lang.Object
com.broadleafcommerce.auth.security.web.authentication.AuthenticationFailureExceptionMapping
com.broadleafcommerce.auth.security.web.authentication.OAuth2LoginSystemAuthenticationFailureExceptionMapping
- All Implemented Interfaces:
org.springframework.core.Ordered
public class OAuth2LoginSystemAuthenticationFailureExceptionMapping
extends AuthenticationFailureExceptionMapping
AuthenticationFailureExceptionMapping that handles system-level (not user-caused) issues
that might occur with third party login flows. This allows for a more clear message to the
end-user that something problematic has occurred internally and not necessarily due to input they
have provided.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default value forgetOrder()for this implementation.Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionOAuth2LoginSystemAuthenticationFailureExceptionMapping(String redirectUrl, org.springframework.security.web.util.matcher.RequestMatcher requestMatcher) -
Method Summary
Modifier and TypeMethodDescriptionintgetOrder()protected org.springframework.security.web.util.matcher.RequestMatcherprotected booleanisSystemFailure(jakarta.servlet.http.HttpServletRequest request, org.springframework.security.core.AuthenticationException exception) Reports whether the givenexceptionis due to a system failure.booleanshouldApply(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException exception) This is a method called byDefaultExceptionMappingAuthenticationFailureHandlerto determine whether this failure mapping should apply for a particular request/exception flow.Methods inherited from class com.broadleafcommerce.auth.security.web.authentication.AuthenticationFailureExceptionMapping
canEqual, equals, getException, getRedirectUrl, getRootCauseException, hashCode, toString
-
Field Details
-
DEFAULT_ORDER
public static final int DEFAULT_ORDERThe default value forgetOrder()for this implementation. This is set to a low precedence to allow more specific exception handlers to beat this one.- See Also:
-
-
Constructor Details
-
OAuth2LoginSystemAuthenticationFailureExceptionMapping
public OAuth2LoginSystemAuthenticationFailureExceptionMapping(String redirectUrl, org.springframework.security.web.util.matcher.RequestMatcher requestMatcher)
-
-
Method Details
-
shouldApply
public boolean shouldApply(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException exception) Description copied from class:AuthenticationFailureExceptionMappingThis is a method called by
DefaultExceptionMappingAuthenticationFailureHandlerto determine whether this failure mapping should apply for a particular request/exception flow.For backward compatibility, the default implementation of this method matches the logic used by
DefaultExceptionMappingAuthenticationFailureHandlerbefore this method existed.- Overrides:
shouldApplyin classAuthenticationFailureExceptionMapping- Parameters:
request- the request passed toDefaultExceptionMappingAuthenticationFailureHandler.onAuthenticationFailure(HttpServletRequest, HttpServletResponse, AuthenticationException)response- the response passed toDefaultExceptionMappingAuthenticationFailureHandler.onAuthenticationFailure(HttpServletRequest, HttpServletResponse, AuthenticationException)exception- the exception passed toDefaultExceptionMappingAuthenticationFailureHandler.onAuthenticationFailure(HttpServletRequest, HttpServletResponse, AuthenticationException)- Returns:
- true if this failure mapping should apply for the given inputs, false otherwise
-
isSystemFailure
protected boolean isSystemFailure(jakarta.servlet.http.HttpServletRequest request, org.springframework.security.core.AuthenticationException exception) Reports whether the givenexceptionis due to a system failure. While this could be implemented by doing a whitelist ofOAuth2Error.getErrorCode()values thrown by flows inOidcAuthorizationCodeAuthenticationProvider, there is not a definitive set of such codes, as in some cases the error code comes directly from the third party redirect response itself (see how the authorization response is built inOAuth2LoginAuthenticationFilter). Instead, we rely primarily on the idea that thegetRequestMatcher()has already been restricted down to OAuth2 login specific paths, and thus any exception that happens at this stage is likely to be a system error. ThegetNonSystemFailureOAuth2ErrorCodes()method can be used to define a set of codes that should not be considered system failures.- Parameters:
request- the request that encountered the exceptionexception- the exception to verify as a system failure- Returns:
- true if the given exception is a system failure, false otherwise
-
getNonSystemFailureOAuth2ErrorCodes
-
getNonSystemFailureNonOAuth2ExceptionTypes
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered- Overrides:
getOrderin classAuthenticationFailureExceptionMapping- Returns:
- relative bean order for this component
-
getRequestMatcher
protected org.springframework.security.web.util.matcher.RequestMatcher getRequestMatcher()
-