Search in sources :

Example 16 with WebApplicationService

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

the class DefaultSingleLogoutServiceMessageHandler method handle.

/**
     * Handle logout for slo service.
     *
     * @param singleLogoutService the service
     * @param ticketId            the ticket id
     * @return the logout request
     */
@Override
public LogoutRequest handle(final WebApplicationService singleLogoutService, final String ticketId) {
    if (!singleLogoutService.isLoggedOutAlready()) {
        final WebApplicationService selectedService = WebApplicationService.class.cast(this.authenticationRequestServiceSelectionStrategies.resolveService(singleLogoutService));
        LOGGER.debug("Processing logout request for service [{}]", selectedService);
        final RegisteredService registeredService = this.servicesManager.findServiceBy(selectedService);
        if (serviceSupportsSingleLogout(registeredService)) {
            LOGGER.debug("Service [{}] supports single logout and is found in the registry as [{}]. Proceeding...", selectedService, registeredService);
            final URL logoutUrl = this.singleLogoutServiceLogoutUrlBuilder.determineLogoutUrl(registeredService, selectedService);
            LOGGER.debug("Prepared logout url [{}] for service [{}]", logoutUrl, selectedService);
            final DefaultLogoutRequest logoutRequest = new DefaultLogoutRequest(ticketId, selectedService, logoutUrl);
            LOGGER.debug("Logout request [{}] created for [{}] and ticket id [{}]", logoutRequest, selectedService, ticketId);
            final LogoutType type = registeredService.getLogoutType() == null ? LogoutType.BACK_CHANNEL : registeredService.getLogoutType();
            LOGGER.debug("Logout type registered for [{}] is [{}]", selectedService, type);
            switch(type) {
                case BACK_CHANNEL:
                    if (performBackChannelLogout(logoutRequest)) {
                        logoutRequest.setStatus(LogoutRequestStatus.SUCCESS);
                    } else {
                        logoutRequest.setStatus(LogoutRequestStatus.FAILURE);
                        LOGGER.warn("Logout message not sent to [{}]; Continuing processing...", singleLogoutService.getId());
                    }
                    break;
                default:
                    logoutRequest.setStatus(LogoutRequestStatus.NOT_ATTEMPTED);
                    break;
            }
            return logoutRequest;
        }
    }
    return null;
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) RegisteredService(org.apereo.cas.services.RegisteredService) LogoutType(org.apereo.cas.services.LogoutType) URL(java.net.URL)

Example 17 with WebApplicationService

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

the class SamlCompliantLogoutMessageCreatorTests method verifyMessageBuilding.

@Test
public void verifyMessageBuilding() throws Exception {
    final WebApplicationService service = mock(WebApplicationService.class);
    when(service.getOriginalUrl()).thenReturn(RegisteredServiceTestUtils.CONST_TEST_URL);
    final URL logoutUrl = new URL(service.getOriginalUrl());
    final DefaultLogoutRequest request = new DefaultLogoutRequest("TICKET-ID", service, logoutUrl);
    final String msg = builder.create(request);
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder builder = factory.newDocumentBuilder();
    final InputStream is = new ByteArrayInputStream(msg.getBytes());
    final Document document = builder.parse(is);
    final NodeList list = document.getDocumentElement().getElementsByTagName("samlp:SessionIndex");
    assertEquals(list.getLength(), 1);
    assertEquals(list.item(0).getTextContent(), request.getTicketId());
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) URL(java.net.URL) Test(org.junit.Test)

Example 18 with WebApplicationService

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

the class SamlMetadataUIParserAction method doExecute.

@Override
public Event doExecute(final RequestContext requestContext) throws Exception {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
    final String entityId = request.getParameter(this.entityIdParameterName);
    if (StringUtils.isBlank(entityId)) {
        LOGGER.debug("No entity id found for parameter [{}]", this.entityIdParameterName);
        return success();
    }
    final WebApplicationService service = this.serviceFactory.createService(entityId);
    final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
    if (registeredService == null || !registeredService.getAccessStrategy().isServiceAccessAllowed()) {
        LOGGER.debug("Entity id [{}] is not recognized/allowed by the CAS service registry", entityId);
        if (registeredService != null) {
            WebUtils.putUnauthorizedRedirectUrlIntoFlowScope(requestContext, registeredService.getAccessStrategy().getUnauthorizedRedirectUrl());
        }
        throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, "Entity [" + entityId + "] not recognized");
    }
    final SamlMetadataUIInfo mdui = MetadataUIUtils.locateMetadataUserInterfaceForEntityId(this.metadataAdapter, entityId, registeredService);
    WebUtils.putServiceUserInterfaceMetadata(requestContext, mdui);
    return success();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) RegisteredService(org.apereo.cas.services.RegisteredService) SamlMetadataUIInfo(org.apereo.cas.support.saml.mdui.SamlMetadataUIInfo) UnauthorizedServiceException(org.apereo.cas.services.UnauthorizedServiceException)

Example 19 with WebApplicationService

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

the class RedirectToServiceAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    final WebApplicationService service = WebUtils.getService(requestContext);
    final String serviceTicketId = WebUtils.getServiceTicketFromRequestScope(requestContext);
    final Response response = responseBuilderLocator.locate(service).build(service, serviceTicketId);
    WebUtils.putServiceResponseIntoRequestScope(requestContext, response);
    WebUtils.putServiceOriginalUrlIntoRequestScope(requestContext, service);
    return new EventFactorySupport().event(this, response.getResponseType().name().toLowerCase());
}
Also used : Response(org.apereo.cas.authentication.principal.Response) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

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