Search in sources :

Example 1 with FileBackedHTTPMetadataResolver

use of org.opensaml.saml.metadata.resolver.impl.FileBackedHTTPMetadataResolver in project cas by apereo.

the class ChainingMetadataResolverCacheLoader method resolveUrlBasedMetadataResource.

private void resolveUrlBasedMetadataResource(final SamlRegisteredService service, final List<MetadataResolver> metadataResolvers, final AbstractResource metadataResource) throws Exception {
    final SamlIdPProperties.Metadata md = casProperties.getAuthn().getSamlIdp().getMetadata();
    final File backupDirectory = new File(md.getLocation().getFile(), "metadata-backups");
    final File backupFile = new File(backupDirectory, metadataResource.getFilename());
    LOGGER.debug("Metadata backup directory is designated to be [{}]", backupDirectory.getCanonicalPath());
    FileUtils.forceMkdir(backupDirectory);
    LOGGER.debug("Metadata backup file will be at [{}]", backupFile.getCanonicalPath());
    FileUtils.forceMkdirParent(backupFile);
    final HttpClientMultithreadedDownloader downloader = new HttpClientMultithreadedDownloader(metadataResource, backupFile);
    final FileBackedHTTPMetadataResolver metadataProvider = new FileBackedHTTPMetadataResolver(this.httpClient.getWrappedHttpClient(), metadataResource.getURL().toExternalForm(), backupFile.getCanonicalPath());
    buildSingleMetadataResolver(metadataProvider, service);
    metadataResolvers.add(metadataProvider);
}
Also used : HttpClientMultithreadedDownloader(org.apereo.cas.util.http.HttpClientMultithreadedDownloader) FileBackedHTTPMetadataResolver(org.opensaml.saml.metadata.resolver.impl.FileBackedHTTPMetadataResolver) SamlIdPProperties(org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties) File(java.io.File)

Example 2 with FileBackedHTTPMetadataResolver

use of org.opensaml.saml.metadata.resolver.impl.FileBackedHTTPMetadataResolver in project cas by apereo.

the class UrlResourceMetadataResolver method resolve.

@Override
public Collection<MetadataResolver> resolve(final SamlRegisteredService service) {
    try {
        final String metadataLocation = service.getMetadataLocation();
        LOGGER.info("Loading SAML metadata from [{}]", metadataLocation);
        final AbstractResource metadataResource = ResourceUtils.getResourceFrom(metadataLocation);
        final File backupFile = getMetadataBackupFile(metadataResource, service);
        final String canonicalPath = backupFile.getCanonicalPath();
        LOGGER.debug("Metadata backup file will be at [{}]", canonicalPath);
        FileUtils.forceMkdirParent(backupFile);
        cleanUpExpiredBackupMetadataFilesFor(metadataResource, service);
        final FileBackedHTTPMetadataResolver metadataProvider = new FileBackedHTTPMetadataResolver(this.httpClient.getWrappedHttpClient(), metadataResource.getURL().toExternalForm(), canonicalPath);
        configureAndInitializeSingleMetadataResolver(metadataProvider, service);
        return CollectionUtils.wrap(metadataProvider);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return new ArrayList<>(0);
}
Also used : FileBackedHTTPMetadataResolver(org.opensaml.saml.metadata.resolver.impl.FileBackedHTTPMetadataResolver) ArrayList(java.util.ArrayList) AbstractResource(org.springframework.core.io.AbstractResource) File(java.io.File) IOException(java.io.IOException)

Aggregations

File (java.io.File)2 FileBackedHTTPMetadataResolver (org.opensaml.saml.metadata.resolver.impl.FileBackedHTTPMetadataResolver)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 SamlIdPProperties (org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties)1 HttpClientMultithreadedDownloader (org.apereo.cas.util.http.HttpClientMultithreadedDownloader)1 AbstractResource (org.springframework.core.io.AbstractResource)1