在使用CAS进行单点登录的过程中,由于网络及浏览器等情况而导致登录超时失败。以下几处代码可以设置CAS的一些操作时间。
1.配置文件ticketExpirationPolicies.xml
修改以下俩个参数的大小来控制登录的时间。
<!-- TicketGrantingTicketExpirationPolicy: Default as of 3.5 -->
<!-- Provides both idle and hard timeouts, for instance 2 hour sliding window with an 8 hour max lifetime -->
<bean id="grantingTicketExpirationPolicy" class="org.jasig.cas.ticket.support.TicketGrantingTicketExpirationPolicy"
p:maxTimeToLiveInSeconds="${tgt.maxTimeToLiveInSeconds:28800}"
p:timeToKillInSeconds="${tgt.timeToKillInSeconds:7200}"/>
2.监听文件TerminateWebSessionListener及相关配置
在cas-servlet.xml配置中配置监听,然后修改timeToDieInSeconds参数以控制登录时间。
<webflow:listener ref="terminateWebSessionListener" />
<bean id="terminateWebSessionListener" class="org.jasig.cas.web.flow.TerminateWebSessionListener"
p:serviceManagerUrl="${cas.securityContext.serviceProperties.service}" />
@Min(0)
private int timeToDieInSeconds = 20;
@Override
public void sessionEnded(final RequestContext context, final FlowSession session, final String outcome,
final AttributeMap output) {
final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
// get session but don't create it if it doesn't already exist
final HttpSession webSession = request.getSession(false);
if (webSession != null && webSession.getAttribute(DO_NOT_TERMINATE) == null) {
logger.debug("Terminate web session {} in {} seconds", webSession.getId(), this.timeToDieInSeconds);
// set the web session to die in timeToDieInSeconds
webSession.setMaxInactiveInterval(this.timeToDieInSeconds);
}
}