Spring Security redirect to previous page after successful login

前端 未结 9 1185
孤独总比滥情好
孤独总比滥情好 2020-11-27 10:09

I know this question has been asked before, however I\'m facing a particular issue here.

I use spring security 3.1.3.

I have 3 possible login cases in my web

9条回答
  •  旧时难觅i
    2020-11-27 10:51

    What happens after login (to which url the user is redirected) is handled by the AuthenticationSuccessHandler.

    This interface (a concrete class implementing it is SavedRequestAwareAuthenticationSuccessHandler) is invoked by the AbstractAuthenticationProcessingFilter or one of its subclasses like (UsernamePasswordAuthenticationFilter) in the method successfulAuthentication.

    So in order to have an other redirect in case 3 you have to subclass SavedRequestAwareAuthenticationSuccessHandler and make it to do what you want.


    Sometimes (depending on your exact usecase) it is enough to enable the useReferer flag of AbstractAuthenticationTargetUrlRequestHandler which is invoked by SimpleUrlAuthenticationSuccessHandler (super class of SavedRequestAwareAuthenticationSuccessHandler).

    
        
        
        
            
                
            
        
        
            
                
            
        
    
    

提交回复
热议问题