use of org.apereo.cas.ticket.TicketGrantingTicket in project cas by apereo.
the class DistributedTicketRegistryTests method verifyUpdateOfRegistry.
@Test
public void verifyUpdateOfRegistry() throws AbstractTicketException {
final TicketGrantingTicket t = new TicketGrantingTicketImpl(TGT_ID, CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
this.ticketRegistry.addTicket(t);
final TicketGrantingTicket returned = (TicketGrantingTicket) this.ticketRegistry.getTicket(TGT_ID);
final ServiceTicket s = returned.grantServiceTicket("test2", RegisteredServiceTestUtils.getService(), new NeverExpiresExpirationPolicy(), false, true);
this.ticketRegistry.addTicket(s);
final ServiceTicket s2 = (ServiceTicket) this.ticketRegistry.getTicket("test2");
assertNotNull(s2.grantProxyGrantingTicket("ff", CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()));
assertTrue(s2.isValidFor(RegisteredServiceTestUtils.getService()));
assertTrue(this.wasTicketUpdated);
returned.markTicketExpired();
assertTrue(t.isExpired());
}
use of org.apereo.cas.ticket.TicketGrantingTicket 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.TicketGrantingTicket 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.TicketGrantingTicket 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.TicketGrantingTicket in project cas by apereo.
the class HazelcastTicketRegistryReplicationTests method retrieveCollectionOfTickets.
@Test
public void retrieveCollectionOfTickets() {
Collection<Ticket> col = this.hzTicketRegistry1.getTickets();
col.forEach(ticket -> this.hzTicketRegistry1.deleteTicket(ticket.getId()));
col = hzTicketRegistry2.getTickets();
assertEquals(0, col.size());
final TicketGrantingTicket tgt = newTestTgt();
this.hzTicketRegistry1.addTicket(tgt);
this.hzTicketRegistry1.addTicket(newTestSt(tgt));
col = hzTicketRegistry2.getTickets();
assertEquals(2, col.size());
assertEquals(1, hzTicketRegistry2.serviceTicketCount());
assertEquals(1, hzTicketRegistry2.sessionCount());
}
Aggregations