Search in sources :

Example 1 with ProxyGrantingTicketIssuerTicket

use of org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket in project cas by apereo.

the class BaseTicketRegistryTests method verifyDeleteTicketWithPGT.

@RepeatedTest(2)
public void verifyDeleteTicketWithPGT() throws Exception {
    val a = CoreAuthenticationTestUtils.getAuthentication();
    ticketRegistry.addTicket(new TicketGrantingTicketImpl(ticketGrantingTicketId, a, NeverExpiresExpirationPolicy.INSTANCE));
    val tgt = ticketRegistry.getTicket(ticketGrantingTicketId, TicketGrantingTicket.class);
    val service = RegisteredServiceTestUtils.getService("TGT_DELETE_TEST");
    val st1 = (ProxyGrantingTicketIssuerTicket) tgt.grantServiceTicket(serviceTicketId, service, NeverExpiresExpirationPolicy.INSTANCE, false, true);
    ticketRegistry.addTicket(st1);
    ticketRegistry.updateTicket(tgt);
    assertNotNull(ticketRegistry.getTicket(ticketGrantingTicketId, TicketGrantingTicket.class));
    assertNotNull(ticketRegistry.getTicket(serviceTicketId, ServiceTicket.class));
    val pgt = st1.grantProxyGrantingTicket(proxyGrantingTicketId, a, NeverExpiresExpirationPolicy.INSTANCE);
    ticketRegistry.addTicket(pgt);
    ticketRegistry.updateTicket(tgt);
    ticketRegistry.updateTicket(st1);
    assertEquals(pgt.getTicketGrantingTicket(), tgt);
    assertNotNull(ticketRegistry.getTicket(proxyGrantingTicketId, ProxyGrantingTicket.class));
    assertEquals(a, pgt.getAuthentication());
    assertNotNull(ticketRegistry.getTicket(serviceTicketId, ServiceTicket.class));
    await().untilAsserted(() -> assertTrue(ticketRegistry.deleteTicket(tgt.getId()) > 0));
    assertNull(ticketRegistry.getTicket(ticketGrantingTicketId, TicketGrantingTicket.class));
    assertNull(ticketRegistry.getTicket(serviceTicketId, ServiceTicket.class));
    assertNull(ticketRegistry.getTicket(proxyGrantingTicketId, ProxyGrantingTicket.class));
}
Also used : lombok.val(lombok.val) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) ProxyGrantingTicketIssuerTicket(org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 2 with ProxyGrantingTicketIssuerTicket

use of org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket in project cas by apereo.

the class BaseTicketRegistryTests method verifyDeleteTicketsWithMultiplePGTs.

@RepeatedTest(2)
public void verifyDeleteTicketsWithMultiplePGTs() throws Exception {
    FunctionUtils.doAndRetry(callback -> {
        val a = CoreAuthenticationTestUtils.getAuthentication();
        ticketRegistry.addTicket(new TicketGrantingTicketImpl(ticketGrantingTicketId, a, NeverExpiresExpirationPolicy.INSTANCE));
        val tgt = ticketRegistry.getTicket(ticketGrantingTicketId, TicketGrantingTicket.class);
        assertNotNull(tgt, "Ticket-granting ticket must not be null");
        val service = RegisteredServiceTestUtils.getService("TGT_DELETE_TEST");
        IntStream.range(1, 5).forEach(Unchecked.intConsumer(i -> {
            val st = (ProxyGrantingTicketIssuerTicket) tgt.grantServiceTicket(serviceTicketId + '-' + i, service, NeverExpiresExpirationPolicy.INSTANCE, false, true);
            ticketRegistry.addTicket(st);
            ticketRegistry.updateTicket(tgt);
            val pgt = st.grantProxyGrantingTicket(proxyGrantingTicketId + '-' + i, a, NeverExpiresExpirationPolicy.INSTANCE);
            ticketRegistry.addTicket(pgt);
            ticketRegistry.updateTicket(tgt);
            ticketRegistry.updateTicket(st);
        }));
        val c = ticketRegistry.deleteTicket(ticketGrantingTicketId);
        assertEquals(6, c);
        return null;
    });
}
Also used : lombok.val(lombok.val) BeforeEach(org.junit.jupiter.api.BeforeEach) RepeatedTest(org.junit.jupiter.api.RepeatedTest) TransientSessionTicketImpl(org.apereo.cas.ticket.TransientSessionTicketImpl) CipherExecutor(org.apereo.cas.util.crypto.CipherExecutor) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ExpirationPolicyBuilder(org.apereo.cas.ticket.ExpirationPolicyBuilder) CasCoreConfiguration(org.apereo.cas.config.CasCoreConfiguration) ProxyGrantingTicketIssuerTicket(org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket) FunctionUtils(org.apereo.cas.util.function.FunctionUtils) CasWebApplicationServiceFactoryConfiguration(org.apereo.cas.config.support.CasWebApplicationServiceFactoryConfiguration) TicketGrantingTicketIdGenerator(org.apereo.cas.util.TicketGrantingTicketIdGenerator) RegisteredServiceTestUtils(org.apereo.cas.services.RegisteredServiceTestUtils) TimeoutExpirationPolicy(org.apereo.cas.ticket.expiration.TimeoutExpirationPolicy) CasCoreAuthenticationServiceSelectionStrategyConfiguration(org.apereo.cas.config.CasCoreAuthenticationServiceSelectionStrategyConfiguration) TicketFactory(org.apereo.cas.ticket.TicketFactory) Tag(org.junit.jupiter.api.Tag) ZoneOffset(java.time.ZoneOffset) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) CasCoreWebConfiguration(org.apereo.cas.config.CasCoreWebConfiguration) TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) Unchecked(org.jooq.lambda.Unchecked) CasCoreTicketIdGeneratorsConfiguration(org.apereo.cas.config.CasCoreTicketIdGeneratorsConfiguration) CasCoreLogoutConfiguration(org.apereo.cas.logout.config.CasCoreLogoutConfiguration) UUID(java.util.UUID) CasCoreAuthenticationPolicyConfiguration(org.apereo.cas.config.CasCoreAuthenticationPolicyConfiguration) TestInfo(org.junit.jupiter.api.TestInfo) CasCookieConfiguration(org.apereo.cas.web.config.CasCookieConfiguration) DefaultUniqueTicketIdGenerator(org.apereo.cas.util.DefaultUniqueTicketIdGenerator) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) CasCoreTicketCatalogConfiguration(org.apereo.cas.config.CasCoreTicketCatalogConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CasCoreTicketsConfiguration(org.apereo.cas.config.CasCoreTicketsConfiguration) AbstractTicket(org.apereo.cas.ticket.AbstractTicket) CasPersonDirectoryConfiguration(org.apereo.cas.config.CasPersonDirectoryConfiguration) Awaitility(org.awaitility.Awaitility) CasCoreAuthenticationSupportConfiguration(org.apereo.cas.config.CasCoreAuthenticationSupportConfiguration) EncryptionRandomizedSigningJwtCryptographyProperties(org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties) IntStream(java.util.stream.IntStream) CasCoreAuthenticationConfiguration(org.apereo.cas.config.CasCoreAuthenticationConfiguration) TicketGrantingTicketExpirationPolicy(org.apereo.cas.ticket.expiration.TicketGrantingTicketExpirationPolicy) ImportAutoConfiguration(org.springframework.boot.autoconfigure.ImportAutoConfiguration) AopTestUtils(org.springframework.test.util.AopTestUtils) CasCoreTicketsSchedulingConfiguration(org.apereo.cas.config.CasCoreTicketsSchedulingConfiguration) ArrayList(java.util.ArrayList) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) RepetitionInfo(org.junit.jupiter.api.RepetitionInfo) ProxyGrantingTicketIdGenerator(org.apereo.cas.util.ProxyGrantingTicketIdGenerator) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.expiration.NeverExpiresExpirationPolicy) RefreshAutoConfiguration(org.springframework.cloud.autoconfigure.RefreshAutoConfiguration) CasCoreNotificationsConfiguration(org.apereo.cas.config.CasCoreNotificationsConfiguration) ServiceTicketIdGenerator(org.apereo.cas.util.ServiceTicketIdGenerator) CollectionUtils(org.apereo.cas.util.CollectionUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) CasCoreAuthenticationMetadataConfiguration(org.apereo.cas.config.CasCoreAuthenticationMetadataConfiguration) CasCoreAuthenticationHandlersConfiguration(org.apereo.cas.config.CasCoreAuthenticationHandlersConfiguration) CasCoreHttpConfiguration(org.apereo.cas.config.CasCoreHttpConfiguration) CasCoreServicesConfiguration(org.apereo.cas.config.CasCoreServicesConfiguration) CasCoreServicesAuthenticationConfiguration(org.apereo.cas.config.CasCoreServicesAuthenticationConfiguration) CasCoreAuthenticationPrincipalConfiguration(org.apereo.cas.config.CasCoreAuthenticationPrincipalConfiguration) lombok.val(lombok.val) Import(org.springframework.context.annotation.Import) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) AlwaysExpiresExpirationPolicy(org.apereo.cas.ticket.expiration.AlwaysExpiresExpirationPolicy) CoreTicketUtils(org.apereo.cas.util.CoreTicketUtils) CasCoreTicketsSerializationConfiguration(org.apereo.cas.config.CasCoreTicketsSerializationConfiguration) Assumptions(org.junit.jupiter.api.Assumptions) SpringBootConfiguration(org.springframework.boot.SpringBootConfiguration) ExpirationPolicy(org.apereo.cas.ticket.ExpirationPolicy) Assertions(org.junit.jupiter.api.Assertions) Clock(java.time.Clock) CasCoreUtilConfiguration(org.apereo.cas.config.CasCoreUtilConfiguration) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Collections(java.util.Collections) CoreAuthenticationTestUtils(org.apereo.cas.authentication.CoreAuthenticationTestUtils) Ticket(org.apereo.cas.ticket.Ticket) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 3 with ProxyGrantingTicketIssuerTicket

