Search in sources :

Example 36 with ServiceTicket

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));
}
Also used : NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) Authentication(org.apereo.cas.authentication.Authentication) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Service(org.apereo.cas.authentication.principal.Service) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) Test(org.junit.Test)

Example 37 with ServiceTicket

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());
}
Also used : Credential(org.apereo.cas.authentication.Credential) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.junit.Test)

Example 38 with ServiceTicket

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();
}
Also used : ServiceTicket(org.apereo.cas.ticket.ServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) Credential(org.apereo.cas.authentication.Credential) Authentication(org.apereo.cas.authentication.Authentication) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationTransaction(org.apereo.cas.authentication.AuthenticationTransaction)

Example 39 with ServiceTicket

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"));
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 40 with ServiceTicket

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();
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) ProxyTicket(org.apereo.cas.ticket.proxy.ProxyTicket) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

ServiceTicket (org.apereo.cas.ticket.ServiceTicket)79 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)65 Test (org.junit.Test)59 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)49 Service (org.apereo.cas.authentication.principal.Service)38 Authentication (org.apereo.cas.authentication.Authentication)22 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)15 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)14 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)14 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)14 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)13 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)13 Assertion (org.apereo.cas.validation.Assertion)13 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 Credential (org.apereo.cas.authentication.Credential)10 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)8 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)8 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)7 RegisteredService (org.apereo.cas.services.RegisteredService)7