According to spring docs , "In Spring Security 3, the user first authenticates with the AuthenticationManager, and after it is successfully completed, the session is created."
Instead, you can implement your own AuthenticationSuccessHandler (perhaps by subclassing SavedRequestAwareAuthenticationSuccessHandler ). You can put any logic in the onAuthenticationSuccess method, so move the existing logic there:
public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
Then update your configs so that Spring Security calls this class during the authentication process. Here's how:
Step 1: Configure the UsernamePasswordAuthenticationFilter that is created by the <form-login> element. In particular, put this in your <http> element:
<sec:custom-filter position="FORM_LOGIN_FILTER" ref="myFilter" />
Step 2: Define myFilter and hook MyAuthenticationSuccessHandler .
<bean id="myFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"> <property name="authenticationManager" ref="authenticationManager" /> <property name="authenticationFailureHandler" ref="myAuthenticationSuccessHandler" /> <property name="authenticationSuccessHandler" ref="myAuthenticationFailureHandler" /> </bean> <bean id="myAuthenticationSuccessHandler" class="my.MyAuthenticationSuccessHandler"> </bean> <bean id="myAuthenticationFailureHandler" class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler"> </bean>
See http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ns-config.html for more details. Also see AbstractAuthenticationProcessingFilter .
By the way, your problem reminds me of OAuth. In fact, you issue an access token to the client as a result of authorization of the resource owner.
jtoberon
source share