Search in sources :

Example 76 with RegisteredService

use of org.apereo.cas.services.RegisteredService in project cas by apereo.

the class GenericSuccessViewAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    if (StringUtils.isNotBlank(this.redirectUrl)) {
        final Service service = this.serviceFactory.createService(this.redirectUrl);
        final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
        RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service, registeredService);
        requestContext.getExternalContext().requestExternalRedirect(service.getId());
    } else {
        final String tgt = WebUtils.getTicketGrantingTicketId(requestContext);
        WebUtils.putPrincipal(requestContext, getAuthenticationPrincipal(tgt));
    }
    return success();
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service)

Example 77 with RegisteredService

use of org.apereo.cas.services.RegisteredService in project cas by apereo.

the class LogoutAction method doInternalExecute.

@Override
protected Event doInternalExecute(final HttpServletRequest request, final HttpServletResponse response, final RequestContext context) {
    boolean needFrontSlo = false;
    final List<LogoutRequest> logoutRequests = WebUtils.getLogoutRequests(context);
    if (logoutRequests != null) {
        needFrontSlo = logoutRequests.stream().anyMatch(logoutRequest -> logoutRequest.getStatus() == LogoutRequestStatus.NOT_ATTEMPTED);
    }
    final String paramName = StringUtils.defaultIfEmpty(logoutProperties.getRedirectParameter(), CasProtocolConstants.PARAMETER_SERVICE);
    LOGGER.debug("Using parameter name [{}] to detect destination service, if any", paramName);
    final String service = request.getParameter(paramName);
    LOGGER.debug("Located target service [{}] for redirection after logout", paramName);
    if (logoutProperties.isFollowServiceRedirects() && StringUtils.isNotBlank(service)) {
        final Service webAppService = webApplicationServiceFactory.createService(service);
        final RegisteredService rService = this.servicesManager.findServiceBy(webAppService);
        if (rService != null && rService.getAccessStrategy().isServiceAccessAllowed()) {
            LOGGER.debug("Redirecting to service [{}]", service);
            WebUtils.putLogoutRedirectUrl(context, service);
        } else {
            LOGGER.warn("Cannot redirect to [{}] given the service is unauthorized to use CAS. " + "Ensure the service is registered with CAS and is enabled to allowed access", service);
        }
    } else {
        LOGGER.debug("No target service is located for redirection after logout, or CAS is not allowed to follow redirects after logout");
    }
    // there are some front services to logout, perform front SLO
    if (needFrontSlo) {
        LOGGER.debug("Proceeding forward with front-channel single logout");
        return new Event(this, CasWebflowConstants.TRANSITION_ID_FRONT);
    }
    LOGGER.debug("Moving forward to finish the logout process");
    return new Event(this, CasWebflowConstants.TRANSITION_ID_FINISH);
}
Also used : CasProtocolConstants(org.apereo.cas.CasProtocolConstants) LogoutRequest(org.apereo.cas.logout.LogoutRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) LogoutRequestStatus(org.apereo.cas.logout.LogoutRequestStatus) LogoutProperties(org.apereo.cas.configuration.model.core.logout.LogoutProperties) StringUtils(org.apache.commons.lang3.StringUtils) RequestContext(org.springframework.webflow.execution.RequestContext) RegisteredService(org.apereo.cas.services.RegisteredService) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) CasWebflowConstants(org.apereo.cas.web.flow.CasWebflowConstants) Service(org.apereo.cas.authentication.principal.Service) AllArgsConstructor(lombok.AllArgsConstructor) WebUtils(org.apereo.cas.web.support.WebUtils) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) Event(org.springframework.webflow.execution.Event) ServicesManager(org.apereo.cas.services.ServicesManager) RegisteredService(org.apereo.cas.services.RegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Service(org.apereo.cas.authentication.principal.Service) Event(org.springframework.webflow.execution.Event) LogoutRequest(org.apereo.cas.logout.LogoutRequest)

Example 78 with RegisteredService

use of org.apereo.cas.services.RegisteredService in project cas by apereo.

the class ServiceAuthorizationCheckTests method setUpMocks.

@Before
public void setUpMocks() {
    final RegexRegisteredService authorizedRegisteredService = new RegexRegisteredService();
    final RegexRegisteredService unauthorizedRegisteredService = new RegexRegisteredService();
    unauthorizedRegisteredService.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy(false, false));
    final List<RegisteredService> list = new ArrayList<>();
    list.add(authorizedRegisteredService);
    list.add(unauthorizedRegisteredService);
    when(this.servicesManager.findServiceBy(this.authorizedService)).thenReturn(authorizedRegisteredService);
    when(this.servicesManager.findServiceBy(this.unauthorizedService)).thenReturn(unauthorizedRegisteredService);
    when(this.servicesManager.findServiceBy(this.undefinedService)).thenReturn(null);
    when(this.servicesManager.getAllServices()).thenReturn(list);
    this.serviceAuthorizationCheck = new ServiceAuthorizationCheck(this.servicesManager, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
}
Also used : DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) ArrayList(java.util.ArrayList) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) DefaultRegisteredServiceAccessStrategy(org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy) Before(org.junit.Before)

