Search in sources :

Example 1 with WebApplicationService

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

the class DefaultSingleLogoutServiceMessageHandler method performBackChannelLogout.

/**
     * Log out of a service through back channel.
     *
     * @param request the logout request.
     * @return if the logout has been performed.
     */
public boolean performBackChannelLogout(final LogoutRequest request) {
    try {
        final String logoutRequest = this.logoutMessageBuilder.create(request);
        final WebApplicationService logoutService = request.getService();
        logoutService.setLoggedOutAlready(true);
        LOGGER.debug("Sending logout request for [{}] to [{}]", logoutService.getId(), request.getLogoutUrl());
        final LogoutHttpMessage msg = new LogoutHttpMessage(request.getLogoutUrl(), logoutRequest, this.asynchronous);
        LOGGER.debug("Prepared logout message to send is [{}]", msg);
        return this.httpClient.sendMessageToEndPoint(msg);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return false;
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService)

Example 2 with WebApplicationService

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

the class LogoutManagerImpl method performLogoutForTicket.

private void performLogoutForTicket(final TicketGrantingTicket ticket, final List<LogoutRequest> logoutRequests) {
    ticket.getServices().entrySet().stream().filter(entry -> entry.getValue() instanceof WebApplicationService).forEach(entry -> {
        final Service service = entry.getValue();
        LOGGER.debug("Handling single logout callback for [{}]", service);
        final LogoutRequest logoutRequest = this.singleLogoutServiceMessageHandler.handle((WebApplicationService) service, entry.getKey());
        if (logoutRequest != null) {
            LOGGER.debug("Captured logout request [{}]", logoutRequest);
            logoutRequests.add(logoutRequest);
        }
    });
    final Collection<ProxyGrantingTicket> proxyGrantingTickets = ticket.getProxyGrantingTickets();
    if (proxyGrantingTickets.isEmpty()) {
        LOGGER.debug("There are no proxy-granting tickets associated with [{}] to process for single logout", ticket.getId());
    } else {
        proxyGrantingTickets.forEach(proxyGrantingTicket -> performLogoutForTicket(proxyGrantingTicket, logoutRequests));
    }
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) List(java.util.List) Logger(org.slf4j.Logger) Service(org.apereo.cas.authentication.principal.Service) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) CompressionUtils(org.apereo.cas.util.CompressionUtils) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Collections(java.util.Collections) ArrayList(java.util.ArrayList) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Service(org.apereo.cas.authentication.principal.Service) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket)

Example 3 with WebApplicationService

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

the class SendTicketGrantingTicketActionTests method verifySsoSessionCookieOnServiceSsoDisallowed.

@Test
public void verifySsoSessionCookieOnServiceSsoDisallowed() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final WebApplicationService svc = mock(WebApplicationService.class);
    when(svc.getId()).thenReturn("TestSsoFalse");
    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn(TEST_STRING);
    request.setCookies(new Cookie("TGT", "test5"));
    WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    this.context.getFlowScope().put("service", svc);
    final SendTicketGrantingTicketAction action = new SendTicketGrantingTicketAction(centralAuthenticationService, servicesManager, ticketGrantingTicketCookieGenerator, false);
    assertEquals(SUCCESS, action.execute(this.context).getId());
    assertEquals(0, response.getCookies().length);
}
Also used : Cookie(javax.servlet.http.Cookie) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 4 with WebApplicationService

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

the class DelegatedClientAuthenticationAction method prepareForLoginPage.

/**
     * Prepare the data for the login page.
     *
     * @param context The current webflow context
     * @throws HttpAction the http action
     */
protected void prepareForLoginPage(final RequestContext context) throws HttpAction {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final HttpServletResponse response = WebUtils.getHttpServletResponse(context);
    final HttpSession session = request.getSession();
    // web context
    final WebContext webContext = WebUtils.getPac4jJ2EContext(request, response);
    // save parameters in web session
    final WebApplicationService service = WebUtils.getService(context);
    LOGGER.debug("save service: [{}]", service);
    session.setAttribute(CasProtocolConstants.PARAMETER_SERVICE, service);
    saveRequestParameter(request, session, this.themeParamName);
    saveRequestParameter(request, session, this.localParamName);
    saveRequestParameter(request, session, CasProtocolConstants.PARAMETER_METHOD);
    final Set<ProviderLoginPageConfiguration> urls = new LinkedHashSet<>();
    this.clients.findAllClients().forEach(client -> {
        try {
            final IndirectClient indirectClient = (IndirectClient) client;
            final String name = client.getName().replaceAll("Client\\d*", "");
            final String redirectionUrl = indirectClient.getRedirectAction(webContext).getLocation();
            LOGGER.debug("[{}] -> [{}]", name, redirectionUrl);
            urls.add(new ProviderLoginPageConfiguration(name, redirectionUrl, name.toLowerCase()));
        } catch (final HttpAction e) {
            if (e.getCode() == HttpStatus.UNAUTHORIZED.value()) {
                LOGGER.debug("Authentication request was denied from the provider [{}]", client.getName());
            } else {
                LOGGER.warn(e.getMessage(), e);
            }
        } catch (final Exception e) {
            LOGGER.error("Cannot process client [{}]", client, e);
        }
    });
    if (!urls.isEmpty()) {
        context.getFlowScope().put(PAC4J_URLS, urls);
    } else if (response.getStatus() != HttpStatus.UNAUTHORIZED.value()) {
        LOGGER.warn("No clients could be determined based on the provided configuration");
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) LinkedHashSet(java.util.LinkedHashSet) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) WebContext(org.pac4j.core.context.WebContext) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) IndirectClient(org.pac4j.core.client.IndirectClient) HttpAction(org.pac4j.core.exception.HttpAction)

Example 5 with WebApplicationService

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

the class OAuth20Validator method checkServiceValid.

/**
     * Check if the service is valid.
     *
     * @param registeredService the registered service
     * @return whether the service is valid
     */
public boolean checkServiceValid(final RegisteredService registeredService) {
    if (registeredService == null) {
        return false;
    }
    final WebApplicationService service = webApplicationServiceServiceFactory.createService(registeredService.getServiceId());
    LOGGER.debug("Check registered service: [{}]", registeredService);
    try {
        RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service, registeredService);
        return true;
    } catch (final UnauthorizedServiceException e) {
        return false;
    }
}
Also used : WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) UnauthorizedServiceException(org.apereo.cas.services.UnauthorizedServiceException)

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