Search in sources :

Example 26 with Service

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

the class WSFederationAuthenticationServiceSelectionStrategy method getReplyAsParameter.

private static Optional<NameValuePair> getReplyAsParameter(final Service service) {
    try {
        final URIBuilder builder = new URIBuilder(service.getId());
        final Optional param = builder.getQueryParams().stream().filter(p -> p.getName().equals(WSFederationConstants.WREPLY)).findFirst();
        return param;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return Optional.empty();
}
Also used : AuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.AuthenticationServiceSelectionStrategy) Ordered(org.springframework.core.Ordered) Slf4j(lombok.extern.slf4j.Slf4j) URIBuilder(org.apache.http.client.utils.URIBuilder) WSFederationConstants(org.apereo.cas.ws.idp.WSFederationConstants) Service(org.apereo.cas.authentication.principal.Service) Optional(java.util.Optional) NameValuePair(org.apache.http.NameValuePair) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) Optional(java.util.Optional) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 27 with Service

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

the class SecurityTokenServiceAuthenticationMetaDataPopulator method populateAttributes.

@Override
public void populateAttributes(final AuthenticationBuilder builder, final AuthenticationTransaction transaction) {
    if (!this.selectionStrategy.supports(transaction.getService())) {
        return;
    }
    final Service service = this.selectionStrategy.resolveServiceFrom(transaction.getService());
    if (service != null) {
        final WSFederationRegisteredService rp = this.servicesManager.findServiceBy(service, WSFederationRegisteredService.class);
        if (rp == null || !rp.getAccessStrategy().isServiceAccessAllowed()) {
            LOGGER.warn("Service [{}] is not allowed to use SSO.", rp);
            throw new UnauthorizedSsoServiceException();
        }
        final SecurityTokenServiceClient sts = clientBuilder.buildClientForSecurityTokenRequests(rp);
        invokeSecurityTokenServiceForToken(transaction, builder, rp, sts);
    }
}
Also used : UnauthorizedSsoServiceException(org.apereo.cas.services.UnauthorizedSsoServiceException) WSFederationRegisteredService(org.apereo.cas.ws.idp.services.WSFederationRegisteredService) WSFederationRegisteredService(org.apereo.cas.ws.idp.services.WSFederationRegisteredService) Service(org.apereo.cas.authentication.principal.Service)

Example 28 with Service

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

the class WsFederationAction method prepareLoginViewWithWsFederationClients.

private void prepareLoginViewWithWsFederationClients(final RequestContext context) {
    final List<WsFedClient> clients = new ArrayList<>();
    final HttpServletRequest request = WebUtils.getHttpServletRequestFromExternalWebflowContext(context);
    final Service service = (Service) context.getFlowScope().get(CasProtocolConstants.PARAMETER_SERVICE);
    this.configurations.forEach(cfg -> {
        final WsFedClient c = new WsFedClient();
        c.setName(cfg.getName());
        final String id = UUID.randomUUID().toString();
        final String rpId = wsFederationHelper.getRelyingPartyIdentifier(service, cfg);
        c.setAuthorizationUrl(cfg.getAuthorizationUrl(rpId, id));
        c.setReplyingPartyId(rpId);
        c.setId(id);
        c.setRedirectUrl(WsFederationNavigationController.getRelativeRedirectUrlFor(cfg, service, request));
        c.setAutoRedirect(cfg.isAutoRedirect());
        clients.add(c);
    });
    context.getFlowScope().put("wsfedUrls", clients);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service)

Example 29 with Service

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

the class DefaultSingleSignOnParticipationStrategy method isParticipating.

