mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
basic auth filter should return 403 instead of 401 for wrong credentials
This commit is contained in:
@@ -35,6 +35,7 @@ package sonia.scm.web.filter;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
@@ -52,7 +53,6 @@ import sonia.scm.config.ScmConfiguration;
|
|||||||
import sonia.scm.user.User;
|
import sonia.scm.user.User;
|
||||||
import sonia.scm.util.HttpUtil;
|
import sonia.scm.util.HttpUtil;
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
import sonia.scm.web.security.AuthenticationHandler;
|
|
||||||
import sonia.scm.web.security.WebSecurityContext;
|
import sonia.scm.web.security.WebSecurityContext;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
@@ -60,6 +60,7 @@ import sonia.scm.web.security.WebSecurityContext;
|
|||||||
import com.sun.jersey.core.util.Base64;
|
import com.sun.jersey.core.util.Base64;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.FilterChain;
|
import javax.servlet.FilterChain;
|
||||||
@@ -105,6 +106,7 @@ public class BasicAuthenticationFilter extends AutoLoginFilter
|
|||||||
* Constructs a new basic authenticaton filter
|
* Constructs a new basic authenticaton filter
|
||||||
*
|
*
|
||||||
* @param configuration scm-manager global configuration
|
* @param configuration scm-manager global configuration
|
||||||
|
* @param autoLoginModules auto login modules
|
||||||
*
|
*
|
||||||
* @since 1.21
|
* @since 1.21
|
||||||
*/
|
*/
|
||||||
@@ -146,7 +148,8 @@ public class BasicAuthenticationFilter extends AutoLoginFilter
|
|||||||
{
|
{
|
||||||
if (logger.isTraceEnabled())
|
if (logger.isTraceEnabled())
|
||||||
{
|
{
|
||||||
logger.trace("found basic authorization header, start authentication");
|
logger.trace(
|
||||||
|
"found basic authorization header, start authentication");
|
||||||
}
|
}
|
||||||
|
|
||||||
user = authenticate(request, response, subject, authentication);
|
user = authenticate(request, response, subject, authentication);
|
||||||
@@ -192,12 +195,13 @@ public class BasicAuthenticationFilter extends AutoLoginFilter
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Sends status code 401 back to client, if no authorization header was found,
|
||||||
|
* if a authorization is present and the authentication failed the method will
|
||||||
|
* send status code 403.
|
||||||
*
|
*
|
||||||
*
|
* @param request servlet request
|
||||||
* @param request
|
* @param response servlet response
|
||||||
* @param response
|
* @param chain filter chain
|
||||||
* @param chain
|
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws ServletException
|
* @throws ServletException
|
||||||
@@ -207,9 +211,18 @@ public class BasicAuthenticationFilter extends AutoLoginFilter
|
|||||||
protected void handleUnauthorized(HttpServletRequest request,
|
protected void handleUnauthorized(HttpServletRequest request,
|
||||||
HttpServletResponse response, FilterChain chain)
|
HttpServletResponse response, FilterChain chain)
|
||||||
throws IOException, ServletException
|
throws IOException, ServletException
|
||||||
|
{
|
||||||
|
String authentication = request.getHeader(HEADER_AUTHORIZATION);
|
||||||
|
|
||||||
|
if (Strings.isNullOrEmpty(authentication))
|
||||||
{
|
{
|
||||||
HttpUtil.sendUnauthorized(request, response);
|
HttpUtil.sendUnauthorized(request, response);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
|
|||||||
Reference in New Issue
Block a user