简体   繁体   中英

After login redirect to specific URL using spring security

I have a case in developing a project. I have some courses link in footer of my application and whenever a user click on the same we will show him the login or sign up pop up(if he is not logged in) or redirect to the course page (If he is logged in). So now what i want that whenever a user click on course before login he/she should be redirected to the course detail page just after login.

I am using spring security for authentication. Let me know how can i achieve this using spring security authentication?

this is the trivial use case.

the links that you have in the footer should be to a "secured zone" (for example ".../secured/page1", ".../secured/page2"). you configure in your security-beans.xml what is this "secured zone".

when user clicks and tries to get to a secured resource, spring checks whether the user has authenticated. if not, it redirects him to the login page. (in the login page you can add link to "create account").

this is how you configure the "secured zone":

<sec:http authentication-manager-ref="authenticationManager">
   <sec:intercept-url pattern="/secured/**" access="ROLE_USER" />
   ...

Spring saves the "redirect url", and if user is not logged in he is redirected to the login page, and after login spring uses the "redirect uri" and sends him to the 'secured resource' which is the course page in your case. In detail: after login, class SavedRequestAwareAuthenticationSuccessHandler uses RequestCache that holds the original request URI.

If you need popup, see this: Spring security opening a popup login

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