Spring Security2中设置Cookie的保存时间

今天改了下Ss3ex中Spring Security2的COOKIE的保存时间设置,取消了原来的两周默认值,改为用户自定义期限,粘贴相关代码如下:
<http auto-config="true" access-denied-page="/common/403.htm">
		<intercept-url pattern="/login.**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
		<form-login login-page="/login.jsp" default-target-url="/demo/success.action" authentication-failure-url="/login.jsp?error=1" />
		<logout logout-success-url="/login.jsp" invalidate-session="true"/>
		<remember-me key="e37f4b31-0c45-11dd-bd0b-0800200c9a66" services-ref="rememberMeServices"/>
		<concurrent-session-control max-sessions="1" exception-if-maximum-exceeded="false" expired-url="/login.jsp?error=3"/>
	</http>
	
	<!-- cookie认证过滤器 -->
	<beans:bean id="rememberMeProcessingFilter"
		class="org.springframework.security.ui.rememberme.RememberMeProcessingFilter">
		<beans:property name="authenticationManager"
			ref="authenticationManager">
		</beans:property>
		<beans:property name="rememberMeServices"
			ref="rememberMeServices">
		</beans:property>
	</beans:bean>
	<beans:bean id="rememberMeServices"
		class="org.springframework.security.ui.rememberme.TokenBasedRememberMeServices">
		<beans:property name="userDetailsService" ref="userDetailsService"></beans:property>
		<!-- cookie中的键值, 防止保存到客户端的cookie中的加密串被恶意篡改 -->
		<beans:property name="key" value="e37f4b31-0c45-11dd-bd0b-0800200c9a66"></beans:property>
		<!-- cookie有效时间, 单位为秒, 这里设定为5天内不用再登陆 -->
		<beans:property name="tokenValiditySeconds" value="432000"></beans:property>
	</beans:bean>

也许还有更好的实现,下面附上源代码,SVN中已经更新了。

你可能感兴趣的:(spring,xml,SVN)