Search in sources :

Example 71 with ServiceTicket

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

the class CasKryoTranscoderTests method verifyEncodeDecodeTGTImpl.

@Test
public void verifyEncodeDecodeTGTImpl() {
    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", new AccountNotFoundException());
    bldr.addSuccess("authn", new DefaultAuthenticationHandlerExecutionResult(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);
    ServiceTicket resultStTicket = (ServiceTicket) transcoder.decode(result);
    assertEquals(ticket, resultStTicket);
    resultStTicket = (ServiceTicket) transcoder.decode(result);
    assertEquals(ticket, resultStTicket);
}
Also used : DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) AuthenticationBuilder(org.apereo.cas.authentication.AuthenticationBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) CachedData(net.spy.memcached.CachedData) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) AcceptUsersAuthenticationHandler(org.apereo.cas.authentication.AcceptUsersAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) Test(org.junit.Test)

Example 72 with ServiceTicket

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

the class StatisticsController method getTicketStats.

/**
 * Gets ticket stats.
 *
 * @param request  the http servlet request
 * @param response the http servlet response
 * @return the ticket stats
 */
@GetMapping(value = "/getTicketStats")
@ResponseBody
public Map<String, Object> getTicketStats(final HttpServletRequest request, final HttpServletResponse response) {
    ensureEndpointAccessIsAuthorized(request, response);
    final Map<String, Object> model = new HashMap<>();
    int unexpiredTgts = 0;
    int unexpiredSts = 0;
    int expiredTgts = 0;
    int expiredSts = 0;
    final Collection<Ticket> tickets = this.centralAuthenticationService.getTickets(ticket -> true);
    for (final Ticket ticket : tickets) {
        if (ticket instanceof ServiceTicket) {
            if (ticket.isExpired()) {
                this.centralAuthenticationService.deleteTicket(ticket.getId());
                expiredSts++;
            } else {
                unexpiredSts++;
            }
        } else {
            if (ticket.isExpired()) {
                this.centralAuthenticationService.deleteTicket(ticket.getId());
                expiredTgts++;
            } else {
                unexpiredTgts++;
            }
        }
    }
    model.put("unexpiredTgts", unexpiredTgts);
    model.put("unexpiredSts", unexpiredSts);
    model.put("expiredTgts", expiredTgts);
    model.put("expiredSts", expiredSts);
    return model;
}
Also used : ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Ticket(org.apereo.cas.ticket.Ticket) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) BaseCasMvcEndpoint(org.apereo.cas.web.BaseCasMvcEndpoint) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 73 with ServiceTicket

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

the class ServiceTicketResourceTests method configureCasMockToCreateValidST.

private void configureCasMockToCreateValidST() {
    final ServiceTicket st = mock(ServiceTicket.class);
    when(st.getId()).thenReturn("ST-1");
    when(this.casMock.grantServiceTicket(anyString(), any(Service.class), any(AuthenticationResult.class))).thenReturn(st);
}
Also used : CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult)

Example 74 with ServiceTicket

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

the class JpaTicketRegistryTests method verifyTicketCreationAndDeletion.

@Test
public void verifyTicketCreationAndDeletion() {
    // TGT
    final TicketGrantingTicket newTgt = newTGT();
    addTicketInTransaction(newTgt);
    TicketGrantingTicket tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
    assertNotNull(tgtFromDb);
    assertEquals(newTgt.getId(), tgtFromDb.getId());
    // ST
    final ServiceTicket newSt = grantServiceTicketInTransaction(tgtFromDb);
    final ServiceTicket stFromDb = (ServiceTicket) getTicketInTransaction(newSt.getId());
    assertNotNull(stFromDb);
    assertEquals(newSt.getId(), stFromDb.getId());
    // PGT
    final ProxyGrantingTicket newPgt = grantProxyGrantingTicketInTransaction(stFromDb);
    updateTicketInTransaction(stFromDb.getTicketGrantingTicket());
    final ProxyGrantingTicket pgtFromDb = (ProxyGrantingTicket) getTicketInTransaction(newPgt.getId());
    assertNotNull(pgtFromDb);
    assertEquals(newPgt.getId(), pgtFromDb.getId());
    tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
    assertNotNull(tgtFromDb);
    assertEquals(1, tgtFromDb.getProxyGrantingTickets().size());
    // PT
    final ProxyTicket newPt = grantProxyTicketInTransaction(pgtFromDb);
    final ProxyTicket ptFromDb = (ProxyTicket) getTicketInTransaction(newPt.getId());
    assertNotNull(ptFromDb);
    assertEquals(newPt.getId(), ptFromDb.getId());
    // ST 2
    final ServiceTicket newSt2 = grantServiceTicketInTransaction(tgtFromDb);
    final ServiceTicket st2FromDb = (ServiceTicket) getTicketInTransaction(newSt2.getId());
    assertNotNull(st2FromDb);
    assertEquals(newSt2.getId(), st2FromDb.getId());
    // PGT 2
    final ProxyGrantingTicket newPgt2 = grantProxyGrantingTicketInTransaction(st2FromDb);
    updateTicketInTransaction(st2FromDb.getTicketGrantingTicket());
    final ProxyGrantingTicket pgt2FromDb = (ProxyGrantingTicket) getTicketInTransaction(newPgt2.getId());
    assertNotNull(pgt2FromDb);
    assertEquals(newPgt2.getId(), pgt2FromDb.getId());
    tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
    assertNotNull(tgtFromDb);
    assertEquals(2, tgtFromDb.getProxyGrantingTickets().size());
    // delete PGT 2
    deleteTicketInTransaction(pgt2FromDb.getId());
    assertNull(getTicketInTransaction(newPgt2.getId()));
    tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
    assertNotNull(tgtFromDb);
    assertEquals(1, tgtFromDb.getProxyGrantingTickets().size());
    // delete ticket hierarchy
    tgtFromDb = (TicketGrantingTicket) getTicketInTransaction(newTgt.getId());
    assertNotNull(tgtFromDb);
    deleteTicketInTransaction(tgtFromDb.getId());
    assertNull(getTicketInTransaction(newTgt.getId()));
    assertNull(getTicketInTransaction(newSt.getId()));
    assertNull(getTicketInTransaction(newPgt.getId()));
    assertNull(getTicketInTransaction(newPt.getId()));
}
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)

Example 75 with ServiceTicket

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

the class AbstractServiceValidateControllerTests method getHttpServletRequest.

protected HttpServletRequest getHttpServletRequest() {
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), SERVICE);
    final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    getCentralAuthenticationService().grantServiceTicket(tId.getId(), SERVICE, ctx);
    final ServiceTicket sId2 = getCentralAuthenticationService().grantServiceTicket(tId.getId(), SERVICE, null);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, SERVICE.getId());
    request.addParameter(CasProtocolConstants.PARAMETER_TICKET, sId2.getId());
    request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");
    return request;
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult)

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