Search in sources :

Example 56 with NeverExpiresExpirationPolicy

use of org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy in project cas by apereo.

the class AbstractTicketRegistryTests method verifyGetTicketsFromRegistryEqualToTicketsAdded.

@Test
public void verifyGetTicketsFromRegistryEqualToTicketsAdded() {
    Assume.assumeTrue(isIterableRegistry());
    final Collection<Ticket> tickets = new ArrayList<>();
    for (int i = 0; i < TICKETS_IN_REGISTRY; i++) {
        final TicketGrantingTicket ticketGrantingTicket = new TicketGrantingTicketImpl(TicketGrantingTicket.PREFIX + i, CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
        final ServiceTicket st = ticketGrantingTicket.grantServiceTicket("ST" + i, RegisteredServiceTestUtils.getService(), new NeverExpiresExpirationPolicy(), false, true);
        tickets.add(ticketGrantingTicket);
        tickets.add(st);
        this.ticketRegistry.addTicket(ticketGrantingTicket);
        this.ticketRegistry.addTicket(st);
    }
    try {
        final Collection<Ticket> ticketRegistryTickets = this.ticketRegistry.getTickets();
        assertEquals("The size of the registry is not the same as the collection.", tickets.size(), ticketRegistryTickets.size());
        tickets.stream().filter(ticket -> !ticketRegistryTickets.contains(ticket)).forEach(ticket -> {
            throw new AssertionError("Ticket " + ticket + " was not found in retrieval of collection of all tickets.");
        });
    } catch (final Exception e) {
        throw new AssertionError(EXCEPTION_CAUGHT_NONE_EXPECTED + e.getMessage(), e);
    }
}
Also used : IntStream(java.util.stream.IntStream) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) AlwaysExpiresExpirationPolicy(org.apereo.cas.ticket.support.AlwaysExpiresExpirationPolicy) AopTestUtils(org.springframework.test.util.AopTestUtils) ArrayList(java.util.ArrayList) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) SpringMethodRule(org.springframework.test.context.junit4.rules.SpringMethodRule) Authentication(org.apereo.cas.authentication.Authentication) RegisteredServiceTestUtils(org.apereo.cas.services.RegisteredServiceTestUtils) Assume(org.junit.Assume) SpringClassRule(org.springframework.test.context.junit4.rules.SpringClassRule) ClassRule(org.junit.ClassRule) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Before(org.junit.Before) Collection(java.util.Collection) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) Test(org.junit.Test) CipherExecutor(org.apereo.cas.CipherExecutor) CoreTicketUtils(org.apereo.cas.util.CoreTicketUtils) Slf4j(lombok.extern.slf4j.Slf4j) Rule(org.junit.Rule) Service(org.apereo.cas.authentication.principal.Service) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Assert(org.junit.Assert) Collections(java.util.Collections) CoreAuthenticationTestUtils(org.apereo.cas.authentication.CoreAuthenticationTestUtils) EncryptionRandomizedSigningJwtCryptographyProperties(org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties) Ticket(org.apereo.cas.ticket.Ticket) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Ticket(org.apereo.cas.ticket.Ticket) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ArrayList(java.util.ArrayList) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Test(org.junit.Test)

Example 57 with NeverExpiresExpirationPolicy

use of org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy in project cas by apereo.

the class AbstractTicketRegistryTests method verifyAddAndUpdateTicket.

@Test
public void verifyAddAndUpdateTicket() {
    try {
        TicketGrantingTicket tgt = new TicketGrantingTicketImpl(TicketGrantingTicket.PREFIX, CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
        this.ticketRegistry.addTicket(tgt);
        tgt = this.ticketRegistry.getTicket(tgt.getId(), TicketGrantingTicket.class);
        assertNotNull(tgt);
        assertTrue(tgt.getServices().isEmpty());
        tgt.grantServiceTicket("ST1", RegisteredServiceTestUtils.getService("TGT_UPDATE_TEST"), new NeverExpiresExpirationPolicy(), false, false);
        this.ticketRegistry.updateTicket(tgt);
        tgt = this.ticketRegistry.getTicket(tgt.getId(), TicketGrantingTicket.class);
        assertEquals(Collections.singleton("ST1"), tgt.getServices().keySet());
    } catch (final Exception e) {
        throw new AssertionError(CAUGHT_AN_EXCEPTION_BUT_WAS_NOT_EXPECTED + e.getMessage(), e);
    }
}
Also used : NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) Test(org.junit.Test)

