Search in sources :

Example 1 with RestServiceRegistry

use of org.apereo.cas.services.RestServiceRegistry 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)

Aggregations

SneakyThrows (lombok.SneakyThrows)1 ServiceRegistryProperties (org.apereo.cas.configuration.model.core.services.ServiceRegistryProperties)1 RestServiceRegistry (org.apereo.cas.services.RestServiceRegistry)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 RestTemplate (org.springframework.web.client.RestTemplate)1