Created
December 6, 2012 10:25
Custom Authentication Failure URL Handler, Accepting No Slash URLs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NoSlashAuthenticationFailureHandler implements AuthenticationFailureHandler { | |
protected final Log logger = LogFactory.getLog(getClass()); | |
private String defaultFailureUrl; | |
public NoSlashAuthenticationFailureHandler() { | |
} | |
public NoSlashAuthenticationFailureHandler(String defaultFailureUrl) { | |
setDefaultFailureUrl(defaultFailureUrl); | |
} | |
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, | |
AuthenticationException exception) throws IOException, ServletException { | |
if (defaultFailureUrl == null) { | |
logger.debug("No failure URL set, sending 401 Unauthorized error"); | |
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication Failed: " + exception.getMessage()); | |
} else { | |
logger.debug("Redirecting to " + defaultFailureUrl); | |
response.sendRedirect(defaultFailureUrl); | |
} | |
} | |
/** | |
* The URL which will be used as the failure destination. | |
* @param defaultFailureUrl the failure URL, for example "loginFailed.jsp". | |
*/ | |
public void setDefaultFailureUrl(String defaultFailureUrl) { | |
this.defaultFailureUrl = defaultFailureUrl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment