Skip to content

Instantly share code, notes, and snippets.

@Cameron-C-Chapman
Last active February 22, 2016 18:33
Show Gist options
  • Save Cameron-C-Chapman/73dfdb7917a0ffc697fe to your computer and use it in GitHub Desktop.
Save Cameron-C-Chapman/73dfdb7917a0ffc697fe to your computer and use it in GitHub Desktop.
Spring Security custom AuthenticationFailureHandler
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