use of org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket in project cas by apereo.

the class DefaultProxyGrantingTicketFactory method produceTicket.

/**
 * Produce ticket.
 *
 * @param <T>            the type parameter
 * @param serviceTicket  the service ticket
 * @param authentication the authentication
 * @param pgtId          the pgt id
 * @param clazz          the clazz
 * @return the ticket
 */
protected <T extends ProxyGrantingTicket> T produceTicket(final ServiceTicket serviceTicket, final Authentication authentication, final String pgtId, final Class<T> clazz) {
    val proxyGrantingTicketExpirationPolicy = getProxyGrantingTicketExpirationPolicy(serviceTicket);
    val pgtIssuer = (ProxyGrantingTicketIssuerTicket) serviceTicket;
    val result = produceTicketWithAdequateExpirationPolicy(proxyGrantingTicketExpirationPolicy, pgtIssuer, authentication, pgtId);
    if (!clazz.isAssignableFrom(result.getClass())) {
        throw new ClassCastException("Result [" + result + " is of type " + result.getClass() + " when we were expecting " + clazz);
    }
    return (T) result;
}
Also used : lombok.val(lombok.val) ProxyGrantingTicketIssuerTicket(org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket)

Example 4 with ProxyGrantingTicketIssuerTicket

use of org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket in project cas by apereo.

