How to change default destination URL based on user role

I use spring for user authentication. In security.xml, I have

<form-login login-page="/login" 
                default-target-url="/dashboard" 
                always-use-default-target="false"  
                authentication-failure-url="/login/error" 
                login-processing-url="/j_security_check"/>

I want to be able to configure different destination URLs for different user roles. How should I do it?

Thank!

+5
source share
3 answers

If you use Spring-Security 3.0 or higher, implementing your own AuthenticationSuccessHandler, this is the way:

<sec:form-login ... authentication-success-handler-ref="successHandler"/>
...
<bean id="successHandler" class="de.....MySpecialAuthenticationSuccessHandler">

Then it MySpecialAuthenticationSuccessHandlercan distribute one of the default handlers, for example SavedRequestAwareAuthenticationSuccessHandler, although they are not very convenient for inheritance.

+7
source

, , default-target-url may contain logic to redirect to the appropriate page based on the role.

0
source

All Articles