All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.payneteasy.superfly.security.x509.X509EFailureHandler Maven / Gradle / Ivy

Go to download

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();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy