com.onelogin.saml2.util.Constants Java Examples

The following examples show how to use com.onelogin.saml2.util.Constants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigurationService.java    From guacamole-client with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the collection of SAML settings used to initialize the client.
 *
 * @return
 *     The collection of SAML settings used to initialize the SAML client.
 *
 * @throws GuacamoleException
 *     If guacamole.properties cannot be parsed or if required parameters
 *     are missing.
 */
public Saml2Settings getSamlSettings() throws GuacamoleException {

    // Try to get the XML file, first.
    URI idpMetadata = getIdpMetadata();
    Map<String, Object> samlMap;
    if (idpMetadata != null) {
        try {
            samlMap = IdPMetadataParser.parseRemoteXML(idpMetadata.toURL());
        }
        catch (Exception e) {
            throw new GuacamoleServerException(
                    "Could not parse SAML IdP Metadata file.", e);
        }
    }

    // If no XML metadata is provided, fall-back to individual values.
    else {
        samlMap = new HashMap<>();
        samlMap.put(SettingsBuilder.IDP_ENTITYID_PROPERTY_KEY,
                getIdpUrl().toString());
        samlMap.put(SettingsBuilder.IDP_SINGLE_SIGN_ON_SERVICE_URL_PROPERTY_KEY,
                getIdpUrl().toString());
        samlMap.put(SettingsBuilder.IDP_SINGLE_SIGN_ON_SERVICE_BINDING_PROPERTY_KEY,
                Constants.BINDING_HTTP_REDIRECT);
    }

    // Read entity ID from properties if not provided within metadata XML
    if (!samlMap.containsKey(SettingsBuilder.SP_ENTITYID_PROPERTY_KEY)) {
        URI entityId = getEntityId();
        if (entityId == null)
            throw new GuacamoleServerException("SAML Entity ID was not found"
                    + " in either the metadata XML file or guacamole.properties");
        samlMap.put(SettingsBuilder.SP_ENTITYID_PROPERTY_KEY, entityId.toString());
    }

    // Derive ACS URL from properties if not provided within metadata XML
    if (!samlMap.containsKey(SettingsBuilder.SP_ASSERTION_CONSUMER_SERVICE_URL_PROPERTY_KEY)) {
        samlMap.put(SettingsBuilder.SP_ASSERTION_CONSUMER_SERVICE_URL_PROPERTY_KEY,
                UriBuilder.fromUri(getCallbackUrl()).path("api/ext/saml/callback").build().toString());
    }

    SettingsBuilder samlBuilder = new SettingsBuilder();
    Saml2Settings samlSettings = samlBuilder.fromValues(samlMap).build();
    samlSettings.setStrict(getStrict());
    samlSettings.setDebug(getDebug());
    samlSettings.setCompressRequest(getCompressRequest());
    samlSettings.setCompressResponse(getCompressResponse());

    return samlSettings;
}
 
Example #2
Source File: SAMLAuthFilter.java    From para with Apache License 2.0 4 votes vote down vote up
protected static Map<String, Object> getSAMLSettings(App app) {
	if (app == null) {
		return Collections.emptyMap();
	}
	Map<String, Object> conf = new HashMap<>();
	conf.put(STRICT_PROPERTY_KEY, true);
	conf.put(DEBUG_PROPERTY_KEY, !Config.IN_PRODUCTION);

	// SP
	String spEntityId = getConfigProp(app, SP_ENTITYID_PROPERTY_KEY, "");
	String spACS = getConfigProp(app, SP_ASSERTION_CONSUMER_SERVICE_URL_PROPERTY_KEY, spEntityId);
	conf.put(SP_ENTITYID_PROPERTY_KEY, spEntityId);
	conf.put(SP_ASSERTION_CONSUMER_SERVICE_URL_PROPERTY_KEY, StringUtils.isBlank(spACS) ? spEntityId : spACS);
	conf.put(SP_NAMEIDFORMAT_PROPERTY_KEY,
			getConfigProp(app, SP_NAMEIDFORMAT_PROPERTY_KEY, Constants.NAMEID_UNSPECIFIED));
	conf.put(SP_X509CERT_PROPERTY_KEY, Utils.base64dec(getConfigProp(app, SP_X509CERT_PROPERTY_KEY, "")));
	conf.put(SP_PRIVATEKEY_PROPERTY_KEY, Utils.base64dec(getConfigProp(app, SP_PRIVATEKEY_PROPERTY_KEY, "")));

	// IDP
	String entityId = getConfigProp(app, IDP_ENTITYID_PROPERTY_KEY, "");
	String ssoServiceUrl = getConfigProp(app, IDP_SINGLE_SIGN_ON_SERVICE_URL_PROPERTY_KEY, "");
	String idpCert = Utils.base64dec(getConfigProp(app, IDP_X509CERT_PROPERTY_KEY, ""));
	if (!StringUtils.isBlank(entityId)) {
		conf.put(IDP_ENTITYID_PROPERTY_KEY, entityId);
	}
	if (!StringUtils.isBlank(ssoServiceUrl)) {
		conf.put(IDP_SINGLE_SIGN_ON_SERVICE_URL_PROPERTY_KEY, ssoServiceUrl);
	}
	if (!StringUtils.isBlank(idpCert)) {
		conf.put(IDP_X509CERT_PROPERTY_KEY, idpCert);
	}

	// Security
	conf.put(SECURITY_AUTHREQUEST_SIGNED, getConfigPropBool(app, SECURITY_AUTHREQUEST_SIGNED, false));
	conf.put(SECURITY_WANT_MESSAGES_SIGNED, getConfigPropBool(app, SECURITY_WANT_MESSAGES_SIGNED, false));
	conf.put(SECURITY_WANT_ASSERTIONS_SIGNED, getConfigPropBool(app, SECURITY_WANT_ASSERTIONS_SIGNED, false));
	conf.put(SECURITY_WANT_ASSERTIONS_ENCRYPTED, getConfigPropBool(app, SECURITY_WANT_ASSERTIONS_ENCRYPTED, false));
	conf.put(SECURITY_WANT_NAMEID_ENCRYPTED, getConfigPropBool(app, SECURITY_WANT_NAMEID_ENCRYPTED, false));
	conf.put(SECURITY_SIGN_METADATA, getConfigPropBool(app, SECURITY_SIGN_METADATA, false));
	conf.put(SECURITY_WANT_XML_VALIDATION, getConfigPropBool(app, SECURITY_WANT_XML_VALIDATION, true));
	conf.put(SECURITY_SIGNATURE_ALGORITHM, getConfigProp(app, SECURITY_SIGNATURE_ALGORITHM, ""));

	return conf;
}