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