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中,会引起用户名密码输入错误的情况下,重返回登陆页面时,用户名是不能回显的,这点需要注意。
另外,附上官网的添加免登陆的网页地址:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值