use of org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy in project cas by apereo.
the class CachingTicketRegistryTests method verifyExpirationByTimeout.
@RepeatedTest(1)
public void verifyExpirationByTimeout() throws Exception {
val registry = new CachingTicketRegistry(CipherExecutor.noOp(), new DirectObjectProvider<>(mock(LogoutManager.class)));
val ticket = new TicketGrantingTicketImpl(TicketGrantingTicket.PREFIX + "-12346", RegisteredServiceTestUtils.getAuthentication(), new HardTimeoutExpirationPolicy(1));
registry.addTicket(ticket);
Thread.sleep(3000);
assertNull(registry.getTicket(ticket.getId()));
}
use of org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy in project cas by apereo.
the class TicketGrantingTicketExpirationPolicyBuilderTests method verifyHard.
@Test
public void verifyHard() {
val props = new CasConfigurationProperties();
props.getTicket().getTgt().getHardTimeout().setTimeToKillInSeconds(10);
val builder = new TicketGrantingTicketExpirationPolicyBuilder(props);
assertTrue(builder.buildTicketExpirationPolicy() instanceof HardTimeoutExpirationPolicy);
}
use of org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy in project cas by apereo.
the class JpaTicketRegistryCleanerTests method verifyConcurrentCleaner.
@Test
@Order(100)
public void verifyConcurrentCleaner() throws Exception {
val registryTask = new TimerTask() {
@Override
public void run() {
for (int i = 0; i < 5; i++) {
FunctionUtils.doUnchecked(s -> {
val tgt = new TicketGrantingTicketImpl(TicketGrantingTicket.PREFIX + '-' + RandomUtils.randomAlphabetic(16), CoreAuthenticationTestUtils.getAuthentication(UUID.randomUUID().toString()), new HardTimeoutExpirationPolicy(1));
ticketRegistry.addTicket(tgt);
val st = tgt.grantServiceTicket(ServiceTicket.PREFIX + '-' + RandomUtils.randomAlphabetic(16), RegisteredServiceTestUtils.getService(), new HardTimeoutExpirationPolicy(1), true, false);
ticketRegistry.addTicket(st);
ticketRegistry.updateTicket(tgt);
});
}
}
};
val registryTimer = new Timer("TicketRegistry");
registryTimer.scheduleAtFixedRate(registryTask, 5, 5);
val cleanerTask = new TimerTask() {
public void run() {
ticketRegistryCleaner.clean();
}
};
val cleanerTimer = new Timer("TicketRegistryCleaner");
cleanerTimer.scheduleAtFixedRate(cleanerTask, 10, 5);
Thread.sleep(1000 * 15);
cleanerTimer.cancel();
registryTimer.cancel();
ticketRegistry.deleteAll();
}
use of org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy in project cas by apereo.
the class TicketGrantingTicketExpirationPolicyBuilder method toRememberMeTicketExpirationPolicy.
/**
* To remember-me ticket expiration policy.
*
* @return the expiration policy
*/
public ExpirationPolicy toRememberMeTicketExpirationPolicy() {
val tgt = casProperties.getTicket().getTgt();
LOGGER.debug("Remember me expiration policy is being configured based on hard timeout of [{}] seconds", tgt.getRememberMe().getTimeToKillInSeconds());
val rememberMePolicy = new HardTimeoutExpirationPolicy(tgt.getRememberMe().getTimeToKillInSeconds());
val p = new RememberMeDelegatingExpirationPolicy();
p.addPolicy(RememberMeDelegatingExpirationPolicy.POLICY_NAME_REMEMBER_ME, rememberMePolicy);
p.addPolicy(RememberMeDelegatingExpirationPolicy.POLICY_NAME_DEFAULT, toTicketGrantingTicketExpirationPolicy());
return p;
}
use of org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy in project cas by apereo.
the class TicketGrantingTicketExpirationPolicyBuilder method toTicketGrantingTicketExpirationPolicy.
/**
* To ticket-granting ticket expiration policy.
*
* @return the expiration policy
*/
protected ExpirationPolicy toTicketGrantingTicketExpirationPolicy() {
val tgt = casProperties.getTicket().getTgt();
if (tgt.getPrimary().getMaxTimeToLiveInSeconds() <= 0 && tgt.getPrimary().getTimeToKillInSeconds() <= 0) {
LOGGER.warn("Ticket-granting ticket expiration policy is set to NEVER expire tickets.");
return NeverExpiresExpirationPolicy.INSTANCE;
}
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.getThrottledTimeout().getTimeInBetweenUsesInSeconds() > 0 && tgt.getThrottledTimeout().getTimeToKillInSeconds() > 0) {
val 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());
}
if (tgt.getPrimary().getMaxTimeToLiveInSeconds() > 0 && tgt.getPrimary().getTimeToKillInSeconds() > 0) {
LOGGER.debug("Ticket-granting ticket expiration policy is based on hard/idle timeouts of [{}]/[{}] seconds", tgt.getPrimary().getMaxTimeToLiveInSeconds(), tgt.getPrimary().getTimeToKillInSeconds());
return new TicketGrantingTicketExpirationPolicy(tgt.getPrimary().getMaxTimeToLiveInSeconds(), tgt.getPrimary().getTimeToKillInSeconds());
}
LOGGER.warn("Ticket-granting ticket expiration policy is set to ALWAYS expire tickets.");
return new AlwaysExpiresExpirationPolicy();
}
Aggregations