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

JavaSpring.libraries.spring-boot.CustomAuthenticationFailureHandler Maven / Gradle / Ivy

There is a newer version: 0.9.25
Show newest version
package io.swagger.configuration;

import java.io.IOException;
import java.util.Calendar;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

public class CustomAuthenticationFailureHandler
		implements AuthenticationFailureHandler {

	@Override
	public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
		httpServletResponse.setStatus(HttpStatus.UNAUTHORIZED.value());

		String jsonPayload = "{\"message\" : \"%s\", \"timestamp\" : \"%s\" }";
		httpServletResponse.getOutputStream()
				.println(String.format(jsonPayload, e.getMessage(), Calendar
						.getInstance().getTime()));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy