CAS学习之Remember Me功能(1)

CAS通过简单的配置就可以实现免登陆的功能。即当用户登录系统之后,关闭浏览器,用户可以直接进入系统无需再次验证。具体配置步骤如下:

1、在deployerConfigContext.xml中增加如下配置:

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

2、在login-webflow.xml中将以下配置:

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

改为:

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

另外,在这个文件中找到字符串【id="viewLoginForm"】,在<binder>后面增加一行:

<binding property="rememberMe" />

3、在ticketExpirationPolicies.xml中,将配置:

<bean id="grantingTicketExpirationPolicy" class="org.jasig.cas.ticket.support.TicketGrantingTicketExpirationPolicy"
          p:maxTimeToLiveInSeconds="${tgt.maxTimeToLiveInSeconds:28800}"
          p:timeToKillInSeconds="${tgt.timeToKillInSeconds:7200}"/>

改为:

<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中找到字符串【id="ticketGrantingTicketCookieGenerator"】,增加如下配置:

p:rememberMeMaxAge="7200"

这个时间单位为妙

5、在文件casLoginView.jsp中增加如下配置:

<div class="row check">
                        <input id="rememberMe" name="rememberMe" value="true" tabindex="4" type="checkbox" />
                        <label for="rememberMe">remeberMe</label>
                    </div>


你可能感兴趣的:(cas,免登陆,RememberMe)