Search in sources :

Example 6 with ProxyGrantingTicket

use of org.apereo.cas.ticket.proxy.ProxyGrantingTicket in project cas by apereo.

the class ProxyControllerTests method verifyExistingPGT.

@Test
public void verifyExistingPGT() throws Exception {
    final ProxyGrantingTicket ticket = new ProxyGrantingTicketImpl("ticketGrantingTicketId", CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
    getTicketRegistry().addTicket(ticket);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET, ticket.getId());
    request.addParameter("targetService", "testDefault");
    assertTrue(this.proxyController.handleRequestInternal(request, new MockHttpServletResponse()).getModel().containsKey(CasProtocolConstants.PARAMETER_TICKET));
}
Also used : NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ProxyGrantingTicketImpl(org.apereo.cas.ticket.ProxyGrantingTicketImpl) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 7 with ProxyGrantingTicket

use of org.apereo.cas.ticket.proxy.ProxyGrantingTicket in project cas by apereo.

the class JpaTicketRegistryTests method verifyTicketCreationAndDeletion.

@Test
public void verifyTicketCreationAndDeletion() throws Exception {
    // 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);
    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);
    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)

Example 8 with ProxyGrantingTicket

use of org.apereo.cas.ticket.proxy.ProxyGrantingTicket in project cas by apereo.

the class JpaTicketRegistryTests method verifyTicketDeletionInBulk.

@Test
public void verifyTicketDeletionInBulk() {
    final TicketGrantingTicket newTgt = newTGT();
    addTicketInTransaction(newTgt);
    final TicketGrantingTicket tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
    final ServiceTicket newSt = grantServiceTicketInTransaction(tgtFromDb);
    final ServiceTicket stFromDb = (ServiceTicket) getTicketInTransaction(newSt.getId());
    final ProxyGrantingTicket newPgt = grantProxyGrantingTicketInTransaction(stFromDb);
    final ProxyGrantingTicket pgtFromDb = (ProxyGrantingTicket) getTicketInTransaction(newPgt.getId());
    final ProxyTicket newPt = grantProxyTicketInTransaction(pgtFromDb);
    getTicketInTransaction(newPt.getId());
    deleteTicketsInTransaction();
}
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)

Example 9 with ProxyGrantingTicket

use of org.apereo.cas.ticket.proxy.ProxyGrantingTicket in project cas by apereo.

the class ServiceTicketImpl method grantProxyGrantingTicket.

@Override
public ProxyGrantingTicket grantProxyGrantingTicket(final String id, final Authentication authentication, final ExpirationPolicy expirationPolicy) throws AbstractTicketException {
    synchronized (this) {
        if (this.grantedTicketAlready) {
            throw new InvalidProxyGrantingTicketForServiceTicket(this.service);
        }
        this.grantedTicketAlready = Boolean.TRUE;
    }
    final ProxyGrantingTicket pgt = new ProxyGrantingTicketImpl(id, this.service, this.getGrantingTicket(), authentication, expirationPolicy);
    getGrantingTicket().getProxyGrantingTickets().add(pgt);
    return pgt;
}
Also used : ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket)

Example 10 with ProxyGrantingTicket

use of org.apereo.cas.ticket.proxy.ProxyGrantingTicket in project cas by apereo.

the class AbstractTicketRegistry method deleteTicket.

@Override
public int deleteTicket(final String ticketId) {
    final AtomicInteger count = new AtomicInteger(0);
    if (StringUtils.isBlank(ticketId)) {
        return count.intValue();
    }
    final Ticket ticket = getTicket(ticketId);
    if (ticket == null) {
        return count.intValue();
    }
    if (ticket instanceof TicketGrantingTicket) {
        if (ticket instanceof ProxyGrantingTicket) {
            LOGGER.debug("Removing proxy-granting ticket [[{}]]", ticketId);
        }
        LOGGER.debug("Removing children of ticket [{}] from the registry.", ticket.getId());
        final TicketGrantingTicket tgt = (TicketGrantingTicket) ticket;
        count.addAndGet(deleteChildren(tgt));
        final Collection<ProxyGrantingTicket> proxyGrantingTickets = tgt.getProxyGrantingTickets();
        proxyGrantingTickets.stream().map(Ticket::getId).forEach(t -> count.addAndGet(this.deleteTicket(t)));
    }
    LOGGER.debug("Removing ticket [{}] from the registry.", ticket);
    if (deleteSingleTicket(ticketId)) {
        count.incrementAndGet();
    }
    return count.intValue();
}
Also used : ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket)

Aggregations

ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)13 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)7 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)7 Test (org.junit.Test)7 Authentication (org.apereo.cas.authentication.Authentication)5 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)5 Service (org.apereo.cas.authentication.principal.Service)4 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)3 ProxyTicket (org.apereo.cas.ticket.proxy.ProxyTicket)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Counted (com.codahale.metrics.annotation.Counted)2 Metered (com.codahale.metrics.annotation.Metered)2 Timed (com.codahale.metrics.annotation.Timed)2 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)2 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)2 RegisteredService (org.apereo.cas.services.RegisteredService)2 ProxyGrantingTicketImpl (org.apereo.cas.ticket.ProxyGrantingTicketImpl)2 Audit (org.apereo.inspektr.audit.annotation.Audit)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2