com.payneteasy.superfly.security.x509.X509EFailureHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of superfly-spring-security Show documentation
Show all versions of superfly-spring-security Show documentation
Module for Spring Security which enables application to use Superfly authentication/authorization declaratively through Spring Security
The newest version!
package com.payneteasy.superfly.security.x509;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
public class X509EFailureHandler implements AuthenticationFailureHandler {
@Override
public void onAuthenticationFailure(
HttpServletRequest request,
HttpServletResponse response,
AuthenticationException exception
) throws IOException {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
writeTextMessage(response, exception);
}
private void writeTextMessage(HttpServletResponse response, AuthenticationException exception) throws IOException {
response.setHeader("Content-Type", "text/plain");
PrintWriter writer = response.getWriter();
writer.print(exception.getMessage());
writer.close();
}
}