Search in sources :

Example 26 with TicketGrantingTicketImpl

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

the class AbstractTicketRegistryTests method verifyGetTicketsFromRegistryEqualToTicketsAdded.

@Test
public void verifyGetTicketsFromRegistryEqualToTicketsAdded() {
    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 -> fail("Ticket was added to registry but was not found in retrieval of collection of all tickets."));
    } catch (final Exception e) {
        fail(EXCEPTION_CAUGHT_NONE_EXPECTED);
    }
}
Also used : Collection(java.util.Collection) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) Test(org.junit.Test) ArrayList(java.util.ArrayList) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) Service(org.apereo.cas.authentication.principal.Service) RegisteredServiceTestUtils(org.apereo.cas.services.RegisteredServiceTestUtils) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Assert(org.junit.Assert) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) CoreAuthenticationTestUtils(org.apereo.cas.authentication.CoreAuthenticationTestUtils) Ticket(org.apereo.cas.ticket.Ticket) Before(org.junit.Before) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ArrayList(java.util.ArrayList) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Test(org.junit.Test)

Example 27 with TicketGrantingTicketImpl

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

the class CentralAuthenticationServiceImplTests method verifyDestroyRemoteRegistry.

/**
     * This test checks that the TGT destruction happens properly for a remote registry.
     * It previously failed when the deletion happens before the ticket was marked expired because an update was necessary for that.
     */
@Test
public void verifyDestroyRemoteRegistry() throws AbstractTicketException, AuthenticationException {
    final MockOnlyOneTicketRegistry registry = new MockOnlyOneTicketRegistry();
    final TicketGrantingTicketImpl tgt = new TicketGrantingTicketImpl("TGT-1", mock(Authentication.class), mock(ExpirationPolicy.class));
    final MockExpireUpdateTicketLogoutManager logoutManager = new MockExpireUpdateTicketLogoutManager(registry);
    registry.addTicket(tgt);
    final DefaultCentralAuthenticationService cas = new DefaultCentralAuthenticationService(registry, null, null, logoutManager, null, null, null, null);
    cas.setApplicationEventPublisher(mock(ApplicationEventPublisher.class));
    cas.destroyTicketGrantingTicket(tgt.getId());
}
Also used : Authentication(org.apereo.cas.authentication.Authentication) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) MockOnlyOneTicketRegistry(org.apereo.cas.util.MockOnlyOneTicketRegistry) ExpirationPolicy(org.apereo.cas.ticket.ExpirationPolicy) Test(org.junit.Test)

Example 28 with TicketGrantingTicketImpl

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

the class MemCacheTicketRegistryTests method verifyDeleteTicketWithPGT.

@Test
public void verifyDeleteTicketWithPGT() {
    final Authentication a = CoreAuthenticationTestUtils.getAuthentication();
    this.registry.addTicket(new TicketGrantingTicketImpl(TGT_ID, a, new NeverExpiresExpirationPolicy()));
    final TicketGrantingTicket tgt = this.registry.getTicket(TGT_ID, TicketGrantingTicket.class);
    final Service service = RegisteredServiceTestUtils.getService("TGT_DELETE_TEST");
    final ServiceTicket st1 = tgt.grantServiceTicket(ST_1_ID, service, new NeverExpiresExpirationPolicy(), false, true);
    this.registry.addTicket(st1);
    this.registry.updateTicket(tgt);
    assertNotNull(this.registry.getTicket(TGT_ID, TicketGrantingTicket.class));
    assertNotNull(this.registry.getTicket(ST_1_ID, ServiceTicket.class));
    final ProxyGrantingTicket pgt = st1.grantProxyGrantingTicket(PGT_1_ID, a, new NeverExpiresExpirationPolicy());
    this.registry.addTicket(pgt);
    this.registry.updateTicket(tgt);
    this.registry.updateTicket(st1);
    assertEquals(pgt.getGrantingTicket(), tgt);
    assertNotNull(this.registry.getTicket(PGT_1_ID, ProxyGrantingTicket.class));
    assertEquals(a, pgt.getAuthentication());
    assertNotNull(this.registry.getTicket(ST_1_ID, ServiceTicket.class));
    assertTrue(this.registry.deleteTicket(tgt.getId()) > 0);
    assertNull(this.registry.getTicket(TGT_ID, TicketGrantingTicket.class));
    assertNull(this.registry.getTicket(ST_1_ID, ServiceTicket.class));
    assertNull(this.registry.getTicket(PGT_1_ID, ProxyGrantingTicket.class));
}
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

TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)28 Test (org.junit.Test)22 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)17 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)12 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)10 Authentication (org.apereo.cas.authentication.Authentication)8 Service (org.apereo.cas.authentication.principal.Service)8 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)5 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)5 Before (org.junit.Before)5 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)3 MockService (org.apereo.cas.mock.MockService)2 ExpirationPolicy (org.apereo.cas.ticket.ExpirationPolicy)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)2 MockRequestContext (org.springframework.webflow.test.MockRequestContext)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1