title: Adding custom filter in spring security
body: <p>I am trying to make a custom AuthenticationProcessingFilter to save some user data in the session after successful login</p>
  
  <p>here's my filter:</p>
  
  <pre><code>package projects.internal;
  
  import java.io.IOException;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.springframework.security.Authentication;
  import org.springframework.security.ui.webapp.AuthenticationProcessingFilter;
  
  public class MyAuthenticationProcessingFilter extends AuthenticationProcessingFilter {
  
  
   protected void onSuccessfulAuthentication(HttpServletRequest request,
     HttpServletResponse response, Authentication authResult)
     throws IOException {
    super.onSuccessfulAuthentication(request, response, authResult);
    request.getSession().setAttribute("myValue", "My value is set");
   }
  }
  </code></pre>
  
  <p>and here's my security.xml file</p>
  
  <pre><code>&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 pre-post-annotations="enabled"&gt;
  
   &lt;/global-method-security&gt;
   &lt;http use-expressions="true" auto-config="false" entry-point-ref="authenticationProcessingFilterEntryPoint"&gt;
    &lt;intercept-url pattern="/" access="permitAll" /&gt;
    &lt;intercept-url pattern="/images/**" filters="none" /&gt;
    &lt;intercept-url pattern="/scripts/**" filters="none" /&gt;
    &lt;intercept-url pattern="/styles/**" filters="none" /&gt;
    &lt;intercept-url pattern="/p/login.jsp" filters="none" /&gt;
    &lt;intercept-url pattern="/p/register" filters="none" /&gt;
    &lt;intercept-url pattern="/p/**" access="isAuthenticated()" /&gt;
  
       &lt;form-login
     login-processing-url="/j_spring_security_check"
     login-page="/p/login.jsp"   
     authentication-failure-url="/p/login_error.jsp" /&gt;
    &lt;logout /&gt;
   &lt;/http&gt;
  
   &lt;authentication-manager alias="authenticationManager"&gt;
   &lt;authentication-provider&gt;
      &lt;jdbc-user-service data-source-ref="dataSource"/&gt;
    &lt;/authentication-provider&gt;
   &lt;/authentication-manager&gt;
  
   &lt;beans:bean id="authenticationProcessingFilter" class="projects.internal.MyAuthenticationProcessingFilter"&gt;
   &lt;custom-filter position="AUTHENTICATION_PROCESSING_FILTER" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="authenticationProcessingFilterEntryPoint" class="org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint"&gt;
      &lt;/beans:bean&gt;
  
  
   &lt;/beans:beans&gt;
  </code></pre>
  
  <p>it gives an error here:</p>
  
  <pre><code>&lt;custom-filter position="AUTHENTICATION_PROCESSING_FILTER" /&gt;
  </code></pre>
  
  <blockquote>
    <p>multiple annotation found at this line:cvc-attribute.3
    cvc-complex-type.4
    cvc-enumeration-vaild</p>
  </blockquote>
  
  <p>what is the problem?</p>