Search in sources :

Example 1 with FunctionDrivenDynamicHTTPMetadataResolver

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);
}
Also used : SamlIdPProperties(org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties) FunctionDrivenDynamicHTTPMetadataResolver(org.opensaml.saml.metadata.resolver.impl.FunctionDrivenDynamicHTTPMetadataResolver) Nullable(javax.annotation.Nullable) SamlException(org.apereo.cas.support.saml.SamlException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

Nullable (javax.annotation.Nullable)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 SamlIdPProperties (org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties)1 SamlException (org.apereo.cas.support.saml.SamlException)1 FunctionDrivenDynamicHTTPMetadataResolver (org.opensaml.saml.metadata.resolver.impl.FunctionDrivenDynamicHTTPMetadataResolver)1