Search in sources :

Example 81 with RegisteredService

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

the class DefaultRegisteredServiceReplicationStrategy method updateLoadedRegisteredServicesFromCache.

@Override
public List<RegisteredService> updateLoadedRegisteredServicesFromCache(final List<RegisteredService> services, final ServiceRegistry serviceRegistry) {
    final Collection<DistributedCacheObject<RegisteredService>> cachedServices = this.distributedCacheManager.getAll();
    for (final DistributedCacheObject<RegisteredService> entry : cachedServices) {
        final RegisteredService cachedService = entry.getValue();
        LOGGER.debug("Found cached service definition [{}] in the replication cache [{}]", cachedService, distributedCacheManager.getName());
        if (isRegisteredServiceMarkedAsDeletedInCache(entry)) {
            LOGGER.debug("Service found in the cache [{}] is marked as a deleted service. CAS will update the service registry " + "of this CAS node to remove the local service, if found.", cachedService);
            serviceRegistry.delete(cachedService);
            this.distributedCacheManager.remove(cachedService, entry);
            continue;
        }
        final RegisteredService matchingService = services.stream().filter(s -> s.getId() == cachedService.getId()).findFirst().orElse(null);
        if (matchingService != null) {
            updateServiceRegistryWithMatchingService(services, cachedService, matchingService, serviceRegistry);
        } else {
            updateServiceRegistryWithNoMatchingService(services, cachedService, serviceRegistry);
        }
    }
    return services;
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) DistributedCacheObject(org.apereo.cas.DistributedCacheObject)

Example 82 with RegisteredService

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

the class CreateResourceBasedRegisteredServiceWatcher method accept.

@Override
public void accept(final File file) {
    LOGGER.debug("New service definition [{}] was created. Locating service entry from cache...", file);
    final Collection<RegisteredService> services = serviceRegistryDao.load(file);
    services.stream().filter(Objects::nonNull).forEach(service -> {
        if (serviceRegistryDao.findServiceById(service.getId()) != null) {
            LOG_SERVICE_DUPLICATE.accept(service);
        }
        LOGGER.debug("Updating service definitions with [{}]", service);
        serviceRegistryDao.publishEvent(new CasRegisteredServicePreSaveEvent(this, service));
        serviceRegistryDao.update(service);
        serviceRegistryDao.publishEvent(new CasRegisteredServiceSavedEvent(this, service));
    });
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) CasRegisteredServiceSavedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent) CasRegisteredServicePreSaveEvent(org.apereo.cas.support.events.service.CasRegisteredServicePreSaveEvent)

Example 83 with RegisteredService

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

the class DeleteResourceBasedRegisteredServiceWatcher method accept.

@Override
public void accept(final File file) {
    LOGGER.debug("Service definition [{}] was deleted. Reloading cache...", file);
    final RegisteredService service = serviceRegistryDao.getRegisteredServiceFromFile(file);
    if (service != null) {
        serviceRegistryDao.publishEvent(new CasRegisteredServicePreDeleteEvent(this, service));
        serviceRegistryDao.removeRegisteredService(service);
        LOGGER.debug("Successfully deleted service definition [{}]", service.getName());
        serviceRegistryDao.publishEvent(new CasRegisteredServiceDeletedEvent(this, service));
    } else {
        LOGGER.warn("Unable to locate a matching service definition from file [{}]. Reloading cache...", file);
        final List<RegisteredService> results = serviceRegistryDao.load();
        serviceRegistryDao.publishEvent(new CasRegisteredServicesLoadedEvent(this, results));
    }
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) CasRegisteredServicePreDeleteEvent(org.apereo.cas.support.events.service.CasRegisteredServicePreDeleteEvent) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) CasRegisteredServicesLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServicesLoadedEvent)

Example 84 with RegisteredService

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

the class DefaultRegisteredServiceJsonSerializerTests method checkNullability.

@Test
public void checkNullability() {
    final DefaultRegisteredServiceJsonSerializer zer = new DefaultRegisteredServiceJsonSerializer();
    final String json = "    {\n" + "        \"@class\" : \"org.apereo.cas.services.RegexRegisteredService\",\n" + "            \"serviceId\" : \"^https://xyz.*\",\n" + "            \"name\" : \"XYZ\",\n" + "            \"id\" : \"20161214\"\n" + "    }";
    final RegisteredService s = zer.from(json);
    assertNotNull(s);
    assertNotNull(s.getAccessStrategy());
    assertNotNull(s.getAttributeReleasePolicy());
    assertNotNull(s.getProxyPolicy());
    assertNotNull(s.getUsernameAttributeProvider());
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) DefaultRegisteredServiceJsonSerializer(org.apereo.cas.services.util.DefaultRegisteredServiceJsonSerializer) Test(org.junit.Test)