the class DistributedTicketRegistryTests method verifyUpdateOfRegistry.

@Test
public void verifyUpdateOfRegistry() throws Exception {
    val t = new TicketGrantingTicketImpl(TGT_ID, CoreAuthenticationTestUtils.getAuthentication(), NeverExpiresExpirationPolicy.INSTANCE);
    this.ticketRegistry.addTicket(t);
    val returned = (TicketGrantingTicket) this.ticketRegistry.getTicket(TGT_ID);
    val s = (ProxyGrantingTicketIssuerTicket) returned.grantServiceTicket("test2", RegisteredServiceTestUtils.getService(), NeverExpiresExpirationPolicy.INSTANCE, false, true);
    this.ticketRegistry.addTicket(s);
    val s2 = (ProxyGrantingTicketIssuerTicket) this.ticketRegistry.getTicket("test2");
    assertNotNull(s2.grantProxyGrantingTicket("ff", CoreAuthenticationTestUtils.getAuthentication(), NeverExpiresExpirationPolicy.INSTANCE));
    assertTrue(this.wasTicketUpdated);
    returned.markTicketExpired();
    assertTrue(t.isExpired());
}
Also used : lombok.val(lombok.val) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) ProxyGrantingTicketIssuerTicket(org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with ProxyGrantingTicketIssuerTicket

use of org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket in project cas by apereo.

the class DistributedTicketRegistryTests method verifyDeleteTicketWithPGT.

@Test
public void verifyDeleteTicketWithPGT() throws Exception {
    val a = CoreAuthenticationTestUtils.getAuthentication();
    this.ticketRegistry.addTicket(new TicketGrantingTicketImpl(TGT_NAME, a, NeverExpiresExpirationPolicy.INSTANCE));
    val tgt = this.ticketRegistry.getTicket(TGT_NAME, TicketGrantingTicket.class);
    val service = CoreAuthenticationTestUtils.getService("TGT_DELETE_TEST");
    val st1 = (ProxyGrantingTicketIssuerTicket) tgt.grantServiceTicket("ST1", service, NeverExpiresExpirationPolicy.INSTANCE, true, true);
    this.ticketRegistry.addTicket(st1);
    assertNotNull(this.ticketRegistry.getTicket(TGT_NAME, TicketGrantingTicket.class));
    assertNotNull(this.ticketRegistry.getTicket("ST1", ServiceTicket.class));
    val pgt = st1.grantProxyGrantingTicket("PGT-1", a, NeverExpiresExpirationPolicy.INSTANCE);
    assertEquals(a, pgt.getAuthentication());
    this.ticketRegistry.addTicket(pgt);
    assertSame(3, this.ticketRegistry.deleteTicket(tgt.getId()));
    assertNull(this.ticketRegistry.getTicket(TGT_NAME, TicketGrantingTicket.class));
    assertNull(this.ticketRegistry.getTicket("ST1", ServiceTicket.class));
    assertNull(this.ticketRegistry.getTicket("PGT-1", ProxyGrantingTicket.class));
}
Also used : lombok.val(lombok.val) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) RenewableServiceTicket(org.apereo.cas.ticket.RenewableServiceTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) ProxyGrantingTicketIssuerTicket(org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)6 ProxyGrantingTicketIssuerTicket (org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket)6 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)5 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)4 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)3 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)3 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 Clock (java.time.Clock)1 ZoneOffset (java.time.ZoneOffset)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 UUID (java.util.UUID)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 Slf4j (lombok.extern.slf4j.Slf4j)1