Search in sources :

Example 51 with ServiceTicket

use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.

the class DefaultServiceTicketFactoryTests method verifyCustomExpirationPolicy.

@Test
public void verifyCustomExpirationPolicy() {
    val svc = RegisteredServiceTestUtils.getRegisteredService("customExpirationPolicy", RegexRegisteredService.class);
    svc.setServiceTicketExpirationPolicy(new DefaultRegisteredServiceServiceTicketExpirationPolicy(10, "666"));
    servicesManager.save(svc);
    val factory = (ServiceTicketFactory) this.ticketFactory.get(ServiceTicket.class);
    val serviceTicket = factory.create(new MockTicketGrantingTicket("casuser"), RegisteredServiceTestUtils.getService("customExpirationPolicy"), true, ServiceTicket.class);
    assertNotNull(serviceTicket);
    assertEquals(666, serviceTicket.getExpirationPolicy().getTimeToLive());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ServiceTicketFactory(org.apereo.cas.ticket.ServiceTicketFactory) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) DefaultRegisteredServiceServiceTicketExpirationPolicy(org.apereo.cas.services.DefaultRegisteredServiceServiceTicketExpirationPolicy) Test(org.junit.jupiter.api.Test)

Example 52 with ServiceTicket

use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.

the class DefaultServiceTicketFactoryTests method verifyDefaultExpirationPolicy.

@Test
public void verifyDefaultExpirationPolicy() {
    val svc = RegisteredServiceTestUtils.getRegisteredService("defaultExpirationPolicy", RegexRegisteredService.class);
    servicesManager.save(svc);
    val factory = (ServiceTicketFactory) this.ticketFactory.get(ServiceTicket.class);
    val serviceTicket = factory.create(new MockTicketGrantingTicket("casuser"), RegisteredServiceTestUtils.getService("defaultExpirationPolicy"), true, ServiceTicket.class);
    assertNotNull(serviceTicket);
    assertEquals(10, serviceTicket.getExpirationPolicy().getTimeToLive());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ServiceTicketFactory(org.apereo.cas.ticket.ServiceTicketFactory) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Test(org.junit.jupiter.api.Test)

Example 53 with ServiceTicket

use of org.apereo.cas.ticket.ServiceTicket in project cas by apereo.

the class DistributedTicketRegistryTests method verifyProxiedInstancesEqual.

@Test
public void verifyProxiedInstancesEqual() throws Exception {
    val t = new TicketGrantingTicketImpl(TGT_ID, CoreAuthenticationTestUtils.getAuthentication(), NeverExpiresExpirationPolicy.INSTANCE);
    this.ticketRegistry.addTicket(t);
    val returned = (TicketGrantingTicket) this.ticketRegistry.getTicket(TGT_ID);
    assertEquals(t, returned);
    assertEquals(returned, t);
    assertEquals(t.getCreationTime(), returned.getCreationTime());
    assertEquals(t.getAuthentication(), returned.getAuthentication());
    assertEquals(t.getCountOfUses(), returned.getCountOfUses());
    assertEquals(t.getTicketGrantingTicket(), returned.getTicketGrantingTicket());
    assertEquals(t.getId(), returned.getId());
    assertEquals(t.getChainedAuthentications(), returned.getChainedAuthentications());
    assertEquals(t.isExpired(), returned.isExpired());
    assertEquals(t.isRoot(), returned.isRoot());
    val s = t.grantServiceTicket("stest", RegisteredServiceTestUtils.getService(), NeverExpiresExpirationPolicy.INSTANCE, false, true);
    this.ticketRegistry.addTicket(s);
    val sreturned = (ServiceTicket) this.ticketRegistry.getTicket("stest");
    assertEquals(s, sreturned);
    assertEquals(sreturned, s);
    assertEquals(s.getCreationTime(), sreturned.getCreationTime());
    assertEquals(s.getCountOfUses(), sreturned.getCountOfUses());
    assertEquals(s.getTicketGrantingTicket(), sreturned.getTicketGrantingTicket());
    assertEquals(s.getId(), sreturned.getId());
    assertEquals(s.isExpired(), sreturned.isExpired());
    assertEquals(s.getService(), sreturned.getService());
    assertEquals(((RenewableServiceTicket) s).isFromNewLogin(), ((RenewableServiceTicket) sreturned).isFromNewLogin());
}
Also used : lombok.val(lombok.val) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) RenewableServiceTicket(org.apereo.cas.ticket.RenewableServiceTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ServiceTicket (org.apereo.cas.ticket.ServiceTicket)53 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)41 Test (org.junit.Test)38 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)27 Service (org.apereo.cas.authentication.principal.Service)27 Authentication (org.apereo.cas.authentication.Authentication)16 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)14 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)14 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)12 Assertion (org.apereo.cas.validation.Assertion)11 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)10 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)9 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 Credential (org.apereo.cas.authentication.Credential)6 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)6 HashMap (java.util.HashMap)4 lombok.val (lombok.val)4 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)4 Ticket (org.apereo.cas.ticket.Ticket)3