use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.
the class DistributedTicketRegistryTests method verifyDeleteTicketWithPGT.
@Test
public void verifyDeleteTicketWithPGT() {
final Authentication a = CoreAuthenticationTestUtils.getAuthentication();
this.ticketRegistry.addTicket(new TicketGrantingTicketImpl(TGT_NAME, a, new NeverExpiresExpirationPolicy()));
final TicketGrantingTicket tgt = this.ticketRegistry.getTicket(TGT_NAME, TicketGrantingTicket.class);
final Service service = CoreAuthenticationTestUtils.getService("TGT_DELETE_TEST");
final ServiceTicket st1 = tgt.grantServiceTicket("ST1", service, new NeverExpiresExpirationPolicy(), true, true);
this.ticketRegistry.addTicket(st1);
assertNotNull(this.ticketRegistry.getTicket(TGT_NAME, TicketGrantingTicket.class));
assertNotNull(this.ticketRegistry.getTicket("ST1", ServiceTicket.class));
final ProxyGrantingTicket pgt = st1.grantProxyGrantingTicket("PGT-1", a, new NeverExpiresExpirationPolicy());
assertEquals(a, pgt.getAuthentication());
this.ticketRegistry.addTicket(pgt);
assertSame(3, this.ticketRegistry.deleteTicket(tgt.getId()));
assertNull(this.ticketRegistry.getTicket(TGT_NAME, TicketGrantingTicket.class));
assertNull(this.ticketRegistry.getTicket("ST1", ServiceTicket.class));
assertNull(this.ticketRegistry.getTicket("PGT-1", ProxyGrantingTicket.class));
}
use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.
the class TicketOrCredentialPrincipalResolverTests method verifyResolverServiceTicket.
@Test
public void verifyResolverServiceTicket() throws Exception {
final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), c);
final TicketGrantingTicket ticketId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final ServiceTicket st = getCentralAuthenticationService().grantServiceTicket(ticketId.getId(), CoreAuthenticationTestUtils.getService(), ctx);
final TicketOrCredentialPrincipalResolver res = new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService());
final JoinPoint jp = mock(JoinPoint.class);
when(jp.getArgs()).thenReturn(new Object[] { st.getId() });
final String result = res.resolveFrom(jp, null);
assertNotNull(result);
assertEquals(result, c.getId());
}
use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.
the class TicketOrCredentialPrincipalResolver method resolveArgument.
/**
* Resolve the join point argument.
*
* @param arg1 the arg
* @return the resolved string
*/
private String resolveArgument(final Object arg1) {
LOGGER.debug("Resolving argument [{}] for audit", arg1.getClass().getSimpleName());
if (arg1 instanceof AuthenticationTransaction) {
final AuthenticationTransaction transaction = AuthenticationTransaction.class.cast(arg1);
return resolveArguments(new StringBuilder(), transaction.getCredentials());
}
if (arg1 instanceof Credential) {
return arg1.toString();
}
if (arg1 instanceof String) {
try {
final Ticket ticket = this.centralAuthenticationService.getTicket((String) arg1, Ticket.class);
Authentication authentication = null;
if (ticket instanceof ServiceTicket) {
authentication = ServiceTicket.class.cast(ticket).getGrantingTicket().getAuthentication();
} else if (ticket instanceof TicketGrantingTicket) {
authentication = TicketGrantingTicket.class.cast(ticket).getAuthentication();
}
return this.principalIdProvider.getPrincipalIdFrom(authentication);
} catch (final InvalidTicketException e) {
LOGGER.trace(e.getMessage(), e);
}
LOGGER.debug("Could not locate ticket [{}] in the registry", arg1);
}
return WebUtils.getAuthenticatedUsername();
}
use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.
the class HazelcastTicketRegistryReplicationTests method basicOperationsAndClustering.
@Test
public void basicOperationsAndClustering() throws Exception {
final TicketGrantingTicket tgt = newTestTgt();
this.hzTicketRegistry1.addTicket(tgt);
assertNotNull(this.hzTicketRegistry1.getTicket(tgt.getId()));
assertNotNull(this.hzTicketRegistry2.getTicket(tgt.getId()));
assertEquals(1, this.hzTicketRegistry2.deleteTicket(tgt.getId()));
assertEquals(0, this.hzTicketRegistry1.deleteTicket(tgt.getId()));
assertNull(this.hzTicketRegistry1.getTicket(tgt.getId()));
assertNull(this.hzTicketRegistry2.getTicket(tgt.getId()));
final ServiceTicket st = newTestSt(tgt);
this.hzTicketRegistry2.addTicket(st);
assertNotNull(this.hzTicketRegistry1.getTicket("ST-TEST"));
assertNotNull(this.hzTicketRegistry2.getTicket("ST-TEST"));
assertEquals(1, this.hzTicketRegistry1.deleteTicket("ST-TEST"));
assertNull(this.hzTicketRegistry1.getTicket("ST-TEST"));
assertNull(this.hzTicketRegistry2.getTicket("ST-TEST"));
}
use of org.apereo.cas.ticket.ServiceTicket 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();
}
Aggregations