Spring Security教程(14)---- Logout和SessionManager

Logout的配置很简单,只需要在http中加入下面的配置就可以了

<sec:logout invalidate-session="true" logout-url="/logout"
	logout-success-url="/login.jsp" />
invalidate-session是否销毁Session

logout-url logout地址

logout-success-url logout成功后要跳转的地址

Session管理中最简单的配置方法是

<sec:session-management invalid-session-url="/login.jsp" />
意思就是Session失效时跳转到login.jsp

配置同一事件,只能有一个用户登录系统。

网上有的例子是这样配置的

<sec:session-management invalid-session-url="/login.jsp" >
	<sec:concurrency-control error-if-maximum-exceeded="true"
		max-sessions="1" expired-url="/login.jsp"/>
</sec:session-management>
但是这种配置在3.2版本中不管用

在3.2版本中需要这样配置

首先在web.xml中加入一下配置

<listener>
	<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
然后修改applicationContext-security.xml

	<sec:http access-decision-manager-ref="accessDecisionManager"
		entry-point-ref="authenticationEntryPoint">
		
		<sec:access-denied-handler ref="accessDeniedHandler"/>
		
		<sec:logout invalidate-session="true" logout-url="/logout"
			logout-success-url="/login.jsp" />

		<sec:session-management session-authentication-strategy-ref="concurrentSessionControlStrategy" />
		
		<sec:remember-me 
			authentication-success-handler-ref="authenticationSuccessHandler"
			data-source-ref="dataSource"
			user-service-ref="userDetailService"
		/>
			
		
		<sec:custom-filter ref="filterSecurityInterceptor" before="FILTER_SECURITY_INTERCEPTOR"/>
		<sec:custom-filter ref="captchaAuthenticaionFilter" position="FORM_LOGIN_FILTER"/>
		<sec:custom-filter ref="concurrencyFilter" position="CONCURRENT_SESSION_FILTER"/>
	</sec:http>

	<bean id="captchaAuthenticaionFilter" class="com.zrhis.system.security.CaptchaAuthenticationFilter">
		<property name="authenticationManager" ref="authenticationManager" />
		<property name="authenticationFailureHandler" ref="authenticationFailureHandler" />
		<property name="authenticationSuccessHandler" ref="authenticationSuccessHandler" />
		<property name="filterProcessesUrl" value="/login.do" />
		<property name="sessionAuthenticationStrategy" ref="concurrentSessionControlStrategy" />
	</bean>
	
	<bean id="authenticationSuccessHandler" class="com.zrhis.system.security.SavedRequestLoginSuccessHandler">
		<property name="defaultTargetUrl" value="/index.jsp" />
		<property name="forwardToDestination" value="true" />
		<property name="alwaysUseDefaultTargetUrl" value="false" />
	</bean>
	<bean id="authenticationFailureHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
		<property name="defaultFailureUrl" value="/login.jsp" />
	</bean>
	
	<bean id="authenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
		<property name="loginFormUrl" value="/login.jsp" />
	</bean>
	
	<bean id="concurrencyFilter" class="org.springframework.security.web.session.ConcurrentSessionFilter">
		<constructor-arg name="sessionRegistry" ref="sessionRegistry" />
		<constructor-arg name="expiredUrl" value="/sessionOut.jsp" />
	</bean>
	
	<bean id="concurrentSessionControlStrategy"
		class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy">
		<constructor-arg name="sessionRegistry" ref="sessionRegistry" />
		<property name="maximumSessions" value="1"></property>
	</bean>
	
	<bean id="sessionRegistry" class="org.springframework.security.core.session.SessionRegistryImpl" />








  • 17
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大扑棱蛾子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值