Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly,</p> <p><code>403 Forbidden</code> should be used when user is already authenticated but is not authorized to perform particular action. In your example <code>guest</code> is successfully authenticated but is not granted permission to see page because he is just a guest.</p> <p>You should use <code>401 Unauthorized</code> to indicate that your user was not authenticated successfully.</p> <p>More on HTTP errors codes: <a href="http://en.wikipedia.org/wiki/HTTP_401#4xx_Client_Error" rel="noreferrer">http://en.wikipedia.org/wiki/HTTP_401#4xx_Client_Error</a></p> <p>Secondly,</p> <p>you can specify your custom behavior by extending <code>BasicAuthenticationFilter</code>. There is <code>protected void onUnsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse AuthenticationException failed)</code> method that you can override and do whatever is adequate. In default implementation that method is empty.</p> <p>Spring Security docs on injecting custom filter: <a href="http://static.springsource.org/spring-security/site/docs/3.1.x/reference/appendix-namespace.html#nsa-custom-filter" rel="noreferrer">CLICK</a></p> <p>Edit:</p> <p>What Spring Security does each time your authentication input is invalid:</p> <pre><code>public class BasicAuthenticationEntryPoint implements AuthenticationEntryPoint { ... public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { response.addHeader("WWW-Authenticate", "Basic realm=\"" + realmName + "\""); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage()); </code></pre> <p>So, the default behavior is correct. User is sent 401 and is asked to provide valid login/credentials.</p> <p>Before overriding, try to understand the default behavior. Source code: <a href="https://github.com/SpringSource/spring-security/blob/master/web/src/main/java/org/springframework/security/web/authentication/www/BasicAuthenticationFilter.java" rel="noreferrer">CLICK</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload