use of org.apereo.cas.ticket.TicketGrantingTicketImpl in project cas by apereo.
the class SessionMonitorJpaTests method addTicketsToRegistry.
private static void addTicketsToRegistry(final TicketRegistry registry, final int tgtCount, final int stCount) {
TicketGrantingTicketImpl ticket = null;
for (int i = 0; i < tgtCount; i++) {
ticket = new TicketGrantingTicketImpl(GENERATOR.getNewTicketId("TGT"), CoreAuthenticationTestUtils.getAuthentication(), TEST_EXP_POLICY);
registry.addTicket(ticket);
}
if (ticket != null) {
for (int i = 0; i < stCount; i++) {
registry.addTicket(ticket.grantServiceTicket(GENERATOR.getNewTicketId("ST"), new MockService("junit"), TEST_EXP_POLICY, false, true));
}
}
}
use of org.apereo.cas.ticket.TicketGrantingTicketImpl in project cas by apereo.
the class HazelcastTicketRegistryReplicationTests method verifyDeleteTicketWithPGT.
@Test
public void verifyDeleteTicketWithPGT() {
final Authentication a = CoreAuthenticationTestUtils.getAuthentication();
this.hzTicketRegistry1.addTicket(new TicketGrantingTicketImpl(TGT_ID, a, new NeverExpiresExpirationPolicy()));
final TicketGrantingTicket tgt = this.hzTicketRegistry1.getTicket(TGT_ID, TicketGrantingTicket.class);
final Service service = RegisteredServiceTestUtils.getService("TGT_DELETE_TEST");
final ServiceTicket st1 = tgt.grantServiceTicket(ST_ID_1, service, new NeverExpiresExpirationPolicy(), false, true);
this.hzTicketRegistry1.addTicket(st1);
assertNotNull(this.hzTicketRegistry1.getTicket(TGT_ID, TicketGrantingTicket.class));
assertNotNull(this.hzTicketRegistry1.getTicket(ST_ID_1, ServiceTicket.class));
final ProxyGrantingTicket pgt = st1.grantProxyGrantingTicket(PGT_ID_1, a, new NeverExpiresExpirationPolicy());
assertEquals(a, pgt.getAuthentication());
this.hzTicketRegistry1.addTicket(pgt);
this.hzTicketRegistry1.updateTicket(tgt);
assertSame(3, this.hzTicketRegistry1.deleteTicket(tgt.getId()));
assertNull(this.hzTicketRegistry1.getTicket(TGT_ID, TicketGrantingTicket.class));
assertNull(this.hzTicketRegistry1.getTicket(ST_ID_1, ServiceTicket.class));
assertNull(this.hzTicketRegistry1.getTicket(PGT_ID_1, ProxyGrantingTicket.class));
}
use of org.apereo.cas.ticket.TicketGrantingTicketImpl in project cas by apereo.
the class HazelcastTicketRegistryReplicationTests method verifyDeleteTicketWithChildren.
@Test
public void verifyDeleteTicketWithChildren() throws Exception {
this.hzTicketRegistry1.addTicket(new TicketGrantingTicketImpl(TGT_ID, CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()));
final TicketGrantingTicket tgt = this.hzTicketRegistry1.getTicket(TGT_ID, TicketGrantingTicket.class);
final Service service = RegisteredServiceTestUtils.getService("TGT_DELETE_TEST");
final ServiceTicket st1 = tgt.grantServiceTicket(ST_ID_1, service, new NeverExpiresExpirationPolicy(), false, false);
final ServiceTicket st2 = tgt.grantServiceTicket("ST2", service, new NeverExpiresExpirationPolicy(), false, false);
final ServiceTicket st3 = tgt.grantServiceTicket("ST3", service, new NeverExpiresExpirationPolicy(), false, false);
this.hzTicketRegistry1.addTicket(st1);
this.hzTicketRegistry1.addTicket(st2);
this.hzTicketRegistry1.addTicket(st3);
this.hzTicketRegistry1.updateTicket(tgt);
assertNotNull(this.hzTicketRegistry1.getTicket(tgt.getId(), TicketGrantingTicket.class));
assertNotNull(this.hzTicketRegistry1.getTicket(ST_ID_1, ServiceTicket.class));
assertNotNull(this.hzTicketRegistry1.getTicket("ST2", ServiceTicket.class));
assertNotNull(this.hzTicketRegistry1.getTicket("ST3", ServiceTicket.class));
assertTrue("TGT and children were deleted", this.hzTicketRegistry1.deleteTicket(tgt.getId()) > 0);
assertNull(this.hzTicketRegistry1.getTicket(tgt.getId(), TicketGrantingTicket.class));
assertNull(this.hzTicketRegistry1.getTicket(ST_ID_1, ServiceTicket.class));
assertNull(this.hzTicketRegistry1.getTicket("ST2", ServiceTicket.class));
assertNull(this.hzTicketRegistry1.getTicket("ST3", ServiceTicket.class));
}
use of org.apereo.cas.ticket.TicketGrantingTicketImpl in project cas by apereo.
the class MemCacheTicketRegistryTests method verifyDeleteTicketWithChildren.
@Test
public void verifyDeleteTicketWithChildren() throws Exception {
this.registry.addTicket(new TicketGrantingTicketImpl(TGT_ID, CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()));
final TicketGrantingTicket tgt = this.registry.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, false);
final ServiceTicket st2 = tgt.grantServiceTicket("ST2", service, new NeverExpiresExpirationPolicy(), false, false);
final ServiceTicket st3 = tgt.grantServiceTicket("ST3", service, new NeverExpiresExpirationPolicy(), false, false);
this.registry.addTicket(st1);
this.registry.addTicket(st2);
this.registry.addTicket(st3);
this.registry.updateTicket(tgt);
assertNotNull(this.registry.getTicket(TGT_ID, TicketGrantingTicket.class));
assertNotNull(this.registry.getTicket(ST_1_ID, ServiceTicket.class));
assertNotNull(this.registry.getTicket("ST2", ServiceTicket.class));
assertNotNull(this.registry.getTicket("ST3", ServiceTicket.class));
this.registry.deleteTicket(tgt.getId());
assertNull(this.registry.getTicket(TGT_ID, TicketGrantingTicket.class));
assertNull(this.registry.getTicket(ST_1_ID, ServiceTicket.class));
assertNull(this.registry.getTicket("ST2", ServiceTicket.class));
assertNull(this.registry.getTicket("ST3", ServiceTicket.class));
}
use of org.apereo.cas.ticket.TicketGrantingTicketImpl in project cas by apereo.
the class KryoTranscoderTests method verifyEncodeDecodeTGTImpl.
@Test
public void verifyEncodeDecodeTGTImpl() throws Exception {
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", AccountNotFoundException.class);
bldr.addSuccess("authn", new DefaultHandlerResult(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);
final ServiceTicket resultStTicket = (ServiceTicket) transcoder.decode(result);
assertEquals(ticket, resultStTicket);
}
Aggregations