CAS增加免登陆(Remember Me)功能

CAS可以通过配置,实现免登陆功能,在版本3.4.10 , 3.4.11中,具体需要在如下几个文件进行修改配置。

1)deployerConfigContext.xml
 AuthenticationManager 的bean中增加

<property name="authenticationMetaDataPopulators"> <list> <bean class="org.jasig.cas.authentication.principal.RememberMeAuthenticationMetaDataPopulator" /> </list> </property>

2) login-webflow.xml

"credentials" var,:

< var name = "credentials" class = "org.jasig.cas.authentication.principal.UsernamePasswordCredentials" />

改成:

< var name = "credentials" class = "org.jasig.cas.authentication.principal.RememberMeUsernamePasswordCredentials" />

在该文件定位 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="XXXXXXXX" /> </bean> </property> <property name="rememberMeExpirationPolicy"> <bean class="org.jasig.cas.ticket.support.TimeoutExpirationPolicy"> <constructor-arg index="0" value="XXXXXXXX" /> </bean> </property> </bean>
其中的 XXXXXXXX为毫秒数。

4) ticketGrantingTicketCookieGenerator.xml
在ticketGrantingTicketCookieGenerator的bean中增加  p:rememberMeMaxAge="xxxxxxx" ,要注意的是这里的 xxxxxxx为秒数。并且要注意和ticketExpirationPolicies.xml中设置的保持一致。

5)casLoginView.jsp
在该登陆页面增加

<input type="checkbox" name="rememberMe" id="rememberMe" value="true" /> <label for="rememberMe">Remember Me</label>


到此,配置完成。

需要注意的是,在CAS之前的版本中, login-webflow.xml中的 viewLoginForm是如下样子的:

<view-state id="viewLoginForm" view="casLoginView" model="credentials"> <var name="credentials" class="org.jasig.cas.authentication.principal.UsernamePasswordCredentials" /> <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"> <set name="flowScope.credentials" value="credentials" /> <evaluate expression="authenticationViaFormAction.doBind(flowRequestContext, flowScope.credentials)" /> </transition> </view-state>
如果使用上面的代码并增加 <binding property="rememberMe" />,在 版本3.4.10 , 3.4.11中,会引起用户名密码输入错误的情况下,重返回登陆页面时,用户名是不能回显的,这点需要注意。
另外,附上官网的添加免登陆的网页地址:
https://wiki.jasig.org/display/CASUM/Remember+Me

你可能感兴趣的:(CAS增加免登陆(Remember Me)功能)