CAS增加免登陆(Remember Me)功能
1. 打开deployerConfigContext.xml
在 authenticationManager 的bean中增加
<property name="authenticationMetaDataPopulators"> <list> <bean class="org.jasig.cas.authentication.principal.RememberMeAuthenticationMetaDataPopulator" /> </list> </property>
2. login-webflow.xml
在该文件定位viewLoginForm,可以找到:
<view-state id="viewLoginForm" view="casLoginView" model="credentials"> <binder> <binding property="username" /> <binding property="password" />
<binding property="rememberMe" /> </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" /> </bean> </property> <property name="rememberMeExpirationPolicy"> <bean class="org.jasig.cas.ticket.support.TimeoutExpirationPolicy"> <constructor-arg index="0" value="7200000" /> </bean> </property> </bean>
其中的7200000为毫秒数。
4. ticketGrantingTicketCookieGenerator.xml
在ticketGrantingTicketCookieGenerator的bean中增加 p:rememberMeMaxAge="7200000" ,要注意的是这里的7200000为秒数。并且要注意和上面 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>
到此,配置完成。
另外,附上官网的添加免登陆的网页地址:
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· 对象命名为何需要避免'-er'和'-or'后缀
· JDK 24 发布,新特性解读!
· .NET Core奇技淫巧之WinForm使用Python.NET并打包
· Java24你发任你发,我用Java8
· .NET 10 Preview 2 增强了 Blazor 和.NET MAUI