Class SettingsBuilder

java.lang.Object
com.onelogin.saml2.settings.SettingsBuilder

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

  • Constructor Details

    • SettingsBuilder

      public SettingsBuilder()
  • Method Details

    • fromFile

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

      public SettingsBuilder fromFile(String propFileName, KeyStoreSettings keyStoreSetting) throws Error, 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:
      IOException
      Error
    • fromProperties

      public SettingsBuilder fromProperties(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(Map<String,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(Map<String,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 List<Contact> loadContacts()
      Loads the contacts settings from the properties file
      Returns:
      a list containing all the loaded contacts
    • loadContact

      private Contact loadContact(Map<String,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 SortedMap<Integer,Map<String,Object>> extractIndexedProperties(String prefix, Map<String,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 SortedMap<Integer,Object> extractIndexedValues(String prefix, Map<String,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 List<String> toStringList(Map<Integer,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 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 String loadStringProperty(String propertyKey)
      Loads a property of the type String from the Properties object
      Parameters:
      propertyKey - the property name
      Returns:
      the value
    • loadStringProperty

      private String loadStringProperty(String propertyKey, Map<String,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 Boolean loadBooleanProperty(String propertyKey)
      Loads a property of the type Boolean from the Properties object
      Parameters:
      propertyKey - the property name
      Returns:
      the value
    • loadListProperty

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

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

      protected PrivateKey getPrivateKeyFromKeyStore(KeyStore keyStore, String alias, String password)
    • getCertificateFromKeyStore

      protected X509Certificate getCertificateFromKeyStore(KeyStore keyStore, String alias, String password)
    • loadCertificateFromProp

      protected X509Certificate loadCertificateFromProp(Object propValue)
      Loads a property of the type X509Certificate from the property value
      Parameters:
      propValue - the property value
      Returns:
      the X509Certificate object
    • loadCertificateFromProp

      protected X509Certificate loadCertificateFromProp(String propertyKey)
      Loads a property of the type X509Certificate from the Properties object
      Parameters:
      propertyKey - the property name
      Returns:
      the X509Certificate object
    • loadCertificateListFromProp

      private List<X509Certificate> loadCertificateListFromProp(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 PrivateKey loadPrivateKeyFromProp(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(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(Object propValue)
      Aux method that verifies if an Object is an string
      Parameters:
      propValue - the Object to be verified