use of org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain in project cas by apereo.
the class SamlMetadataUIConfiguration method configureAdapter.
private static MetadataResolverAdapter configureAdapter(final AbstractMetadataResolverAdapter adapter, final ConfigurableApplicationContext applicationContext, final CasConfigurationProperties casProperties, final OpenSamlConfigBean openSamlConfigBean) {
val resources = new HashMap<Resource, MetadataFilterChain>();
val chain = new MetadataFilterChain();
casProperties.getSamlMetadataUi().getResources().forEach(Unchecked.consumer(r -> configureResource(applicationContext, resources, chain, r, casProperties)));
adapter.setRequireValidMetadata(casProperties.getSamlMetadataUi().isRequireValidMetadata());
adapter.setMetadataResources(resources);
adapter.setConfigBean(openSamlConfigBean);
return adapter;
}
use of org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain in project cas by apereo.
the class SamlMetadataUIConfiguration method configureResource.
private static void configureResource(final ConfigurableApplicationContext applicationContext, final Map<Resource, MetadataFilterChain> resources, final MetadataFilterChain chain, final String resourceArray, final CasConfigurationProperties casProperties) {
val splitArray = org.springframework.util.StringUtils.commaDelimitedListToStringArray(resourceArray);
Arrays.stream(splitArray).forEach(Unchecked.consumer(entry -> {
val arr = Splitter.on(DEFAULT_SEPARATOR).splitToList(entry);
val metadataFile = arr.get(0);
val signingKey = arr.size() > 1 ? arr.get(1) : null;
val filters = new ArrayList<MetadataFilter>();
if (casProperties.getSamlMetadataUi().getMaxValidity() > 0) {
val filter = new RequiredValidUntilFilter();
filter.setMaxValidityInterval(Duration.ofSeconds(casProperties.getSamlMetadataUi().getMaxValidity()));
filters.add(filter);
}
var addResource = true;
if (StringUtils.isNotBlank(signingKey)) {
val sigFilter = SamlUtils.buildSignatureValidationFilter(applicationContext, signingKey);
if (sigFilter != null) {
sigFilter.setRequireSignedRoot(casProperties.getSamlMetadataUi().isRequireSignedRoot());
filters.add(sigFilter);
} else {
LOGGER.warn("Failed to locate the signing key [{}] for [{}]", signingKey, metadataFile);
addResource = false;
}
}
chain.setFilters(filters);
val resource = applicationContext.getResource(metadataFile);
if (addResource && ResourceUtils.doesResourceExist(resource)) {
resources.put(resource, chain);
} else {
LOGGER.warn("Skipping metadata [{}]; Either the resource cannot be retrieved or its signing key is missing", metadataFile);
}
}));
}
Aggregations