Search in sources :

Example 46 with ServiceTicket

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

the class AbstractTicketRegistryTests method verifyDeleteTicketWithPGT.

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

Example 47 with ServiceTicket

use of org.apereo.cas.ticket.ServiceTicket 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 48 with ServiceTicket

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

Example 49 with ServiceTicket

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

the class StatisticsController method getTicketStats.

/**
 * Gets ticket stats.
 *
 * @param request  the http servlet request
 * @param response the http servlet response
 * @return the ticket stats
 */
@GetMapping(value = "/getTicketStats")
@ResponseBody
public Map<String, Object> getTicketStats(final HttpServletRequest request, final HttpServletResponse response) {
    ensureEndpointAccessIsAuthorized(request, response);
    final Map<String, Object> model = new HashMap<>();
    int unexpiredTgts = 0;
    int unexpiredSts = 0;
    int expiredTgts = 0;
    int expiredSts = 0;
    final Collection<Ticket> tickets = this.centralAuthenticationService.getTickets(ticket -> true);
    for (final Ticket ticket : tickets) {
        if (ticket instanceof ServiceTicket) {
            if (ticket.isExpired()) {
                this.centralAuthenticationService.deleteTicket(ticket.getId());
                expiredSts++;
            } else {
                unexpiredSts++;
            }
        } else {
            if (ticket.isExpired()) {
                this.centralAuthenticationService.deleteTicket(ticket.getId());
                expiredTgts++;
            } else {
                unexpiredTgts++;
            }
        }
    }
    model.put("unexpiredTgts", unexpiredTgts);
    model.put("unexpiredSts", unexpiredSts);
    model.put("expiredTgts", expiredTgts);
    model.put("expiredSts", expiredSts);
    return model;
}
Also used : ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Ticket(org.apereo.cas.ticket.Ticket) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) BaseCasMvcEndpoint(org.apereo.cas.web.BaseCasMvcEndpoint) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 50 with ServiceTicket

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

the class JpaTicketRegistryTests method verifyTicketCreationAndDeletion.

@Test
public void verifyTicketCreationAndDeletion() {
    // TGT
    final TicketGrantingTicket newTgt = newTGT();
    addTicketInTransaction(newTgt);
    TicketGrantingTicket tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
    assertNotNull(tgtFromDb);
    assertEquals(newTgt.getId(), tgtFromDb.getId());
    // ST
    final ServiceTicket newSt = grantServiceTicketInTransaction(tgtFromDb);
    final ServiceTicket stFromDb = (ServiceTicket) getTicketInTransaction(newSt.getId());
    assertNotNull(stFromDb);
    assertEquals(newSt.getId(), stFromDb.getId());
    // PGT
    final ProxyGrantingTicket newPgt = grantProxyGrantingTicketInTransaction(stFromDb);
    updateTicketInTransaction(stFromDb.getTicketGrantingTicket());
    final ProxyGrantingTicket pgtFromDb = (ProxyGrantingTicket) getTicketInTransaction(newPgt.getId());
    assertNotNull(pgtFromDb);
    assertEquals(newPgt.getId(), pgtFromDb.getId());
    tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
    assertNotNull(tgtFromDb);
    assertEquals(1, tgtFromDb.getProxyGrantingTickets().size());
    // PT
    final ProxyTicket newPt = grantProxyTicketInTransaction(pgtFromDb);
    final ProxyTicket ptFromDb = (ProxyTicket) getTicketInTransaction(newPt.getId());
    assertNotNull(ptFromDb);
    assertEquals(newPt.getId(), ptFromDb.getId());
    // ST 2
    final ServiceTicket newSt2 = grantServiceTicketInTransaction(tgtFromDb);
    final ServiceTicket st2FromDb = (ServiceTicket) getTicketInTransaction(newSt2.getId());
    assertNotNull(st2FromDb);
    assertEquals(newSt2.getId(), st2FromDb.getId());
    // PGT 2
    final ProxyGrantingTicket newPgt2 = grantProxyGrantingTicketInTransaction(st2FromDb);
    updateTicketInTransaction(st2FromDb.getTicketGrantingTicket());
    final ProxyGrantingTicket pgt2FromDb = (ProxyGrantingTicket) getTicketInTransaction(newPgt2.getId());
    assertNotNull(pgt2FromDb);
    assertEquals(newPgt2.getId(), pgt2FromDb.getId());
    tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
    assertNotNull(tgtFromDb);
    assertEquals(2, tgtFromDb.getProxyGrantingTickets().size());
    // delete PGT 2
    deleteTicketInTransaction(pgt2FromDb.getId());
    assertNull(getTicketInTransaction(newPgt2.getId()));
    tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
    assertNotNull(tgtFromDb);
    assertEquals(1, tgtFromDb.getProxyGrantingTickets().size());
    // delete ticket hierarchy
    tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
    assertNotNull(tgtFromDb);
    deleteTicketInTransaction(tgtFromDb.getId());
    assertNull(getTicketInTransaction(newTgt.getId()));
    assertNull(getTicketInTransaction(newSt.getId()));
    assertNull(getTicketInTransaction(newPgt.getId()));
    assertNull(getTicketInTransaction(newPt.getId()));
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) ProxyTicket(org.apereo.cas.ticket.proxy.ProxyTicket) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

ServiceTicket (org.apereo.cas.ticket.ServiceTicket)53 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)41 Test (org.junit.Test)38 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)27 Service (org.apereo.cas.authentication.principal.Service)27 Authentication (org.apereo.cas.authentication.Authentication)16 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)14 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)14 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)12 Assertion (org.apereo.cas.validation.Assertion)11 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)10 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)9 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 Credential (org.apereo.cas.authentication.Credential)6 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)6 HashMap (java.util.HashMap)4 lombok.val (lombok.val)4 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)4 Ticket (org.apereo.cas.ticket.Ticket)3