1)
deployerConfigContext.xml
在 AuthenticationManager 的bean中增加
<property name="authenticationMetaDataPopulators">
<list>
<bean class="org.jasig.cas.authentication.principal.RememberMeAuthenticationMetaDataPopulator"></bean>
</list>
</property>
在该文件定位 viewLoginForm ,可以找到:
<view-state id="viewLoginForm" view="casLoginView" model="credentials">
<binder>
<binding property="username" />
<binding property="password" />
</binder>
<on-entry>
<set name="viewScope.commandName" value="'credentials'" />
</on-entry>
<transition on="submit" bind="true" validate="true" to="realSubmit">
<evaluate expression="authenticationViaFormAction.doBind(flowRequestContext, flowScope.credentials)" />
</transition>
</view-state>
的binder中增加:
<binding property="rememberMe" />
3)
ticketExpirationPolicies.xml
将 grantingTicketExpirationPolicy的bean替换为:
<bean id="grantingTicketExpirationPolicy" class="org.jasig.cas.ticket.support.RememberMeDelegatingExpirationPolicy">
<property name="sessionExpirationPolicy">
<bean class="org.jasig.cas.ticket.support.TimeoutExpirationPolicy">
<constructor-arg index="0" value="7200000"></constructor-arg>
</bean>
</property>
<property name="rememberMeExpirationPolicy">
<bean class="org.jasig.cas.ticket.support.TimeoutExpirationPolicy">
<constructor-arg index="0" value="7200000"></constructor-arg>
</bean>
</property>
</bean>
其中的 7200000为毫秒数。
4)
ticketGrantingTicketCookieGenerator.xml
在ticketGrantingTicketCookieGenerator的bean中增加
p:rememberMeMaxAge="xxxxxxx" ,要注意的是这里的
xxxxxxx为秒数。并且要注意和ticketExpirationPolicies.xml中设置的保持一致。
5)casLoginView.jsp
在该登陆页面增加 :
<div class="row check">
<input id="rememberMe" name="rememberMe" value="true" tabindex="4" type="checkbox" />
<label for="rememberMe">remeberMe</label>
</div>
到此,配置完成。
感谢原作者,我还有一些需要补充:
login-webflow.xml里的credentials修改为:
<var name="credentials" class="org.jasig.cas.authentication.principal.RememberMeUsernamePasswordCredentials" />
还有需要注意的是ticketExpirationPolicies.xml里设置tgt过期策略时用的是毫秒,而ticketGrantingTicketCookieGenerator.xml里remeberMeMaxAge用的是秒。