Last active
February 22, 2016 18:33
-
-
Save Cameron-C-Chapman/73dfdb7917a0ffc697fe to your computer and use it in GitHub Desktop.
Spring Security custom AuthenticationFailureHandler
This file contains hidden or 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
package package.name; | |
import java.io.IOException; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.security.core.AuthenticationException; | |
import org.springframework.security.web.DefaultRedirectStrategy; | |
import org.springframework.security.web.RedirectStrategy; | |
import org.springframework.security.web.authentication.AuthenticationFailureHandler; | |
public class AuthenticationFailureHandlerImpl implements AuthenticationFailureHandler { | |
@Value("${badCredentialsUrl}") | |
private String badCredentialsUrl; | |
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); | |
@Override | |
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { | |
redirectStrategy.sendRedirect(request, response, badCredentialsUrl); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment