title: UsernamePasswordAuthenticationFilter Problem
body: <p>I have a Spring Security 3 application that I login and logout works well. I wanted to implenment my own UsernamePasswordAuthenticationFilter for my application. I followed that tutorial:</p>
  
  <p><a href="http://mrather.blogspot.com/2010/02/extending-usernamepasswordauthenticatio.html" rel="nofollow">http://mrather.blogspot.com/2010/02/extending-usernamepasswordauthenticatio.html</a></p>
  
  <p>My Filter class is:</p>
  
  <pre><code>package security;
  
  import org.springframework.security.core.Authentication;
  import org.springframework.security.core.AuthenticationException;
  import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.io.IOException;
  
  public class CustomUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
      @Override
      protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) throws IOException, ServletException {
          super.successfulAuthentication(request, response, authResult);
          System.out.println("==successful login==");
      }
  
      @Override
      protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException, ServletException {
          super.unsuccessfulAuthentication(request, response, failed);
          System.out.println("==failed login==");
      }
  }
  </code></pre>
  
  <p>My security xml configuration file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/security"
               xmlns:beans="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.springframework.org/schema/beans
                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                      http://www.springframework.org/schema/security
                      http://www.springframework.org/schema/security/spring-security-3.0.xsd"&gt;
  
      &lt;global-method-security/&gt;
  
      &lt;http entry-point-ref="loginUrlAuthenticationEntryPoint"/&gt;
      &lt;beans:bean id="loginUrlAuthenticationEntryPoint"
                  class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"&gt;
          &lt;beans:property name="loginFormUrl" value="/login.html"/&gt;
      &lt;/beans:bean&gt;
      &lt;beans:bean id="customUsernamePasswordAuthenticationFilter"
                  class="security.CustomUsernamePasswordAuthenticationFilter"&gt;
          &lt;beans:property name="authenticationManager" ref="authenticationManager"/&gt;
          &lt;beans:property name="authenticationFailureHandler" ref="failureHandler"/&gt;
          &lt;beans:property name="authenticationSuccessHandler" ref="successHandler"/&gt;
      &lt;/beans:bean&gt;
      &lt;beans:bean id="successHandler"
                  class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"&gt;
          &lt;beans:property name="defaultTargetUrl" value="/login.html"/&gt;
      &lt;/beans:bean&gt;
      &lt;beans:bean id="failureHandler"
                  class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"&gt;
          &lt;beans:property name="defaultFailureUrl" value="/login.html?login_error=true"/&gt;
      &lt;/beans:bean&gt;
      &lt;http auto-config="false" disable-url-rewriting="true"&gt;
          &lt;custom-filter position="FORM_LOGIN_FILTER" ref="customUsernamePasswordAuthenticationFilter"/&gt;
          &lt;intercept-url pattern="/login.html" filters="none"/&gt;
          &lt;intercept-url pattern="/css/*" filters="none"/&gt;
          &lt;intercept-url pattern="/**" access="ROLE_USER"/&gt;
      &lt;/http&gt;
      &lt;authentication-manager alias="authenticationManager"&gt;
          &lt;authentication-provider&gt;
              &lt;password-encoder hash="sha-256"/&gt;
              &lt;user-service&gt;
                  &lt;user name="sdf" password="6b86d273ff34fce19d6dddf5747ada4eaa22f1d49c01e52ddb7875b4b"
                        authorities="ROLE_USER"/&gt;
              &lt;/user-service&gt;
          &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>However when I run my application it doesn't redirect to login page, it goes to index page by default and gives</p>
  
  <pre><code>404 Not found error
  </code></pre>
  
  <p>for all my web pages. Any ideas? Did I configure my application well?</p>
  
  <p><strong>PS:</strong> That writes at tutorial:</p>
  
  <blockquote>
    <p>Note: Since we are replacing the default FORM_LOGIN_FILTER, we should
    not use 
  </blockquote>
  
  <p>so I removed that:</p>
  
  <pre><code>    &lt;form-login
              login-page="/login3.html"
              login-processing-url="/j_spring_security_check"
              default-target-url="/index.html"
              always-use-default-target="true"/&gt;
      &lt;logout logout-url="/j_spring_security_logout"
              logout-success-url="/login.html"/&gt;
  </code></pre>
  
  <p>from my XML file.</p>
  
  <p>Also is there need to define successHandler and failureHandler because I didn't overwrite them. If I do it because I am replacing the filter(or because of -<code>http auto-config="false"</code></p>
  
  <p>I don't know the real purpose of that line, if you explain you are welcome) should I define anything else for security? </p>
  
  <p>I am new to Spring Security 3 and Spring.</p>