简体   繁体   中英

How to redirect to particular page when provided login credentials

While using spring security I am providing a particular page with ROLE_ANONYMOUS user.

<intercept-url pattern="/runApp*"
        access="hasAnyRole('User', 'Admin','ROLE_ANONYMOUS')" />

There are many other intercept urls in the same http tag of spring security. This is my spring security code:

<http auto-config="true" use-expressions="true">
<intercept-url pattern='/welcome*' access="hasAnyRole('User', 'Admin')" />
<intercept-url pattern="/runApp*" access="hasAnyRole('User', 'Admin','ROLE_ANONYMOUS')" />
<form-login login-page="/login" authentication-failure-url="/login.jsp?login_error=true" default-target-url="/welcome" />
<logout logout-success-url="/login" invalidate-session="true" />

When user logins for the first time it redirects to welcome page. But when he wants to access runApp page he has to provide his credentials in the login page. But when he provides login credential it redirects to welcome page. Whereas I want it to redirect to particular runApp page.

Thanks.

There is another attribute in form-login element named always-use-default-target which defines redirect rule after login. If value of this attribute set to false , then user will be redirected to default-target-url only after requesting login page directly.

I came to a workaround. Not the best solution, but, if someone has something better to show, I'm all ears. When redirecting to login page for the credentials i am saving the data in the session. And when the registered user logins it goes to the controller where i get the data from the session and redirect it to the desired page. Thanks for your support... :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM