title: Spring security Pre authentication success handler
body: <p>I have a web app where you can login with form-login or you can be pre-authenticated and be logged in like that. Both method work well but I only can find way to use a success handler with the form-login using the authentication-success-handler-ref property. </p>
  
  <p>My question is, how can I call the success handler "mySuccessHandler" for the PRE_AUTH_FILTER in my security-app-context? I would guess I can call it as a property or something under the PreAuthenticatedProcessingFilter, preauthAuthProvider or the custom-filter.</p>
  
  <p>Just need to go to different pages if the user has the role Teacher or Student.</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.2.xsd"&gt;
  
  
  &lt;http pattern="/**" use-expressions="true" create-session="always"&gt;
      &lt;intercept-url pattern="/login.jsp*" access="permitAll" /&gt;
      &lt;intercept-url pattern="/**/ErrorPages/**" access="permitAll" /&gt;
      &lt;intercept-url pattern="/**/Students/**" access="hasAnyRole('STUDENT, TEACHER')" /&gt;
      &lt;intercept-url pattern="/**/Teacher/**" access="hasRole('TEACHER')" /&gt;
      &lt;intercept-url pattern="/**/Login/**" access="hasRole('ROLE_USER')" /&gt;
      &lt;intercept-url pattern="/**/Js/**" access="hasRole('ROLE_USER')" /&gt;
      &lt;intercept-url pattern="/**/Css/**" access="permitAll" /&gt;
      &lt;intercept-url pattern="/**/Img/**" access="permitAll" /&gt;
      &lt;intercept-url pattern="/**/api/**" access="hasRole('ROLE_USER')" /&gt;
      &lt;intercept-url pattern="/**" access="denyAll" /&gt;
      &lt;custom-filter position="PRE_AUTH_FILTER" ref="PreAuthenticatedProcessingFilter" /&gt;
      &lt;access-denied-handler
      &lt;form-login
              username-parameter="idnumber"
              password-parameter="password" login-processing-url="/athuga_innskraningu"
              login-page='/login.jsp'
              authentication-failure-handler-ref="myAuthErrorHandler"
              authentication-success-handler-ref="mySuccessHandler"
              always-use-default-target='true'
              authentication-failure-url="/login.jsp?login_error=true"/&gt;
      &lt;logout logout-url="/utskra/" logout-success-url="/login.jsp"/&gt;
  &lt;/http&gt;
  
  
  &lt;beans:bean id="mySuccessHandler" class="is.inna.rest.login.AuthenticationSuccess"/&gt;
  &lt;beans:bean id="myAuthErrorHandler" class="is.inna.rest.login.AuthenticationFailure"/&gt;
  &lt;beans:bean id="passwordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/&gt;
  
  &lt;beans:bean name="myUserDetailsService" class="is.inna.rest.login.UserDetailServiceLogin" /&gt;
  &lt;beans:bean id="userDetailsServiceWrapper"  class="is.inna.rest.login.UserDetailServicePreAuth" /&gt;
  
  &lt;authentication-manager alias="authenticationManager"&gt;
      &lt;authentication-provider user-service-ref="myUserDetailsService"&gt;
          &lt;password-encoder ref="passwordEncoder" /&gt;
      &lt;/authentication-provider&gt;
      &lt;authentication-provider ref="preauthAuthProvider" /&gt;
  &lt;/authentication-manager&gt;
  
  
  &lt;beans:bean id="preauthAuthProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider"&gt;
      &lt;beans:property name="preAuthenticatedUserDetailsService" ref="userDetailsServiceWrapper"/&gt;
  &lt;/beans:bean&gt;
  &lt;beans:bean id="PreAuthenticatedProcessingFilter" class="is.inna.rest.login.PreAuthenticatedProcessingFilter"&gt;
      &lt;beans:property name="authenticationManager" ref="authenticationManager" /&gt;
  &lt;/beans:bean&gt;
  </code></pre>
  
  <p></p>