Search in sources :

Example 1 with ServiceRegistryExecutionPlanConfigurer

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

the class CasCoreServicesConfiguration method serviceRegistry.

@ConditionalOnMissingBean(name = "serviceRegistry")
@Bean
@RefreshScope
public ServiceRegistry serviceRegistry() {
    final List<ServiceRegistryExecutionPlanConfigurer> configurers = ObjectUtils.defaultIfNull(serviceRegistryDaoConfigurers.getIfAvailable(), new ArrayList<>(0));
    final DefaultServiceRegistryExecutionPlan plan = new DefaultServiceRegistryExecutionPlan();
    configurers.forEach(c -> {
        final String name = StringUtils.removePattern(c.getClass().getSimpleName(), "\\$.+");
        LOGGER.debug("Configuring service registry [{}]", name);
        c.configureServiceRegistry(plan);
    });
    final Predicate filter = Predicates.not(Predicates.instanceOf(ImmutableServiceRegistry.class));
    if (plan.getServiceRegistries(filter).isEmpty()) {
        final List<RegisteredService> services = new ArrayList<>();
        LOGGER.warn("Runtime memory is used as the persistence storage for retrieving and persisting service definitions. " + "Changes that are made to service definitions during runtime WILL be LOST when the web server is restarted. " + "Ideally for production, you need to choose a storage option (JDBC, etc) to store and track service definitions.");
        if (applicationContext.containsBean("inMemoryRegisteredServices")) {
            services.addAll(applicationContext.getBean("inMemoryRegisteredServices", List.class));
            LOGGER.debug("Found a list of registered services in the application context. Registering services [{}]", services);
        }
        plan.registerServiceRegistry(new InMemoryServiceRegistry(services));
    }
    return new ChainingServiceRegistry(plan.getServiceRegistries());
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) ArrayList(java.util.ArrayList) Predicate(com.google.common.base.Predicate) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) ImmutableServiceRegistry(org.apereo.cas.services.ImmutableServiceRegistry) DefaultServiceRegistryExecutionPlan(org.apereo.cas.services.DefaultServiceRegistryExecutionPlan) ChainingServiceRegistry(org.apereo.cas.services.ChainingServiceRegistry) ArrayList(java.util.ArrayList) List(java.util.List) ServiceRegistryExecutionPlanConfigurer(org.apereo.cas.services.ServiceRegistryExecutionPlanConfigurer) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

Predicate (com.google.common.base.Predicate)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ChainingServiceRegistry (org.apereo.cas.services.ChainingServiceRegistry)1 DefaultServiceRegistryExecutionPlan (org.apereo.cas.services.DefaultServiceRegistryExecutionPlan)1 ImmutableServiceRegistry (org.apereo.cas.services.ImmutableServiceRegistry)1 InMemoryServiceRegistry (org.apereo.cas.services.InMemoryServiceRegistry)1 RegisteredService (org.apereo.cas.services.RegisteredService)1 ServiceRegistryExecutionPlanConfigurer (org.apereo.cas.services.ServiceRegistryExecutionPlanConfigurer)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1