Search in sources :

Example 6 with WebApplicationService

use of org.apereo.cas.authentication.principal.WebApplicationService in project cas by apereo.

the class AbstractServiceValidateController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final WebApplicationService service = this.argumentExtractor.extractService(request);
    final String serviceTicketId = service != null ? service.getArtifactId() : null;
    if (service == null || serviceTicketId == null) {
        LOGGER.debug("Could not identify service and/or service ticket for service: [{}]", service);
        return generateErrorView(CasProtocolConstants.ERROR_CODE_INVALID_REQUEST, null, request, service);
    }
    try {
        return handleTicketValidation(request, service, serviceTicketId);
    } catch (final AbstractTicketValidationException e) {
        final String code = e.getCode();
        return generateErrorView(code, new Object[] { serviceTicketId, e.getOriginalService().getId(), service.getId() }, request, service);
    } catch (final AbstractTicketException e) {
        return generateErrorView(e.getCode(), new Object[] { serviceTicketId }, request, service);
    } catch (final UnauthorizedProxyingException e) {
        return generateErrorView(CasProtocolConstants.ERROR_CODE_UNAUTHORIZED_SERVICE_PROXY, new Object[] { service.getId() }, request, service);
    } catch (final UnauthorizedServiceException e) {
        return generateErrorView(CasProtocolConstants.ERROR_CODE_UNAUTHORIZED_SERVICE, null, request, service);
    }
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) AbstractTicketValidationException(org.apereo.cas.ticket.AbstractTicketValidationException) UnauthorizedServiceException(org.apereo.cas.services.UnauthorizedServiceException) AbstractTicketException(org.apereo.cas.ticket.AbstractTicketException) UnauthorizedProxyingException(org.apereo.cas.services.UnauthorizedProxyingException)

Example 7 with WebApplicationService

use of org.apereo.cas.authentication.principal.WebApplicationService in project cas by apereo.

the class OAuthWebApplicationServiceTests method verifySerializeACompletePrincipalToJson.

@Test
public void verifySerializeACompletePrincipalToJson() throws IOException {
    final AbstractRegisteredService service = new OAuthRegisteredService();
    service.setName("checkCloning");
    service.setServiceId("testId");
    service.setTheme("theme");
    service.setDescription("description");
    final WebApplicationServiceFactory factory = new WebApplicationServiceFactory();
    final WebApplicationService serviceWritten = factory.createService(service.getServiceId());
    MAPPER.writeValue(JSON_FILE, serviceWritten);
    final WebApplicationService serviceRead = MAPPER.readValue(JSON_FILE, WebApplicationService.class);
    assertEquals(serviceWritten, serviceRead);
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) WebApplicationServiceFactory(org.apereo.cas.authentication.principal.WebApplicationServiceFactory) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) Test(org.junit.Test)

Example 8 with WebApplicationService

use of org.apereo.cas.authentication.principal.WebApplicationService in project cas by apereo.

the class OpenIdServiceFactoryTests method verifyServiceCreationSuccessfullyById.

@Test
public void verifyServiceCreationSuccessfullyById() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(OpenIdProtocolConstants.OPENID_RETURNTO, "test");
    request.addParameter(OpenIdProtocolConstants.OPENID_IDENTITY, "identity");
    final OpenIdServiceFactory factory = new OpenIdServiceFactory("");
    final WebApplicationService service = factory.createService(request);
    assertNotNull(service);
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 9 with WebApplicationService

use of org.apereo.cas.authentication.principal.WebApplicationService in project cas by apereo.

the class OpenIdServiceFactoryTests method verifyServiceCreationMissingId.

@Test
public void verifyServiceCreationMissingId() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(OpenIdProtocolConstants.OPENID_RETURNTO, "test");
    final OpenIdServiceFactory factory = new OpenIdServiceFactory("");
    final WebApplicationService service = factory.createService(request);
    assertNull(service);
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 10 with WebApplicationService

use of org.apereo.cas.authentication.principal.WebApplicationService in project cas by apereo.

the class OpenIdServiceFactoryTests method verifyServiceCreationMissingReturn.

@Test
public void verifyServiceCreationMissingReturn() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(OpenIdProtocolConstants.OPENID_IDENTITY, "identity");
    final OpenIdServiceFactory factory = new OpenIdServiceFactory("");
    final WebApplicationService service = factory.createService(request);
    assertNull(service);
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)19 Test (org.junit.Test)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 Service (org.apereo.cas.authentication.principal.Service)4 RegisteredService (org.apereo.cas.services.RegisteredService)4 URL (java.net.URL)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 UnauthorizedServiceException (org.apereo.cas.services.UnauthorizedServiceException)3 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)2 DefaultArgumentExtractor (org.apereo.cas.web.support.DefaultArgumentExtractor)2 Throwables (com.google.common.base.Throwables)1 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1