use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeTGTImpl.
@Test
public void verifyEncodeDecodeTGTImpl() {
final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
final AuthenticationBuilder bldr = new DefaultAuthenticationBuilder(new DefaultPrincipalFactory().createPrincipal("user", new HashMap<>(this.principalAttributes)));
bldr.setAttributes(new HashMap<>(this.principalAttributes));
bldr.setAuthenticationDate(ZonedDateTime.now());
bldr.addCredential(new BasicCredentialMetaData(userPassCredential));
bldr.addFailure("error", new AccountNotFoundException());
bldr.addSuccess("authn", new DefaultAuthenticationHandlerExecutionResult(new AcceptUsersAuthenticationHandler(""), new BasicCredentialMetaData(userPassCredential)));
final TicketGrantingTicket expectedTGT = new TicketGrantingTicketImpl(TGT_ID, RegisteredServiceTestUtils.getService(), null, bldr.build(), new NeverExpiresExpirationPolicy());
final ServiceTicket ticket = expectedTGT.grantServiceTicket(ST_ID, RegisteredServiceTestUtils.getService(), new NeverExpiresExpirationPolicy(), false, true);
CachedData result = transcoder.encode(expectedTGT);
final TicketGrantingTicket resultTicket = (TicketGrantingTicket) transcoder.decode(result);
assertEquals(expectedTGT, resultTicket);
result = transcoder.encode(ticket);
ServiceTicket resultStTicket = (ServiceTicket) transcoder.decode(result);
assertEquals(ticket, resultStTicket);
resultStTicket = (ServiceTicket) transcoder.decode(result);
assertEquals(ticket, resultStTicket);
}
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 ServiceTicketResourceTests method configureCasMockToCreateValidST.
private void configureCasMockToCreateValidST() {
final ServiceTicket st = mock(ServiceTicket.class);
when(st.getId()).thenReturn("ST-1");
when(this.casMock.grantServiceTicket(anyString(), any(Service.class), any(AuthenticationResult.class))).thenReturn(st);
}
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()));
}
use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.
the class AbstractServiceValidateControllerTests method getHttpServletRequest.
protected HttpServletRequest getHttpServletRequest() {
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), SERVICE);
final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
getCentralAuthenticationService().grantServiceTicket(tId.getId(), SERVICE, ctx);
final ServiceTicket sId2 = getCentralAuthenticationService().grantServiceTicket(tId.getId(), SERVICE, null);
final MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, SERVICE.getId());
request.addParameter(CasProtocolConstants.PARAMETER_TICKET, sId2.getId());
request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");
return request;
}
Aggregations