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);
}
Aggregations