Class SettingsBuilder


  • public class SettingsBuilder
    extends java.lang.Object
    SettingsBuilder class of OneLogin's Java Toolkit. A class that implements the settings builder
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
        Private property to construct a logger for this class.
      • samlData

        private java.util.Map<java.lang.String,​java.lang.Object> samlData
        Private property that contains the SAML settings
      • saml2Setting

        private Saml2Settings saml2Setting
        Saml2Settings object
      • STRICT_PROPERTY_KEY

        public static final java.lang.String STRICT_PROPERTY_KEY
        See Also:
        Constant Field Values
      • DEBUG_PROPERTY_KEY

        public static final java.lang.String DEBUG_PROPERTY_KEY
        See Also:
        Constant Field Values
      • SP_ENTITYID_PROPERTY_KEY

        public static final java.lang.String SP_ENTITYID_PROPERTY_KEY
        See Also:
        Constant Field Values
      • SP_ASSERTION_CONSUMER_SERVICE_URL_PROPERTY_KEY

        public static final java.lang.String SP_ASSERTION_CONSUMER_SERVICE_URL_PROPERTY_KEY
        See Also:
        Constant Field Values
      • SP_ASSERTION_CONSUMER_SERVICE_BINDING_PROPERTY_KEY

        public static final java.lang.String SP_ASSERTION_CONSUMER_SERVICE_BINDING_PROPERTY_KEY
        See Also:
        Constant Field Values
      • SP_SINGLE_LOGOUT_SERVICE_URL_PROPERTY_KEY

        public static final java.lang.String SP_SINGLE_LOGOUT_SERVICE_URL_PROPERTY_KEY
        See Also:
        Constant Field Values
      • SP_SINGLE_LOGOUT_SERVICE_BINDING_PROPERTY_KEY

        public static final java.lang.String SP_SINGLE_LOGOUT_SERVICE_BINDING_PROPERTY_KEY
        See Also:
        Constant Field Values
      • SP_NAMEIDFORMAT_PROPERTY_KEY

        public static final java.lang.String SP_NAMEIDFORMAT_PROPERTY_KEY
        See Also:
        Constant Field Values
      • SP_X509CERT_PROPERTY_KEY

        public static final java.lang.String SP_X509CERT_PROPERTY_KEY
        See Also:
        Constant Field Values
      • SP_PRIVATEKEY_PROPERTY_KEY

        public static final java.lang.String SP_PRIVATEKEY_PROPERTY_KEY
        See Also:
        Constant Field Values
      • SP_X509CERTNEW_PROPERTY_KEY

        public static final java.lang.String SP_X509CERTNEW_PROPERTY_KEY
        See Also:
        Constant Field Values
      • SP_CONTACT_PROPERTY_KEY_PREFIX

        public static final java.lang.String SP_CONTACT_PROPERTY_KEY_PREFIX
        See Also:
        Constant Field Values
      • SP_CONTACT_CONTACT_TYPE_PROPERTY_KEY_SUFFIX

        public static final java.lang.String SP_CONTACT_CONTACT_TYPE_PROPERTY_KEY_SUFFIX
        See Also:
        Constant Field Values
      • SP_CONTACT_COMPANY_PROPERTY_KEY_SUFFIX

        public static final java.lang.String SP_CONTACT_COMPANY_PROPERTY_KEY_SUFFIX
        See Also:
        Constant Field Values
      • SP_CONTACT_GIVEN_NAME_PROPERTY_KEY_SUFFIX

        public static final java.lang.String SP_CONTACT_GIVEN_NAME_PROPERTY_KEY_SUFFIX
        See Also:
        Constant Field Values
      • SP_CONTACT_SUR_NAME_PROPERTY_KEY_SUFFIX

        public static final java.lang.String SP_CONTACT_SUR_NAME_PROPERTY_KEY_SUFFIX
        See Also:
        Constant Field Values
      • SP_CONTACT_EMAIL_ADDRESS_PROPERTY_KEY_PREFIX

        public static final java.lang.String SP_CONTACT_EMAIL_ADDRESS_PROPERTY_KEY_PREFIX
        See Also:
        Constant Field Values
      • SP_CONTACT_TELEPHONE_NUMBER_PROPERTY_KEY_PREFIX

        public static final java.lang.String SP_CONTACT_TELEPHONE_NUMBER_PROPERTY_KEY_PREFIX
        See Also:
        Constant Field Values
      • KEYSTORE_KEY_PASSWORD

        public static final java.lang.String KEYSTORE_KEY_PASSWORD
        See Also:
        Constant Field Values
      • IDP_ENTITYID_PROPERTY_KEY

        public static final java.lang.String IDP_ENTITYID_PROPERTY_KEY
        See Also:
        Constant Field Values
      • IDP_SINGLE_SIGN_ON_SERVICE_URL_PROPERTY_KEY

        public static final java.lang.String IDP_SINGLE_SIGN_ON_SERVICE_URL_PROPERTY_KEY
        See Also:
        Constant Field Values
      • IDP_SINGLE_SIGN_ON_SERVICE_BINDING_PROPERTY_KEY

        public static final java.lang.String IDP_SINGLE_SIGN_ON_SERVICE_BINDING_PROPERTY_KEY
        See Also:
        Constant Field Values
      • IDP_SINGLE_LOGOUT_SERVICE_URL_PROPERTY_KEY

        public static final java.lang.String IDP_SINGLE_LOGOUT_SERVICE_URL_PROPERTY_KEY
        See Also:
        Constant Field Values
      • IDP_SINGLE_LOGOUT_SERVICE_RESPONSE_URL_PROPERTY_KEY

        public static final java.lang.String IDP_SINGLE_LOGOUT_SERVICE_RESPONSE_URL_PROPERTY_KEY
        See Also:
        Constant Field Values
      • IDP_SINGLE_LOGOUT_SERVICE_BINDING_PROPERTY_KEY

        public static final java.lang.String IDP_SINGLE_LOGOUT_SERVICE_BINDING_PROPERTY_KEY
        See Also:
        Constant Field Values
      • IDP_X509CERT_PROPERTY_KEY

        public static final java.lang.String IDP_X509CERT_PROPERTY_KEY
        See Also:
        Constant Field Values
      • IDP_X509CERTMULTI_PROPERTY_KEY

        public static final java.lang.String IDP_X509CERTMULTI_PROPERTY_KEY
        See Also:
        Constant Field Values
      • CERTFINGERPRINT_PROPERTY_KEY

        public static final java.lang.String CERTFINGERPRINT_PROPERTY_KEY
        See Also:
        Constant Field Values
      • CERTFINGERPRINT_ALGORITHM_PROPERTY_KEY

        public static final java.lang.String CERTFINGERPRINT_ALGORITHM_PROPERTY_KEY
        See Also:
        Constant Field Values
      • SECURITY_NAMEID_ENCRYPTED

        public static final java.lang.String SECURITY_NAMEID_ENCRYPTED
        See Also:
        Constant Field Values
      • SECURITY_AUTHREQUEST_SIGNED

        public static final java.lang.String SECURITY_AUTHREQUEST_SIGNED
        See Also:
        Constant Field Values
      • SECURITY_LOGOUTREQUEST_SIGNED

        public static final java.lang.String SECURITY_LOGOUTREQUEST_SIGNED
        See Also:
        Constant Field Values
      • SECURITY_LOGOUTRESPONSE_SIGNED

        public static final java.lang.String SECURITY_LOGOUTRESPONSE_SIGNED
        See Also:
        Constant Field Values
      • SECURITY_WANT_MESSAGES_SIGNED

        public static final java.lang.String SECURITY_WANT_MESSAGES_SIGNED
        See Also:
        Constant Field Values
      • SECURITY_WANT_ASSERTIONS_SIGNED

        public static final java.lang.String SECURITY_WANT_ASSERTIONS_SIGNED
        See Also:
        Constant Field Values
      • SECURITY_WANT_ASSERTIONS_ENCRYPTED

        public static final java.lang.String SECURITY_WANT_ASSERTIONS_ENCRYPTED
        See Also:
        Constant Field Values
      • SECURITY_WANT_NAMEID

        public static final java.lang.String SECURITY_WANT_NAMEID
        See Also:
        Constant Field Values
      • SECURITY_WANT_NAMEID_ENCRYPTED

        public static final java.lang.String SECURITY_WANT_NAMEID_ENCRYPTED
        See Also:
        Constant Field Values
      • SECURITY_SIGN_METADATA

        public static final java.lang.String SECURITY_SIGN_METADATA
        See Also:
        Constant Field Values
      • SECURITY_REQUESTED_AUTHNCONTEXT

        public static final java.lang.String SECURITY_REQUESTED_AUTHNCONTEXT
        See Also:
        Constant Field Values
      • SECURITY_REQUESTED_AUTHNCONTEXTCOMPARISON

        public static final java.lang.String SECURITY_REQUESTED_AUTHNCONTEXTCOMPARISON
        See Also:
        Constant Field Values
      • SECURITY_WANT_XML_VALIDATION

        public static final java.lang.String SECURITY_WANT_XML_VALIDATION
        See Also:
        Constant Field Values
      • SECURITY_SIGNATURE_ALGORITHM

        public static final java.lang.String SECURITY_SIGNATURE_ALGORITHM
        See Also:
        Constant Field Values
      • SECURITY_DIGEST_ALGORITHM

        public static final java.lang.String SECURITY_DIGEST_ALGORITHM
        See Also:
        Constant Field Values
      • SECURITY_REJECT_UNSOLICITED_RESPONSES_WITH_INRESPONSETO

        public static final java.lang.String SECURITY_REJECT_UNSOLICITED_RESPONSES_WITH_INRESPONSETO
        See Also:
        Constant Field Values
      • SECURITY_ALLOW_REPEAT_ATTRIBUTE_NAME_PROPERTY_KEY

        public static final java.lang.String SECURITY_ALLOW_REPEAT_ATTRIBUTE_NAME_PROPERTY_KEY
        See Also:
        Constant Field Values
      • SECURITY_REJECT_DEPRECATED_ALGORITHM

        public static final java.lang.String SECURITY_REJECT_DEPRECATED_ALGORITHM
        See Also:
        Constant Field Values
      • COMPRESS_REQUEST

        public static final java.lang.String COMPRESS_REQUEST
        See Also:
        Constant Field Values
      • COMPRESS_RESPONSE

        public static final java.lang.String COMPRESS_RESPONSE
        See Also:
        Constant Field Values
      • PARSING_TRIM_NAME_IDS

        public static final java.lang.String PARSING_TRIM_NAME_IDS
        See Also:
        Constant Field Values
      • PARSING_TRIM_ATTRIBUTE_VALUES

        public static final java.lang.String PARSING_TRIM_ATTRIBUTE_VALUES
        See Also:
        Constant Field Values
      • CONTACT_TECHNICAL_GIVEN_NAME

        @Deprecated
        public static final java.lang.String CONTACT_TECHNICAL_GIVEN_NAME
        Deprecated.
        See Also:
        Constant Field Values
      • CONTACT_TECHNICAL_EMAIL_ADDRESS

        @Deprecated
        public static final java.lang.String CONTACT_TECHNICAL_EMAIL_ADDRESS
        Deprecated.
        See Also:
        Constant Field Values
      • CONTACT_SUPPORT_GIVEN_NAME

        @Deprecated
        public static final java.lang.String CONTACT_SUPPORT_GIVEN_NAME
        Deprecated.
        See Also:
        Constant Field Values
      • CONTACT_SUPPORT_EMAIL_ADDRESS

        @Deprecated
        public static final java.lang.String CONTACT_SUPPORT_EMAIL_ADDRESS
        Deprecated.
        See Also:
        Constant Field Values
      • ORGANIZATION_NAME

        public static final java.lang.String ORGANIZATION_NAME
        See Also:
        Constant Field Values
      • ORGANIZATION_DISPLAYNAME

        public static final java.lang.String ORGANIZATION_DISPLAYNAME
        See Also:
        Constant Field Values
      • ORGANIZATION_URL

        public static final java.lang.String ORGANIZATION_URL
        See Also:
        Constant Field Values
      • ORGANIZATION_LANG

        public static final java.lang.String ORGANIZATION_LANG
        See Also:
        Constant Field Values
      • UNIQUE_ID_PREFIX_PROPERTY_KEY

        public static final java.lang.String UNIQUE_ID_PREFIX_PROPERTY_KEY
        See Also:
        Constant Field Values
    • Constructor Detail

      • SettingsBuilder

        public SettingsBuilder()
    • Method Detail

      • fromFile

        public SettingsBuilder fromFile​(java.lang.String propFileName)
                                 throws Error,
                                        java.io.IOException
        Load settings from the file
        Parameters:
        propFileName - OneLogin_Saml2_Settings
        Returns:
        the SettingsBuilder object with the settings loaded from the file
        Throws:
        java.io.IOException
        Error
      • fromFile

        public SettingsBuilder fromFile​(java.lang.String propFileName,
                                        KeyStoreSettings keyStoreSetting)
                                 throws Error,
                                        java.io.IOException
        Load settings from the file
        Parameters:
        propFileName - OneLogin_Saml2_Settings
        keyStoreSetting - KeyStore which have the Private/Public keys
        Returns:
        the SettingsBuilder object with the settings loaded from the file
        Throws:
        java.io.IOException
        Error
      • fromProperties

        public SettingsBuilder fromProperties​(java.util.Properties prop)
        Loads the settings from a properties object
        Parameters:
        prop - contains the properties
        Returns:
        the SettingsBuilder object with the settings loaded from the prop object
      • fromValues

        public SettingsBuilder fromValues​(java.util.Map<java.lang.String,​java.lang.Object> samlData)
        Loads the settings from mapped values.
        Parameters:
        samlData - Mapped values.
        Returns:
        the SettingsBuilder object with the settings loaded from the prop object
      • fromValues

        public SettingsBuilder fromValues​(java.util.Map<java.lang.String,​java.lang.Object> samlData,
                                          KeyStoreSettings keyStoreSetting)
        Loads the settings from mapped values and KeyStore settings.
        Parameters:
        samlData - Mapped values.
        keyStoreSetting - KeyStore model
        Returns:
        the SettingsBuilder object with the settings loaded from the prop object
      • build

        public Saml2Settings build()
        Builds the Saml2Settings object. Read the Properties object and set all the SAML settings
        Returns:
        the Saml2Settings object with all the SAML settings loaded
      • build

        public Saml2Settings build​(Saml2Settings saml2Setting)
        Builds the Saml2Settings object. Read the Properties object and set all the SAML settings
        Parameters:
        saml2Setting - an existing Saml2Settings
        Returns:
        the Saml2Settings object with all the SAML settings loaded
      • loadIdpSetting

        private void loadIdpSetting()
        Loads the IdP settings from the properties file
      • loadSecuritySetting

        private void loadSecuritySetting()
        Loads the security settings from the properties file
      • loadCompressSetting

        private void loadCompressSetting()
        Loads the compress settings from the properties file
      • loadParsingSetting

        private void loadParsingSetting()
        Loads the parsing settings from the properties file
      • loadOrganization

        private Organization loadOrganization()
        Loads the organization settings from the properties file
      • loadContacts

        private java.util.List<Contact> loadContacts()
        Loads the contacts settings from the properties file
        Returns:
        a list containing all the loaded contacts
      • loadContact

        private Contact loadContact​(java.util.Map<java.lang.String,​java.lang.Object> contactProps,
                                    int index)
        Loads a single contact from settings.
        Parameters:
        contactProps - a map containing the contact settings
        index - the contact index
        Returns:
        the loaded contact
      • extractIndexedProperties

        private java.util.SortedMap<java.lang.Integer,​java.util.Map<java.lang.String,​java.lang.Object>> extractIndexedProperties​(java.lang.String prefix,
                                                                                                                                             java.util.Map<java.lang.String,​java.lang.Object> data)
        Given a map containing settings data, extracts all the indexed properties identified by a given prefix. The returned map has indexes as keys and a map describing the extracted indexed data as values. Keys are sorted by their natural order (i.e. iterating over the map will return entries in index order).

        For instance, if the prefix is foo, all the following properties will be extracted:

         foo[0].prop1=<value1>
         foo[0].prop2=<value2>
         foo[1].prop1=<value3>
         
        and the returned map will be:
         0 => prop1=<value1>
              prop2=<value2>
         1 => prop1=<value3>
         
        The index is optional: if missing, "-1" is returned. In other words, in the above example:
         foo.prop1=<value1>
         foo.prop2=<value2>
         
        will be mapped to:
         -1 => prop1=<value1>
               prop2=<value2>
         
        Indices can be made of maximum 9 digits, to prevent overflows. Leading zeroes are discarded.
        Parameters:
        prefix - the prefix that identifies the indexed property to extract
        data - the input data
        Returns:
        a map with extracted data for each identified index
      • extractIndexedValues

        private java.util.SortedMap<java.lang.Integer,​java.lang.Object> extractIndexedValues​(java.lang.String prefix,
                                                                                                   java.util.Map<java.lang.String,​java.lang.Object> data)
        Given a map containing settings data, extracts all the indexed values identified by a given prefix. The returned map has indexes as keys and the corresponding values as values. Keys are sorted by their natural order (i.e. iterating over the map will return entries in index order).

        For instance, if the prefix is foo, all the following values will be extracted:

         foo[0]=<value1>
         foo[1]=<value2>
         foo[2]=<value3>
         
        and the returned map will be:
         0 => <value1>
         1 => <value2>
         3 => <value3>
         
        The index is optional: if missing, "-1" is returned. In other words, in the above example:
         foo=<value1>
         
        will be mapped to:
         -1 => <value1>
         
        Indices can be made of maximum 9 digits, to prevent overflows. Leading zeroes are discarded.
        Parameters:
        prefix - the prefix that identifies the indexed property to extract
        data - the input data
        Returns:
        a map with extracted values for each identified index
      • toStringList

        private java.util.List<java.lang.String> toStringList​(java.util.Map<java.lang.Integer,​java.lang.Object> indexedValues)
        Given a map of indexed property values (possibly extracted with extractIndexedValues(String, Map)), returns a list containing all the String values contained in the map, sorted by their iteration order.
        Parameters:
        indexedValues - a map containing indexed values (key = index; value = actual value)
        Returns:
        a list containing all the string values in the input map, sorted by their iteration order; therefore, if the map is a SortedMap, the returned list has values sorted by their index
      • loadUniqueIDPrefix

        private java.lang.String loadUniqueIDPrefix()
        Loads the unique ID prefix. Uses default if property not set.
      • loadSpSetting

        private void loadSpSetting()
        Loads the SP settings from the properties file
      • loadStringProperty

        private java.lang.String loadStringProperty​(java.lang.String propertyKey)
        Loads a property of the type String from the Properties object
        Parameters:
        propertyKey - the property name
        Returns:
        the value
      • loadStringProperty

        private java.lang.String loadStringProperty​(java.lang.String propertyKey,
                                                    java.util.Map<java.lang.String,​java.lang.Object> data)
        Loads a property of the type String from the specified data
        Parameters:
        propertyKey - the property name
        data - the input data
        Returns:
        the value
      • loadBooleanProperty

        private java.lang.Boolean loadBooleanProperty​(java.lang.String propertyKey)
        Loads a property of the type Boolean from the Properties object
        Parameters:
        propertyKey - the property name
        Returns:
        the value
      • loadListProperty

        private java.util.List<java.lang.String> loadListProperty​(java.lang.String propertyKey)
        Loads a property of the type List from the Properties object
        Parameters:
        propertyKey - the property name
        Returns:
        the value
      • loadURLProperty

        private java.net.URL loadURLProperty​(java.lang.String propertyKey)
        Loads a property of the type URL from the Properties object
        Parameters:
        propertyKey - the property name
        Returns:
        the value
      • getPrivateKeyFromKeyStore

        protected java.security.PrivateKey getPrivateKeyFromKeyStore​(java.security.KeyStore keyStore,
                                                                     java.lang.String alias,
                                                                     java.lang.String password)
      • getCertificateFromKeyStore

        protected java.security.cert.X509Certificate getCertificateFromKeyStore​(java.security.KeyStore keyStore,
                                                                                java.lang.String alias,
                                                                                java.lang.String password)
      • loadCertificateFromProp

        protected java.security.cert.X509Certificate loadCertificateFromProp​(java.lang.Object propValue)
        Loads a property of the type X509Certificate from the property value
        Parameters:
        propValue - the property value
        Returns:
        the X509Certificate object
      • loadCertificateFromProp

        protected java.security.cert.X509Certificate loadCertificateFromProp​(java.lang.String propertyKey)
        Loads a property of the type X509Certificate from the Properties object
        Parameters:
        propertyKey - the property name
        Returns:
        the X509Certificate object
      • loadCertificateListFromProp

        private java.util.List<java.security.cert.X509Certificate> loadCertificateListFromProp​(java.lang.String propertyKey)
        Loads a property of the type List of X509Certificate from the Properties object
        Parameters:
        propertyKey - the property name
        Returns:
        the X509Certificate object list
      • loadPrivateKeyFromProp

        protected java.security.PrivateKey loadPrivateKeyFromProp​(java.lang.String propertyKey)
        Loads a property of the type PrivateKey from the Properties object
        Parameters:
        propertyKey - the property name
        Returns:
        the PrivateKey object
      • parseProperties

        private void parseProperties​(java.util.Properties properties)
        Parses properties
        Parameters:
        properties - the Properties object to be parsed
      • parseKeyStore

        private void parseKeyStore​(KeyStoreSettings setting)
        Parses the KeyStore data
        Parameters:
        setting - the KeyStoreSettings object to be parsed
      • isString

        private boolean isString​(java.lang.Object propValue)
        Aux method that verifies if an Object is an string
        Parameters:
        propValue - the Object to be verified