We recently had to implement logout functions using Spring-security 3.0.5. Although this question has already been answered above, I will post the full code that will definitely help a novice user like me :)
Configuration in Spring -security.xml
<http auto-config="false" lowercase-comparisons="false" use-expressions="true"> <custom-filter position="LOGOUT_FILTER" ref="logoutFilter" /> </http> <beans:bean id="logoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter"> <beans:constructor-arg name="logoutSuccessHandler" ref="xxxLogoutSuccessHandler" /> <beans:constructor-arg name="handlers"> <beans:list> <beans:ref bean="securityContextLogoutHandler"/> <beans:ref bean="xxxLogoutHandler"/> </beans:list> </beans:constructor-arg> <beans:property name="filterProcessesUrl" value="/logout"/> </beans:bean> <beans:bean id="XXXLogoutSuccessHandler" class="com.tms.dis.sso.XXXLogoutSuccessHandler"/> <beans:bean id="securityContextLogoutHandler" class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"> <beans:property name="invalidateHttpSession" value="true"/> </beans:bean> <beans:bean id="XXXLogoutHandler" class="com.tms.dis.sso.XXXLogoutHandler"/>
Here I created two custom classes
- XXXLogoutHandler, which implements org.springframework.security.web.authentication.logout.LogoutHandler and overrides the logout () method.
- XXXLogoutSuccessHandler, which will implement org.springframework.security.web.authentication.logout.LogoutSuccessHanlder and override the onLoguoutSuccess () method. In the XXXLogoutSuccessHandler.onLogoutSuccess () method, call the redirectStrategy.sendRedirect () method, which will bring the user to a specific destination URL.
- org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler performs the task of canceling a user session.
I hope this helps and gives the right direction to the starter
Note Code for user implementation is not intentionally posted.
Nayan Oct 24 '13 at 13:26 2013-10-24 13:26
source share