@Override
public boolean isParticipating(final RequestContext ctx) {
    if (renewEnabled && ctx.getRequestParameters().contains(CasProtocolConstants.PARAMETER_RENEW)) {
        LOGGER.debug("[{}] is specified for the request. The authentication session will be considered renewed.", CasProtocolConstants.PARAMETER_RENEW);
        return this.createSsoSessionCookieOnRenewAuthentications;
    }
    final Authentication authentication = WebUtils.getAuthentication(ctx);
    final Service service = WebUtils.getService(ctx);
    if (service != null) {
        final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
        if (registeredService != null) {
            final Authentication ca = AuthenticationCredentialsThreadLocalBinder.getCurrentAuthentication();
            try {
                AuthenticationCredentialsThreadLocalBinder.bindCurrent(authentication);
                final boolean isAllowedForSso = registeredService.getAccessStrategy().isServiceAccessAllowedForSso();
                LOGGER.debug("Located [{}] in registry. Service access to participate in SSO is set to [{}]", registeredService.getServiceId(), isAllowedForSso);
                return isAllowedForSso;
            } finally {
                AuthenticationCredentialsThreadLocalBinder.bindCurrent(ca);
            }
        }
    }
    return true;
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) Service(org.apereo.cas.authentication.principal.Service) RegisteredService(org.apereo.cas.services.RegisteredService)

Example 30 with Service

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

the class GroovyScriptMultifactorAuthenticationPolicyEventResolver method resolveInternal.

@Override
public Set<Event> resolveInternal(final RequestContext context) {
    final Service service = resolveServiceFromAuthenticationRequest(context);
    final RegisteredService registeredService = resolveRegisteredServiceInRequestContext(context);
    final Authentication authentication = WebUtils.getAuthentication(context);
    if (groovyScript == null) {
        LOGGER.debug("No groovy script is configured for multifactor authentication");
        return null;
    }
    if (!ResourceUtils.doesResourceExist(groovyScript)) {
        LOGGER.warn("No groovy script is found at [{}] for multifactor authentication", groovyScript);
        return null;
    }
    if (authentication == null) {
        LOGGER.debug("No authentication is available to determine event for principal");
        return null;
    }
    if (registeredService == null || service == null) {
        LOGGER.debug("No registered service is available to determine event for principal [{}]", authentication.getPrincipal());
        return null;
    }
    final Map<String, MultifactorAuthenticationProvider> providerMap = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext);
    if (providerMap == null || providerMap.isEmpty()) {
        LOGGER.error("No multifactor authentication providers are available in the application context");
        throw new AuthenticationException();
    }
    try {
        final Object[] args = { service, registeredService, authentication, LOGGER };
        final String provider = ScriptingUtils.executeGroovyScript(groovyScript, args, String.class);
        LOGGER.debug("Groovy script run for [{}] returned the provider id [{}]", service, provider);
        if (StringUtils.isBlank(provider)) {
            return null;
        }
        final Optional<MultifactorAuthenticationProvider> providerFound = resolveProvider(providerMap, provider);
        if (providerFound.isPresent()) {
            final MultifactorAuthenticationProvider multifactorAuthenticationProvider = providerFound.get();
            if (multifactorAuthenticationProvider.isAvailable(registeredService)) {
                final Event event = validateEventIdForMatchingTransitionInContext(multifactorAuthenticationProvider.getId(), context, buildEventAttributeMap(authentication.getPrincipal(), registeredService, multifactorAuthenticationProvider));
                return CollectionUtils.wrapSet(event);
            }
            LOGGER.warn("Located multifactor provider [{}], yet the provider cannot be reached or verified", multifactorAuthenticationProvider);
            return null;
        }
        LOGGER.warn("No multifactor provider could be found for [{}]", provider);
        throw new AuthenticationException();
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) Authentication(org.apereo.cas.authentication.Authentication) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) Event(org.springframework.webflow.execution.Event) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider) AuthenticationException(org.apereo.cas.authentication.AuthenticationException)

Aggregations

Service (org.apereo.cas.authentication.principal.Service)162 lombok.val (lombok.val)54 RegisteredService (org.apereo.cas.services.RegisteredService)53 Authentication (org.apereo.cas.authentication.Authentication)44 Test (org.junit.Test)36 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)34 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)31 Slf4j (lombok.extern.slf4j.Slf4j)30 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)26 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)25 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)25 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)25 Test (org.junit.jupiter.api.Test)25 Optional (java.util.Optional)24 HttpServletRequest (javax.servlet.http.HttpServletRequest)23 StringUtils (org.apache.commons.lang3.StringUtils)18 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)18 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)17 UnauthorizedServiceException (org.apereo.cas.services.UnauthorizedServiceException)17 HashMap (java.util.HashMap)16