Search in sources :

Example 1 with ServiceRegistryProperties

use of org.apereo.cas.configuration.model.core.services.ServiceRegistryProperties in project cas by apereo.

the class RestServiceRegistryConfiguration method restfulServiceRegistry.

@Bean
@RefreshScope
@SneakyThrows
public ServiceRegistry restfulServiceRegistry() {
    final ServiceRegistryProperties registry = casProperties.getServiceRegistry();
    final RestTemplate restTemplate = new RestTemplate();
    final MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    if (StringUtils.isNotBlank(registry.getRest().getBasicAuthUsername()) && StringUtils.isNotBlank(registry.getRest().getBasicAuthPassword())) {
        final String auth = registry.getRest().getBasicAuthUsername() + ":" + registry.getRest().getBasicAuthPassword();
        final byte[] encodedAuth = EncodingUtils.encodeBase64ToByteArray(auth.getBytes(StandardCharsets.UTF_8));
        final String authHeader = "Basic " + new String(encodedAuth, StandardCharsets.UTF_8);
        headers.put("Authorization", CollectionUtils.wrap(authHeader));
    }
    return new RestServiceRegistry(restTemplate, registry.getRest().getUrl(), headers);
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ServiceRegistryProperties(org.apereo.cas.configuration.model.core.services.ServiceRegistryProperties) RestTemplate(org.springframework.web.client.RestTemplate) RestServiceRegistry(org.apereo.cas.services.RestServiceRegistry) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) SneakyThrows(lombok.SneakyThrows) Bean(org.springframework.context.annotation.Bean)

Example 2 with ServiceRegistryProperties

use of org.apereo.cas.configuration.model.core.services.ServiceRegistryProperties in project cas by apereo.

the class CasServiceRegistryInitializationConfiguration method serviceRegistryInitializer.

@RefreshScope
@Bean
public ServiceRegistryInitializer serviceRegistryInitializer() {
    final ServiceRegistryProperties props = casProperties.getServiceRegistry();
    final ServiceRegistry serviceRegistryInstance = serviceRegistry.getIfAvailable();
    final ServiceRegistryInitializer initializer = new ServiceRegistryInitializer(embeddedJsonServiceRegistry(), serviceRegistryInstance, servicesManager.getIfAvailable(), props.isInitFromJson());
    if (props.isInitFromJson()) {
        LOGGER.info("Attempting to initialize the service registry [{}] from service definition resources found at [{}]", serviceRegistryInstance.getName(), getServiceRegistryInitializerServicesDirectoryResource());
    }
    initializer.initServiceRegistryIfNecessary();
    return initializer;
}
Also used : ServiceRegistryInitializer(org.apereo.cas.services.ServiceRegistryInitializer) ServiceRegistryProperties(org.apereo.cas.configuration.model.core.services.ServiceRegistryProperties) JsonServiceRegistryProperties(org.apereo.cas.configuration.model.support.services.json.JsonServiceRegistryProperties) AbstractResourceBasedServiceRegistry(org.apereo.cas.services.resource.AbstractResourceBasedServiceRegistry) ServiceRegistry(org.apereo.cas.services.ServiceRegistry) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Aggregations

ServiceRegistryProperties (org.apereo.cas.configuration.model.core.services.ServiceRegistryProperties)2 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)2 Bean (org.springframework.context.annotation.Bean)2 SneakyThrows (lombok.SneakyThrows)1 JsonServiceRegistryProperties (org.apereo.cas.configuration.model.support.services.json.JsonServiceRegistryProperties)1 RestServiceRegistry (org.apereo.cas.services.RestServiceRegistry)1 ServiceRegistry (org.apereo.cas.services.ServiceRegistry)1 ServiceRegistryInitializer (org.apereo.cas.services.ServiceRegistryInitializer)1 AbstractResourceBasedServiceRegistry (org.apereo.cas.services.resource.AbstractResourceBasedServiceRegistry)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 RestTemplate (org.springframework.web.client.RestTemplate)1