use of org.opensaml.saml.metadata.resolver.impl.FunctionDrivenDynamicHTTPMetadataResolver in project cas by apereo.
the class ChainingMetadataResolverCacheLoader method resolveMetadataDynamically.
/**
* Resolve metadata dynamically.
*
* @param service the service
* @param metadataResolvers the metadata resolvers
* @throws Exception the exception
*/
protected void resolveMetadataDynamically(final SamlRegisteredService service, final List<MetadataResolver> metadataResolvers) throws Exception {
LOGGER.info("Loading metadata dynamically for [{}]", service.getName());
final SamlIdPProperties.Metadata md = casProperties.getAuthn().getSamlIdp().getMetadata();
final FunctionDrivenDynamicHTTPMetadataResolver resolver = new FunctionDrivenDynamicHTTPMetadataResolver(this.httpClient.getWrappedHttpClient());
resolver.setMinCacheDuration(TimeUnit.MILLISECONDS.convert(md.getCacheExpirationMinutes(), TimeUnit.MINUTES));
resolver.setRequireValidMetadata(md.isRequireValidMetadata());
if (StringUtils.isNotBlank(md.getBasicAuthnPassword()) && StringUtils.isNotBlank(md.getBasicAuthnUsername())) {
resolver.setBasicCredentials(new UsernamePasswordCredentials(md.getBasicAuthnUsername(), md.getBasicAuthnPassword()));
}
if (!md.getSupportedContentTypes().isEmpty()) {
resolver.setSupportedContentTypes(md.getSupportedContentTypes());
}
resolver.setRequestURLBuilder(new Function<String, String>() {
@Nullable
@Override
public String apply(@Nullable final String input) {
try {
if (StringUtils.isNotBlank(input)) {
final String metadataLocation = service.getMetadataLocation().replace("{0}", EncodingUtils.urlEncode(input));
LOGGER.info("Constructed dynamic metadata query [{}] for [{}]", metadataLocation, service.getName());
return metadataLocation;
}
return null;
} catch (final Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
});
buildSingleMetadataResolver(resolver, service);
metadataResolvers.add(resolver);
}
Aggregations