Example 79 with RegisteredService

use of org.apereo.cas.services.RegisteredService in project cas by apereo.

the class CheckConsentRequiredAction method determineConsentEvent.

/**
 * Determine consent event string.
 *
 * @param requestContext the request context
 * @return the string
 */
protected String determineConsentEvent(final RequestContext requestContext) {
    final Service service = this.authenticationRequestServiceSelectionStrategies.resolveService(WebUtils.getService(requestContext));
    if (service == null) {
        return null;
    }
    final RegisteredService registeredService = getRegisteredServiceForConsent(requestContext, service);
    final Authentication authentication = WebUtils.getAuthentication(requestContext);
    if (authentication == null) {
        return null;
    }
    return isConsentRequired(service, registeredService, authentication, requestContext);
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service)

Example 80 with RegisteredService

use of org.apereo.cas.services.RegisteredService in project cas by apereo.

the class ConfirmConsentAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    final HttpServletRequest request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
    final Service service = this.authenticationRequestServiceSelectionStrategies.resolveService(WebUtils.getService(requestContext));
    final RegisteredService registeredService = getRegisteredServiceForConsent(requestContext, service);
    final Authentication authentication = WebUtils.getAuthentication(requestContext);
    final int optionValue = Integer.parseInt(request.getParameter("option"));
    final ConsentOptions option = ConsentOptions.valueOf(optionValue);
    final long reminder = Long.parseLong(request.getParameter("reminder"));
    final String reminderTimeUnit = request.getParameter("reminderTimeUnit");
    final ChronoUnit unit = ChronoUnit.valueOf(reminderTimeUnit.toUpperCase());
    consentEngine.storeConsentDecision(service, registeredService, authentication, reminder, unit, option);
    return new EventFactorySupport().success(this);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConsentOptions(org.apereo.cas.consent.ConsentOptions) RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) ChronoUnit(java.time.temporal.ChronoUnit)

Aggregations

RegisteredService (org.apereo.cas.services.RegisteredService)182 Authentication (org.apereo.cas.authentication.Authentication)59 Service (org.apereo.cas.authentication.principal.Service)55 Test (org.junit.Test)49 Principal (org.apereo.cas.authentication.principal.Principal)36 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)31 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)29 RegexRegisteredService (org.apereo.cas.services.RegexRegisteredService)23 AbstractRegisteredService (org.apereo.cas.services.AbstractRegisteredService)21 MultifactorAuthenticationProvider (org.apereo.cas.services.MultifactorAuthenticationProvider)20 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)20 Event (org.springframework.webflow.execution.Event)20 ServicesManager (org.apereo.cas.services.ServicesManager)17 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)15 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)15 Map (java.util.Map)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 Slf4j (lombok.extern.slf4j.Slf4j)14 Collection (java.util.Collection)13 HashMap (java.util.HashMap)12