Class SimpleUrlAuthenticationFailureHandler
- java.lang.Object
-
- org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler
-
- All Implemented Interfaces:
AuthenticationFailureHandler
- Direct Known Subclasses:
ExceptionMappingAuthenticationFailureHandler
public class SimpleUrlAuthenticationFailureHandler extends java.lang.Object implements AuthenticationFailureHandler
AuthenticationFailureHandler which performs a redirect to the value of thedefaultFailureUrlproperty when the onAuthenticationFailure method is called. If the property has not been set it will send a 401 response to the client, with the error message from the AuthenticationException which caused the failure.If the
useForwardproperty is set, aRequestDispatcher.forwardcall will be made to the destination instead of a redirect.- Since:
- 3.0
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.logging.Loglogger
-
Constructor Summary
Constructors Constructor Description SimpleUrlAuthenticationFailureHandler()SimpleUrlAuthenticationFailureHandler(java.lang.String defaultFailureUrl)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected RedirectStrategygetRedirectStrategy()protected booleanisAllowSessionCreation()protected booleanisUseForward()voidonAuthenticationFailure(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AuthenticationException exception)Performs the redirect or forward to thedefaultFailureUrlif set, otherwise returns a 401 error code.protected voidsaveException(javax.servlet.http.HttpServletRequest request, AuthenticationException exception)Caches theAuthenticationExceptionfor use in view rendering.voidsetAllowSessionCreation(boolean allowSessionCreation)voidsetDefaultFailureUrl(java.lang.String defaultFailureUrl)The URL which will be used as the failure destination.voidsetRedirectStrategy(RedirectStrategy redirectStrategy)Allows overriding of the behaviour when redirecting to a target URL.voidsetUseForward(boolean forwardToDestination)If set to true, performs a forward to the failure destination URL instead of a redirect.
-
-
-
Method Detail
-
onAuthenticationFailure
public void onAuthenticationFailure(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AuthenticationException exception) throws java.io.IOException, javax.servlet.ServletExceptionPerforms the redirect or forward to thedefaultFailureUrlif set, otherwise returns a 401 error code.If redirecting or forwarding,
saveExceptionwill be called to cache the exception for use in the target view.- Specified by:
onAuthenticationFailurein interfaceAuthenticationFailureHandler- Parameters:
request- the request during which the authentication attempt occurred.response- the response.exception- the exception which was thrown to reject the authentication request.- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
saveException
protected final void saveException(javax.servlet.http.HttpServletRequest request, AuthenticationException exception)Caches theAuthenticationExceptionfor use in view rendering.If
forwardToDestinationis set to true, request scope will be used, otherwise it will attempt to store the exception in the session. If there is no session andallowSessionCreationistruea session will be created. Otherwise the exception will not be stored.
-
setDefaultFailureUrl
public void setDefaultFailureUrl(java.lang.String defaultFailureUrl)
The URL which will be used as the failure destination.- Parameters:
defaultFailureUrl- the failure URL, for example "/loginFailed.jsp".
-
isUseForward
protected boolean isUseForward()
-
setUseForward
public void setUseForward(boolean forwardToDestination)
If set to true, performs a forward to the failure destination URL instead of a redirect. Defaults to false.
-
setRedirectStrategy
public void setRedirectStrategy(RedirectStrategy redirectStrategy)
Allows overriding of the behaviour when redirecting to a target URL.
-
getRedirectStrategy
protected RedirectStrategy getRedirectStrategy()
-
isAllowSessionCreation
protected boolean isAllowSessionCreation()
-
setAllowSessionCreation
public void setAllowSessionCreation(boolean allowSessionCreation)
-
-