From cfbd841ad04cb6d7c28f6b7d0e2add3f62f6a3f3 Mon Sep 17 00:00:00 2001 From: Rohan Sircar Date: Fri, 19 Jun 2020 18:36:43 +0530 Subject: [PATCH] Disable basic auth prompt on failed login #9 --- .../chatto/RESTAuthenticationEntryPoint.java | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/ros/chatto/RESTAuthenticationEntryPoint.java b/src/main/java/org/ros/chatto/RESTAuthenticationEntryPoint.java index bc8f41d..6267be3 100644 --- a/src/main/java/org/ros/chatto/RESTAuthenticationEntryPoint.java +++ b/src/main/java/org/ros/chatto/RESTAuthenticationEntryPoint.java @@ -12,31 +12,19 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationEn import org.springframework.stereotype.Component; @Component -public final class RESTAuthenticationEntryPoint - extends BasicAuthenticationEntryPoint { - -// @Override -// public void commence( -// HttpServletRequest request, -// HttpServletResponse response, -// AuthenticationException authException) throws IOException { -// -// response.sendError(HttpServletResponse.SC_UNAUTHORIZED, -// "Unauthorized"); -// } - - @Override - public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx) +public final class RESTAuthenticationEntryPoint extends BasicAuthenticationEntryPoint { + + @Override + public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx) throws IOException, ServletException { - response.addHeader("WWW-Authenticate", "Basic realm=" +getRealmName()); - response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); - PrintWriter writer = response.getWriter(); - writer.println("HTTP ApplicationStatus 401 - " + authEx.getMessage()); - } + response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + PrintWriter writer = response.getWriter(); + writer.println("HTTP ApplicationStatus 401 - " + authEx.getMessage()); + } - @Override - public void afterPropertiesSet() throws Exception { - setRealmName("Chatto"); - super.afterPropertiesSet(); - } + @Override + public void afterPropertiesSet() throws Exception { + setRealmName("Chatto"); + super.afterPropertiesSet(); + } }