ticket的过期策略(5.x)

tgt的过期策略:

1.hardTimeout

org.jasig.cas.ticket.support.HardTimeoutExpirationPolicy,它的配置:


	 

5.x对应Appliction配置:

cas:
	tgt:
      hardTimeout:
        timeToKillInSeconds: 7200000

在tgt创建之时起,两个小时之后则tgt过期,这个是硬性的没有商量的余地,所以类名有个hard;

2.NeverExpiresExpirationPolicy
org.jasig.cas.ticket.support.NeverExpiresExpirationPolicy,它的配置:



cas:
	tgt:
      hardTimeout:
        timeToKillInSeconds: 7200000

在tgt创建之时起,两个小时之后则tgt过期,这个是硬性的没有商量的余地,所以类名有个hard;

3.ThrottledUseAndTimeoutExpirationPolicy
org.jasig.cas.ticket.support.ThrottledUseAndTimeoutExpirationPolicy,它的配置:


	p:timeToKillInMilliSeconds="7200000"
	p:timeInBetweenUsesInMilliSeconds="5000" 

cas:
	tgt:
      throttledTimeout:
        timeToKillInSeconds: 7200000
        timeInBetweenUsesInSeconds: 5000

在tgt创建之后,上次应用距本次应用超过2小时或者小于5秒钟,只要满足其一,则tgt过期。

4.TicketGrantingTicketExpirationPolicy
org.jasig.cas.ticket.support.TicketGrantingTicketExpirationPolicy,它的配置:



cas:
	tgt:
    	maxTimeToLiveInSeconds: 28800
    	timeToKillInSeconds: 7200

当用户在2个小时(7200秒)之内不动移动鼠标或者进行系统超过8个小时(28800秒),则tgt过期;

5.TimeoutExpirationPolicy
org.jasig.cas.ticket.support.TimeoutExpirationPolicy,它的配置:


	 

cas:
	tgt:
		timeout:
	    	maxTimeToLiveInSeconds: 7200000

如果两个小时不动鼠标则tgt过期;

cas5.x根据不同的配置参数,生成不同的ExpirationPolicy类;
具体代码如下:

	@ConditionalOnMissingBean(name = "ticketGrantingTicketExpirationPolicy")
    @Bean
    public ExpirationPolicy ticketGrantingTicketExpirationPolicy() {
        final TicketGrantingTicketProperties tgt = casProperties.getTicket().getTgt();
        if (tgt.getMaxTimeToLiveInSeconds() <= 0 && tgt.getTimeToKillInSeconds() <= 0) {
            LOGGER.warn("Ticket-granting ticket expiration policy is set to NEVER expire tickets.");
            return new NeverExpiresExpirationPolicy();
        }

        if (tgt.getTimeout().getMaxTimeToLiveInSeconds() > 0) {
            LOGGER.debug("Ticket-granting ticket expiration policy is based on a timeout of [{}] seconds",
                    tgt.getTimeout().getMaxTimeToLiveInSeconds());
            return new TimeoutExpirationPolicy(tgt.getTimeout().getMaxTimeToLiveInSeconds());
        }

        if (tgt.getMaxTimeToLiveInSeconds() > 0 && tgt.getTimeToKillInSeconds() > 0) {
            LOGGER.debug("Ticket-granting ticket expiration policy is based on hard/idle timeouts of [{}]/[{}] seconds",
                    tgt.getMaxTimeToLiveInSeconds(), tgt.getTimeToKillInSeconds());
            return new TicketGrantingTicketExpirationPolicy(tgt.getMaxTimeToLiveInSeconds(), tgt.getTimeToKillInSeconds());
        }

        if (tgt.getThrottledTimeout().getTimeInBetweenUsesInSeconds() > 0
                && tgt.getThrottledTimeout().getTimeToKillInSeconds() > 0) {
            final ThrottledUseAndTimeoutExpirationPolicy p = new ThrottledUseAndTimeoutExpirationPolicy();
            p.setTimeToKillInSeconds(tgt.getThrottledTimeout().getTimeToKillInSeconds());
            p.setTimeInBetweenUsesInSeconds(tgt.getThrottledTimeout().getTimeInBetweenUsesInSeconds());
            LOGGER.debug("Ticket-granting ticket expiration policy is based on throttled timeouts");
            return p;
        }

        if (tgt.getHardTimeout().getTimeToKillInSeconds() > 0) {
            LOGGER.debug("Ticket-granting ticket expiration policy is based on a hard timeout of [{}] seconds",
                    tgt.getHardTimeout().getTimeToKillInSeconds());
            return new HardTimeoutExpirationPolicy(tgt.getHardTimeout().getTimeToKillInSeconds());
        }
        LOGGER.warn("Ticket-granting ticket expiration policy is set to ALWAYS expire tickets.");
        return new AlwaysExpiresExpirationPolicy();
    }

参考地址请点这

你可能感兴趣的:(cas)