Search in sources :

Example 1 with FilesystemMetadataProvider

use of org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider in project cloudstack by apache.

the class SAML2AuthManagerImpl method setup.

private boolean setup() {
    if (!initSP()) {
        s_logger.error("SAML Plugin failed to initialize, please fix the configuration and restart management server");
        return false;
    }
    _timer = new Timer();
    final HttpClient client = new HttpClient();
    final String idpMetaDataUrl = getSAMLIdentityProviderMetadataURL();
    if (SAMLTimeout.value() != null && SAMLTimeout.value() > SAMLPluginConstants.SAML_REFRESH_INTERVAL) {
        _refreshInterval = SAMLTimeout.value();
    }
    try {
        DefaultBootstrap.bootstrap();
        if (idpMetaDataUrl.startsWith("http")) {
            _idpMetaDataProvider = new HTTPMetadataProvider(_timer, client, idpMetaDataUrl);
        } else {
            File metadataFile = PropertiesUtil.findConfigFile(idpMetaDataUrl);
            if (metadataFile == null) {
                s_logger.error("Provided Metadata is not a URL, Unable to locate metadata file from local path: " + idpMetaDataUrl);
                return false;
            } else {
                s_logger.debug("Provided Metadata is not a URL, trying to read metadata file from local path: " + metadataFile.getAbsolutePath());
                _idpMetaDataProvider = new FilesystemMetadataProvider(_timer, metadataFile);
            }
        }
        _idpMetaDataProvider.setRequireValidMetadata(true);
        _idpMetaDataProvider.setParserPool(new BasicParserPool());
        _idpMetaDataProvider.initialize();
        _timer.scheduleAtFixedRate(new MetadataRefreshTask(), 0, _refreshInterval * 1000);
    } catch (MetadataProviderException e) {
        s_logger.error("Unable to read SAML2 IDP MetaData URL, error:" + e.getMessage());
        s_logger.error("SAML2 Authentication may be unavailable");
        return false;
    } catch (ConfigurationException | FactoryConfigurationError e) {
        s_logger.error("OpenSAML bootstrapping failed: error: " + e.getMessage());
        return false;
    } catch (NullPointerException e) {
        s_logger.error("Unable to setup SAML Auth Plugin due to NullPointerException" + " please check the SAML global settings: " + e.getMessage());
        return false;
    }
    return true;
}
Also used : Timer(java.util.Timer) ConfigurationException(org.opensaml.xml.ConfigurationException) HttpClient(org.apache.commons.httpclient.HttpClient) BasicParserPool(org.opensaml.xml.parse.BasicParserPool) FilesystemMetadataProvider(org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider) HTTPMetadataProvider(org.opensaml.saml2.metadata.provider.HTTPMetadataProvider) File(java.io.File) MetadataProviderException(org.opensaml.saml2.metadata.provider.MetadataProviderException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError)

Example 2 with FilesystemMetadataProvider

use of org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider in project hub-alert by blackducksoftware.

the class SAMLManager method createFileProvider.

public Optional<ExtendedMetadataDelegate> createFileProvider() throws MetadataProviderException {
    Timer backgroundTaskTimer = new Timer(true);
    if (!filePersistenceUtil.uploadFileExists(AuthenticationDescriptor.SAML_METADATA_FILE)) {
        return Optional.empty();
    }
    logger.debug("SAML - Create File Metadata provider.");
    File metadataFile = filePersistenceUtil.createUploadsFile(AuthenticationDescriptor.SAML_METADATA_FILE);
    FilesystemMetadataProvider provider = new FilesystemMetadataProvider(backgroundTaskTimer, metadataFile);
    provider.setParserPool(parserPool);
    return Optional.of(createDelegate(provider));
}
Also used : Timer(java.util.Timer) FilesystemMetadataProvider(org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider) File(java.io.File)

Aggregations

File (java.io.File)2 Timer (java.util.Timer)2 FilesystemMetadataProvider (org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider)2 FactoryConfigurationError (javax.xml.stream.FactoryConfigurationError)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 HTTPMetadataProvider (org.opensaml.saml2.metadata.provider.HTTPMetadataProvider)1 MetadataProviderException (org.opensaml.saml2.metadata.provider.MetadataProviderException)1 ConfigurationException (org.opensaml.xml.ConfigurationException)1 BasicParserPool (org.opensaml.xml.parse.BasicParserPool)1