Search in sources :

Example 26 with ServiceTicket

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

the class AbstractServiceValidateControllerTests method getModelAndViewUponServiceValidationWithSecurePgtUrl.

/*
    Helper methods.
     */
protected ModelAndView getModelAndViewUponServiceValidationWithSecurePgtUrl() 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(CasProtocolConstants.PARAMETER_SERVICE, SERVICE.getId());
    request.addParameter(CasProtocolConstants.PARAMETER_TICKET, sId.getId());
    request.addParameter(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET_URL, GITHUB_URL);
    return this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse());
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult)

Example 27 with ServiceTicket

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

the class AbstractServiceValidateControllerTests method verifyValidServiceTicketAndBadFormat.

@Test
public void verifyValidServiceTicketAndBadFormat() throws Exception {
    final Service svc = RegisteredServiceTestUtils.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(CasProtocolConstants.PARAMETER_SERVICE, svc.getId());
    request.addParameter(CasProtocolConstants.PARAMETER_TICKET, sId.getId());
    request.addParameter(CasProtocolConstants.PARAMETER_FORMAT, "NOTHING");
    final ModelAndView modelAndView = this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse());
    assertTrue(modelAndView.getView().toString().contains("Success"));
}
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 28 with ServiceTicket

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

the class AbstractServiceValidateControllerTests method verifyValidServiceTicketWithDifferentEncoding.

/*
        CAS10 Proxying Tests.
     */
@Test
public void verifyValidServiceTicketWithDifferentEncoding() throws Exception {
    final Service svc = RegisteredServiceTestUtils.getService("http://www.jasig.org?param=hello+world");
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), svc);
    final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(), svc, ctx);
    final String reqSvc = "http://www.jasig.org?param=hello%20world";
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, RegisteredServiceTestUtils.getService(reqSvc).getId());
    request.addParameter(CasProtocolConstants.PARAMETER_TICKET, sId.getId());
    this.serviceValidateController.setProxyHandler(new Cas10ProxyHandler());
    assertTrue(this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse()).getView().toString().contains(SUCCESS));
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Service(org.apereo.cas.authentication.principal.Service) 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 29 with ServiceTicket

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

the class AbstractServiceValidateControllerTests method verifyInvalidServiceTicket.

@Test
public void verifyInvalidServiceTicket() throws Exception {
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), SERVICE);
    final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(), SERVICE, ctx);
    getCentralAuthenticationService().destroyTicketGrantingTicket(tId.getId());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, SERVICE.getId());
    request.addParameter(CasProtocolConstants.PARAMETER_TICKET, sId.getId());
    assertFalse(this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse()).getView().toString().contains(SUCCESS));
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) Test(org.junit.Test)

Example 30 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 = RegisteredServiceTestUtils.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(CasProtocolConstants.PARAMETER_SERVICE, svc.getId());
    request.addParameter(CasProtocolConstants.PARAMETER_TICKET, sId.getId());
    request.addParameter(CasProtocolConstants.PARAMETER_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)

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