Search in sources :

Example 1 with HardTimeoutExpirationPolicy

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()));
}
Also used : lombok.val(lombok.val) HardTimeoutExpirationPolicy(org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 2 with HardTimeoutExpirationPolicy

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);
}
Also used : lombok.val(lombok.val) HardTimeoutExpirationPolicy(org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Test(org.junit.jupiter.api.Test)

Example 3 with 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();
}
Also used : lombok.val(lombok.val) TimerTask(java.util.TimerTask) Timer(java.util.Timer) HardTimeoutExpirationPolicy(org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with HardTimeoutExpirationPolicy

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;
}
Also used : lombok.val(lombok.val) HardTimeoutExpirationPolicy(org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy) RememberMeDelegatingExpirationPolicy(org.apereo.cas.ticket.expiration.RememberMeDelegatingExpirationPolicy)

Example 5 with HardTimeoutExpirationPolicy

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();
}
Also used : lombok.val(lombok.val) ThrottledUseAndTimeoutExpirationPolicy(org.apereo.cas.ticket.expiration.ThrottledUseAndTimeoutExpirationPolicy) HardTimeoutExpirationPolicy(org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy) TicketGrantingTicketExpirationPolicy(org.apereo.cas.ticket.expiration.TicketGrantingTicketExpirationPolicy) AlwaysExpiresExpirationPolicy(org.apereo.cas.ticket.expiration.AlwaysExpiresExpirationPolicy) HardTimeoutExpirationPolicy(org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy) TimeoutExpirationPolicy(org.apereo.cas.ticket.expiration.TimeoutExpirationPolicy) ThrottledUseAndTimeoutExpirationPolicy(org.apereo.cas.ticket.expiration.ThrottledUseAndTimeoutExpirationPolicy)

Aggregations

lombok.val (lombok.val)17 HardTimeoutExpirationPolicy (org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy)17 Test (org.junit.jupiter.api.Test)12 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)10 OAuth20DefaultCode (org.apereo.cas.ticket.code.OAuth20DefaultCode)8 JEEContext (org.pac4j.core.context.JEEContext)8 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)3 RepeatedTest (org.junit.jupiter.api.RepeatedTest)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 LinkedHashMap (java.util.LinkedHashMap)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 AcceptUsersAuthenticationHandler (org.apereo.cas.authentication.AcceptUsersAuthenticationHandler)1 DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)1