Search in sources :

Example 6 with ProxyTicket

use of org.apereo.cas.ticket.proxy.ProxyTicket 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 7 with ProxyTicket

use of org.apereo.cas.ticket.proxy.ProxyTicket in project cas by apereo.

the class ProxyController method handleRequestInternal.

/**
 * Handle request internal.
 *
 * @param request  the request
 * @param response the response
 * @return ModelAndView containing a view name of either
 * {@code casProxyFailureView} or {@code casProxySuccessView}
 */
@Override
@GetMapping(path = "/proxy")
protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) {
    final String proxyGrantingTicket = request.getParameter(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET);
    final Service targetService = getTargetService(request);
    if (!StringUtils.hasText(proxyGrantingTicket) || targetService == null) {
        return generateErrorView(CasProtocolConstants.ERROR_CODE_INVALID_REQUEST_PROXY, null, request);
    }
    try {
        final ProxyTicket proxyTicket = this.centralAuthenticationService.grantProxyTicket(proxyGrantingTicket, targetService);
        final Map model = CollectionUtils.wrap(CasProtocolConstants.PARAMETER_TICKET, proxyTicket);
        return new ModelAndView(this.successView, model);
    } catch (final AbstractTicketException e) {
        return generateErrorView(e.getCode(), new Object[] { proxyGrantingTicket }, request);
    } catch (final UnauthorizedServiceException e) {
        return generateErrorView(CasProtocolConstants.ERROR_CODE_UNAUTHORIZED_SERVICE_PROXY, new Object[] { targetService }, request);
    }
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service) UnauthorizedServiceException(org.apereo.cas.services.UnauthorizedServiceException) AbstractTicketException(org.apereo.cas.ticket.AbstractTicketException) Map(java.util.Map) ProxyTicket(org.apereo.cas.ticket.proxy.ProxyTicket) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ProxyTicket (org.apereo.cas.ticket.proxy.ProxyTicket)7 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)3 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)3 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Counted (com.codahale.metrics.annotation.Counted)1 Metered (com.codahale.metrics.annotation.Metered)1 Timed (com.codahale.metrics.annotation.Timed)1 Map (java.util.Map)1 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)1 AuditableContext (org.apereo.cas.audit.AuditableContext)1 AuditableExecutionResult (org.apereo.cas.audit.AuditableExecutionResult)1 Authentication (org.apereo.cas.authentication.Authentication)1 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)1 PrincipalException (org.apereo.cas.authentication.PrincipalException)1 MixedPrincipalException (org.apereo.cas.authentication.exceptions.MixedPrincipalException)1 Principal (org.apereo.cas.authentication.principal.Principal)1 Service (org.apereo.cas.authentication.principal.Service)1 RegisteredService (org.apereo.cas.services.RegisteredService)1