Search in sources :

Example 1 with AlwaysExpiresExpirationPolicy

use of org.apereo.cas.ticket.expiration.AlwaysExpiresExpirationPolicy in project cas by apereo.

the class BaseTicketRegistryTests method verifyExpiration.

@RepeatedTest(2)
public void verifyExpiration() throws Exception {
    val authn = CoreAuthenticationTestUtils.getAuthentication();
    LOGGER.trace("Adding ticket [{}]", ticketGrantingTicketId);
    ticketRegistry.addTicket(new TicketGrantingTicketImpl(ticketGrantingTicketId, authn, NeverExpiresExpirationPolicy.INSTANCE));
    LOGGER.trace("Getting ticket [{}]", ticketGrantingTicketId);
    val tgt = ticketRegistry.getTicket(ticketGrantingTicketId, TicketGrantingTicket.class);
    assertNotNull(tgt, () -> "Ticket-granting ticket " + ticketGrantingTicketId + " cannot be fetched");
    val service = RegisteredServiceTestUtils.getService("TGT_DELETE_TEST");
    LOGGER.trace("Granting service ticket [{}]", serviceTicketId);
    val ticket = (AbstractTicket) tgt.grantServiceTicket(serviceTicketId, service, NeverExpiresExpirationPolicy.INSTANCE, false, true);
    assertNotNull(ticket, "Service ticket cannot be null");
    ticket.setExpirationPolicy(new AlwaysExpiresExpirationPolicy());
    ticketRegistry.addTicket(ticket);
    ticketRegistry.updateTicket(tgt);
    assertNull(ticketRegistry.getTicket(serviceTicketId, ServiceTicket.class));
}
Also used : lombok.val(lombok.val) AbstractTicket(org.apereo.cas.ticket.AbstractTicket) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) AlwaysExpiresExpirationPolicy(org.apereo.cas.ticket.expiration.AlwaysExpiresExpirationPolicy) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 2 with AlwaysExpiresExpirationPolicy

use of org.apereo.cas.ticket.expiration.AlwaysExpiresExpirationPolicy 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)

Example 3 with AlwaysExpiresExpirationPolicy

use of org.apereo.cas.ticket.expiration.AlwaysExpiresExpirationPolicy in project cas by apereo.

the class BaseTicketRegistryTests method verifyExpiredTicket.

@RepeatedTest(2)
public void verifyExpiredTicket() throws Exception {
    val authn = CoreAuthenticationTestUtils.getAuthentication();
    ticketRegistry.addTicket(new TicketGrantingTicketImpl(ticketGrantingTicketId, authn, new AlwaysExpiresExpirationPolicy()));
    var tgt = ticketRegistry.getTicket(ticketGrantingTicketId, TicketGrantingTicket.class);
    assertNull(tgt);
}
Also used : lombok.val(lombok.val) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) AlwaysExpiresExpirationPolicy(org.apereo.cas.ticket.expiration.AlwaysExpiresExpirationPolicy) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 4 with AlwaysExpiresExpirationPolicy

use of org.apereo.cas.ticket.expiration.AlwaysExpiresExpirationPolicy in project cas by apereo.

the class TicketGrantingTicketExpirationPolicyBuilderTests method verifyAlways.

@Test
public void verifyAlways() {
    val props = new CasConfigurationProperties();
    props.getTicket().getTgt().getPrimary().setMaxTimeToLiveInSeconds(1);
    props.getTicket().getTgt().getPrimary().setTimeToKillInSeconds(-1);
    val builder = new TicketGrantingTicketExpirationPolicyBuilder(props);
    assertTrue(builder.buildTicketExpirationPolicy() instanceof AlwaysExpiresExpirationPolicy);
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) AlwaysExpiresExpirationPolicy(org.apereo.cas.ticket.expiration.AlwaysExpiresExpirationPolicy) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)4 AlwaysExpiresExpirationPolicy (org.apereo.cas.ticket.expiration.AlwaysExpiresExpirationPolicy)4 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)2 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 AbstractTicket (org.apereo.cas.ticket.AbstractTicket)1 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)1 HardTimeoutExpirationPolicy (org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy)1 ThrottledUseAndTimeoutExpirationPolicy (org.apereo.cas.ticket.expiration.ThrottledUseAndTimeoutExpirationPolicy)1 TicketGrantingTicketExpirationPolicy (org.apereo.cas.ticket.expiration.TicketGrantingTicketExpirationPolicy)1 TimeoutExpirationPolicy (org.apereo.cas.ticket.expiration.TimeoutExpirationPolicy)1 Test (org.junit.jupiter.api.Test)1