Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring security : Redirect to previous url after logout

I've got a web app that uses spring security. I'm wanting to redirect the user back to the same page they were on before log out when they log out.

Is there an easy way to do this?

like image 233
Programming Guy Avatar asked May 25 '11 06:05

Programming Guy


People also ask

How do I redirect after logout?

To redirect the user after they log out from a specific application, you must add the URL used in the returnTo parameter of the redirect URL to the Allowed Logout URLs list in the Settings tab of your Auth0 application that is associated with the CLIENT_ID parameter.

How do I redirect a requested URL after login?

The most common ways to implement redirection logic after login are: using HTTP Referer header. saving the original request in the session. appending original URL to the redirected login URL.

How do I redirect a spring boot to another URL?

We can use a name such as a redirect: http://localhost:8080/spring-redirect-and-forward/redirectedUrl if we need to redirect to an absolute URL.

How do I get the previous URL in spring boot?

String url=""+PortalUtil.. getCurrentURL(request) takes only current URL .


1 Answers

Not sure which Spring version this question was referring to - but there is a useReferer property on the standard org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler since Spring 3.0.

So all you need to do is configure it like this and the logout will redirect to wherever the user came from:

<bean id="logoutSuccessHandler" class="org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler">
    <property name="useReferer" value="true"/>
</bean>

<security:http>
    <security:logout logout-url="/logout" success-handler-ref="logoutSuccessHandler" />
</security:http>
like image 182
meyertee Avatar answered Sep 29 '22 00:09

meyertee