Example 85 with RegisteredService

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

the class GrouperMultifactorAuthenticationPolicyEventResolver method resolveInternal.

@Override
public Set<Event> resolveInternal(final RequestContext context) {
    final RegisteredService service = resolveRegisteredServiceInRequestContext(context);
    final Authentication authentication = WebUtils.getAuthentication(context);
    if (StringUtils.isBlank(grouperField)) {
        LOGGER.debug("No group field is defined to process for Grouper multifactor trigger");
        return null;
    }
    if (authentication == null || service == null) {
        LOGGER.debug("No authentication or service is available to determine event for principal");
        return null;
    }
    final Principal principal = authentication.getPrincipal();
    final Collection<WsGetGroupsResult> results = GrouperFacade.getGroupsForSubjectId(principal.getId());
    if (results.isEmpty()) {
        LOGGER.debug("No groups could be found for [{}] to resolve events for MFA", principal);
        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();
    }
    final GrouperGroupField groupField = GrouperGroupField.valueOf(grouperField);
    final Set<String> values = results.stream().map(wsGetGroupsResult -> Stream.of(wsGetGroupsResult.getWsGroups())).flatMap(Function.identity()).map(g -> GrouperFacade.getGrouperGroupAttribute(groupField, g)).collect(Collectors.toSet());
    final Optional<MultifactorAuthenticationProvider> providerFound = resolveProvider(providerMap, values);
    if (providerFound.isPresent()) {
        final MultifactorAuthenticationProvider provider = providerFound.get();
        if (provider.isAvailable(service)) {
            LOGGER.debug("Attempting to build event based on the authentication provider [{}] and service [{}]", provider, service.getName());
            final Event event = validateEventIdForMatchingTransitionInContext(provider.getId(), context, buildEventAttributeMap(authentication.getPrincipal(), service, provider));
            return CollectionUtils.wrapSet(event);
        }
        LOGGER.warn("Located multifactor provider [{}], yet the provider cannot be reached or verified", providerFound.get());
        return null;
    }
    LOGGER.debug("No multifactor provider could be found based on [{}]'s Grouper groups", principal.getId());
    return null;
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) WsGetGroupsResult(edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult) MultifactorAuthenticationProviderSelector(org.apereo.cas.services.MultifactorAuthenticationProviderSelector) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) TicketRegistrySupport(org.apereo.cas.ticket.registry.TicketRegistrySupport) RequestContext(org.springframework.webflow.execution.RequestContext) Function(java.util.function.Function) Authentication(org.apereo.cas.authentication.Authentication) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) AuthenticationSystemSupport(org.apereo.cas.authentication.AuthenticationSystemSupport) GrouperFacade(org.apereo.cas.grouper.GrouperFacade) MultifactorAuthenticationUtils(org.apereo.cas.authentication.MultifactorAuthenticationUtils) CookieGenerator(org.springframework.web.util.CookieGenerator) ServicesManager(org.apereo.cas.services.ServicesManager) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider) StringUtils(edu.internet2.middleware.grouperClientExt.org.apache.commons.lang3.StringUtils) GrouperGroupField(org.apereo.cas.grouper.GrouperGroupField) Audit(org.apereo.inspektr.audit.annotation.Audit) Collection(java.util.Collection) AuthenticationServiceSelectionPlan(org.apereo.cas.authentication.AuthenticationServiceSelectionPlan) Set(java.util.Set) Collectors(java.util.stream.Collectors) RegisteredService(org.apereo.cas.services.RegisteredService) BaseMultifactorAuthenticationProviderEventResolver(org.apereo.cas.web.flow.authentication.BaseMultifactorAuthenticationProviderEventResolver) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Optional(java.util.Optional) Principal(org.apereo.cas.authentication.principal.Principal) WebUtils(org.apereo.cas.web.support.WebUtils) Event(org.springframework.webflow.execution.Event) RegisteredService(org.apereo.cas.services.RegisteredService) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider) WsGetGroupsResult(edu.internet2.middleware.grouperClient.ws.beans.WsGetGroupsResult) Authentication(org.apereo.cas.authentication.Authentication) GrouperGroupField(org.apereo.cas.grouper.GrouperGroupField) Event(org.springframework.webflow.execution.Event) Principal(org.apereo.cas.authentication.principal.Principal)

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