Search in sources :

Example 1 with BasicParserPool

use of org.opensaml.xml.parse.BasicParserPool 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)

Aggregations

File (java.io.File)1 Timer (java.util.Timer)1 FactoryConfigurationError (javax.xml.stream.FactoryConfigurationError)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 FilesystemMetadataProvider (org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider)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