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));
}
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()));
}
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();
}
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;
}
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();
}
Aggregations