Example 58 with NeverExpiresExpirationPolicy

use of org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy in project cas by apereo.

the class AbstractTicketRegistryTests method verifyDeleteExistingTicket.

@Test
public void verifyDeleteExistingTicket() {
    try {
        this.ticketRegistry.addTicket(new TicketGrantingTicketImpl(TicketGrantingTicket.PREFIX, CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()));
        assertSame(1, this.ticketRegistry.deleteTicket(TicketGrantingTicket.PREFIX));
        assertNull(this.ticketRegistry.getTicket(TicketGrantingTicket.PREFIX));
    } catch (final Exception e) {
        throw new AssertionError(CAUGHT_AN_EXCEPTION_BUT_WAS_NOT_EXPECTED + e.getMessage(), e);
    }
}
Also used : NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) Test(org.junit.Test)

Example 59 with NeverExpiresExpirationPolicy

use of org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy in project cas by apereo.

the class AbstractTicketRegistryTests method verifyWriteGetDelete.

@Test
public void verifyWriteGetDelete() {
    final Ticket ticket = new TicketGrantingTicketImpl(TicketGrantingTicket.PREFIX, CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
    ticketRegistry.addTicket(ticket);
    final Ticket ticketFromRegistry = ticketRegistry.getTicket(TicketGrantingTicket.PREFIX);
    assertNotNull(ticketFromRegistry);
    assertEquals(TicketGrantingTicket.PREFIX, ticketFromRegistry.getId());
    ticketRegistry.deleteTicket(TicketGrantingTicket.PREFIX);
    assertNull(ticketRegistry.getTicket(TicketGrantingTicket.PREFIX));
}
Also used : MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Ticket(org.apereo.cas.ticket.Ticket) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) Test(org.junit.Test)

Example 60 with NeverExpiresExpirationPolicy

use of org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy in project cas by apereo.

the class AbstractTicketRegistryTests method verifyDeleteTicketsWithMultiplePGTs.

@Test
public void verifyDeleteTicketsWithMultiplePGTs() {
    final Authentication a = CoreAuthenticationTestUtils.getAuthentication();
    this.ticketRegistry.addTicket(new TicketGrantingTicketImpl(TGT_ID, a, new NeverExpiresExpirationPolicy()));
    final TicketGrantingTicket tgt = this.ticketRegistry.getTicket(TGT_ID, TicketGrantingTicket.class);
    final Service service = RegisteredServiceTestUtils.getService("TGT_DELETE_TEST");
    IntStream.range(1, 5).forEach(i -> {
        final ServiceTicket st = tgt.grantServiceTicket(ST_1_ID + "-" + i, service, new NeverExpiresExpirationPolicy(), false, true);
        this.ticketRegistry.addTicket(st);
        this.ticketRegistry.updateTicket(tgt);
        final ProxyGrantingTicket pgt = st.grantProxyGrantingTicket(PGT_1_ID + "-" + i, a, new NeverExpiresExpirationPolicy());
        this.ticketRegistry.addTicket(pgt);
        this.ticketRegistry.updateTicket(tgt);
        this.ticketRegistry.updateTicket(st);
    });
    final int c = this.ticketRegistry.deleteTicket(TGT_ID);
    assertEquals(6, c);
}
Also used : NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) Authentication(org.apereo.cas.authentication.Authentication) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Service(org.apereo.cas.authentication.principal.Service) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) Test(org.junit.Test)

Aggregations

NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)64 Test (org.junit.Test)61 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)27 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)20 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)15 Authentication (org.apereo.cas.authentication.Authentication)14 Service (org.apereo.cas.authentication.principal.Service)13 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)12 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)12 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)9 MultiTimeUseOrTimeoutExpirationPolicy (org.apereo.cas.ticket.support.MultiTimeUseOrTimeoutExpirationPolicy)5 ArrayList (java.util.ArrayList)4 StringBean (org.apereo.cas.StringBean)4 HashMap (java.util.HashMap)3 AlwaysExpiresExpirationPolicy (org.apereo.cas.ticket.support.AlwaysExpiresExpirationPolicy)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 LinkedHashMap (java.util.LinkedHashMap)2 CachedData (net.spy.memcached.CachedData)2 AcceptUsersAuthenticationHandler (org.apereo.cas.authentication.AcceptUsersAuthenticationHandler)2