Search in sources :

Example 21 with ServiceTicket

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

the class TicketsResourceTests method configureCasMockToCreateValidST.

private void configureCasMockToCreateValidST() throws Throwable {
    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 22 with ServiceTicket

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

the class AbstractServiceValidateController method handleProxyGrantingTicketDelivery.

/**
     * Handle proxy granting ticket delivery.
     *
     * @param serviceTicketId the service ticket id
     * @param credential the service credential
     * @return the ticket granting ticket
     */
private TicketGrantingTicket handleProxyGrantingTicketDelivery(final String serviceTicketId, final Credential credential) throws AuthenticationException, AbstractTicketException {
    final ServiceTicket serviceTicket = this.centralAuthenticationService.getTicket(serviceTicketId, ServiceTicket.class);
    final AuthenticationResult authenticationResult = this.authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(serviceTicket.getService(), credential);
    final TicketGrantingTicket proxyGrantingTicketId = this.centralAuthenticationService.createProxyGrantingTicket(serviceTicketId, authenticationResult);
    LOGGER.debug("Generated proxy-granting ticket [[{}]] off of service ticket [{}] and credential [{}]", proxyGrantingTicketId.getId(), serviceTicketId, credential);
    return proxyGrantingTicketId;
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult)

Example 23 with ServiceTicket

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

the class AbstractServiceValidateControllerTests method verifyValidServiceTicketAndFormatAsJson.

@Test
public void verifyValidServiceTicketAndFormatAsJson() throws Exception {
    final Service svc = CoreAuthenticationTestUtils.getService("proxyService");
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), svc);
    final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(), svc, ctx);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(SERVICE_PARAM, svc.getId());
    request.addParameter(TICKET_PARAM, sId.getId());
    request.addParameter("format", ValidationResponseType.JSON.name());
    final ModelAndView modelAndView = this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse());
    assertTrue(modelAndView.getView().toString().contains("Json"));
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 24 with ServiceTicket

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

the class AbstractServiceValidateControllerTests method verifyValidServiceTicketWithInvalidPgt.

@Test
public void verifyValidServiceTicketWithInvalidPgt() throws Exception {
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), SERVICE);
    this.serviceValidateController.setProxyHandler(new Cas10ProxyHandler());
    final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(), SERVICE, ctx);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(SERVICE_PARAM, SERVICE.getId());
    request.addParameter(TICKET_PARAM, sId.getId());
    request.addParameter(PGT_URL_PARAM, "duh");
    final ModelAndView modelAndView = this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse());
    assertTrue(modelAndView.getView().toString().contains(SUCCESS));
    assertNull(modelAndView.getModel().get(PGT_IOU_PARAM));
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) Cas10ProxyHandler(org.apereo.cas.ticket.proxy.support.Cas10ProxyHandler) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 25 with ServiceTicket

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

the class AbstractServiceValidateControllerTests method verifyValidServiceTicketWithValidPgtAndProxyHandlerFailing.

@Test
public void verifyValidServiceTicketWithValidPgtAndProxyHandlerFailing() throws Exception {
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), SERVICE);
    final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(), SERVICE, ctx);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(SERVICE_PARAM, SERVICE.getId());
    request.addParameter(TICKET_PARAM, sId.getId());
    request.addParameter(PGT_URL_PARAM, GITHUB_URL);
    this.serviceValidateController.setProxyHandler(new ProxyHandler() {

        @Override
        public String handle(final Credential credential, final TicketGrantingTicket proxyGrantingTicketId) {
            return null;
        }

        @Override
        public boolean canHandle(final Credential credential) {
            return true;
        }
    });
    final ModelAndView modelAndView = this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse());
    assertFalse(modelAndView.getView().toString().contains(SUCCESS));
    assertNull(modelAndView.getModel().get(PGT_IOU_PARAM));
}
Also used : Credential(org.apereo.cas.authentication.Credential) ProxyHandler(org.apereo.cas.ticket.proxy.ProxyHandler) Cas10ProxyHandler(org.apereo.cas.ticket.proxy.support.Cas10ProxyHandler) Cas20ProxyHandler(org.apereo.cas.ticket.proxy.support.Cas20ProxyHandler) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Aggregations

ServiceTicket (org.apereo.cas.ticket.ServiceTicket)70 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)59 Test (org.junit.Test)53 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)45 Service (org.apereo.cas.authentication.principal.Service)32 Authentication (org.apereo.cas.authentication.Authentication)17 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)14 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)12 Assertion (org.apereo.cas.validation.Assertion)12 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)12 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)10 NeverExpiresExpirationPolicy (org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 Credential (org.apereo.cas.authentication.Credential)9 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)8 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)8 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 RegisteredService (org.apereo.cas.services.RegisteredService)6 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)6