Disable basic auth prompt on failed login #9

This commit is contained in:
Rohan Sircar 2020-06-19 18:36:43 +05:30
parent dda589c2e8
commit cfbd841ad0

View File

@ -12,31 +12,19 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationEn
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public final class RESTAuthenticationEntryPoint public final class RESTAuthenticationEntryPoint extends BasicAuthenticationEntryPoint {
extends BasicAuthenticationEntryPoint {
// @Override @Override
// public void commence( public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx)
// HttpServletRequest request,
// HttpServletResponse response,
// AuthenticationException authException) throws IOException {
//
// response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
// "Unauthorized");
// }
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx)
throws IOException, ServletException { throws IOException, ServletException {
response.addHeader("WWW-Authenticate", "Basic realm=" +getRealmName()); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); PrintWriter writer = response.getWriter();
PrintWriter writer = response.getWriter(); writer.println("HTTP ApplicationStatus 401 - " + authEx.getMessage());
writer.println("HTTP ApplicationStatus 401 - " + authEx.getMessage()); }
}
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
setRealmName("Chatto"); setRealmName("Chatto");
super.afterPropertiesSet(); super.afterPropertiesSet();
} }
} }