Class CredentialParams

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,String>
org.pipservices3.commons.data.StringValueMap
org.pipservices3.commons.config.ConfigParams
org.pipservices3.components.auth.CredentialParams
All Implemented Interfaces:
Serializable, Cloneable, Map<String,String>

public class CredentialParams extends org.pipservices3.commons.config.ConfigParams
Contains credentials to authenticate against external services. They are used together with connection parameters, but usually stored in a separate store, protected from unauthorized access.

### Configuration parameters ###

  • store_key: key to retrieve parameters from credential store
  • username: user name
  • user: alternative to username
  • password: user password
  • pass: alternative to password
  • access_id: application access id
  • client_id: alternative to access_id
  • access_key: application secret key
  • client_key: alternative to access_key
  • secret_key: alternative to access_key

In addition to standard parameters CredentialParams may contain any number of custom parameters

### Example ###

 
 CredentialParams credential = CredentialParams.fromTuples(
  "user", "jdoe",
  "pass", "pass123",
  "pin", "321"
 );

 String username = credential.getUsername();             // Result: "jdoe"
 String password = credential.getPassword();             // Result: "pass123"
 int pin = credential.getAsNullableString("pin");     // Result: 321
 
 
See Also:
  • Constructor Details

    • CredentialParams

      public CredentialParams()
      Creates an empty instance of credential parameters.
    • CredentialParams

      public CredentialParams(Map<?,?> map)
      Creates a new CredentialParams and fills it with values.
      Parameters:
      map - (optional) an object to be converted into key-value pairs to initialize these credentials.
  • Method Details

    • useCredentialStore

      public boolean useCredentialStore()
      Checks if these credential parameters shall be retrieved from CredentialStore. The credential parameters are redirected to CredentialStore when store_key parameter is set.
      Returns:
      true if credentials shall be retrieved from CredentialStore
      See Also:
    • getStoreKey

      public String getStoreKey()
      Gets the key to retrieve these credentials from CredentialStore. If this key is null, than all parameters are already present.
      Returns:
      the store key to retrieve credentials.
      See Also:
    • setStoreKey

      public void setStoreKey(String value)
      Sets the key to retrieve these parameters from CredentialStore.
      Parameters:
      value - a new key to retrieve credentials.
    • getUsername

      public String getUsername()
      Gets the user name. The value can be stored in parameters "username" or "user".
      Returns:
      the user name.
    • setUsername

      public void setUsername(String value)
      Sets the user name.
      Parameters:
      value - a new user name.
    • getPassword

      public String getPassword()
      Get the user password. The value can be stored in parameters "password" or "pass".
      Returns:
      the user password.
    • setPassword

      public void setPassword(String password)
      Sets the user password.
      Parameters:
      password - a new user password.
    • getAccessId

      public String getAccessId()
      Gets the application access id. The value can be stored in parameters "access_id" pr "client_id"
      Returns:
      the application access id.
    • setAccessId

      public void setAccessId(String value)
      Sets the application access id.
      Parameters:
      value - a new application access id.
    • getAccessKey

      public String getAccessKey()
      Gets the application secret key. The value can be stored in parameters "access_key", "client_key" or "secret_key".
      Returns:
      the application secret key.
    • setAccessKey

      public void setAccessKey(String value)
      Sets the application secret key.
      Parameters:
      value - a new application secret key.
    • fromString

      public static CredentialParams fromString(String line)
      Creates a new CredentialParams object filled with key-value pairs serialized as a string.
      Parameters:
      line - a string with serialized key-value pairs as "key1=value1;key2=value2;..." Example: "Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z"
      Returns:
      a new CredentialParams object.
    • manyFromConfig

      public static List<CredentialParams> manyFromConfig(org.pipservices3.commons.config.ConfigParams config, boolean configAsDefault)
      Retrieves all CredentialParams from configuration parameters from "credentials" section. If "credential" section is present instead, than it returns a list with only one CredentialParams.
      Parameters:
      config - a configuration parameters to retrieve credentials
      configAsDefault - boolean parameter for default configuration. If "true" the default value will be added to the result.
      Returns:
      a list of retrieved CredentialParams
    • manyFromConfig

      public static List<CredentialParams> manyFromConfig(org.pipservices3.commons.config.ConfigParams config)
      Retrieves all CredentialParams from configuration parameters from "credentials" section. If "credential" section is present instead, than it returns a list with only one CredentialParams.
      Parameters:
      config - a configuration parameters to retrieve credentials
      Returns:
      a list of retrieved CredentialParams
    • fromConfig

      public static CredentialParams fromConfig(org.pipservices3.commons.config.ConfigParams config, boolean configAsDefault)
      Retrieves a single CredentialParams from configuration parameters from "credential" section. If "credentials" section is present instead, then is returns only the first credential element.
      Parameters:
      config - ConfigParams, containing a section named "credential(s)".
      configAsDefault - boolean parameter for default configuration. If "true" the default value will be added to the result.
      Returns:
      the generated CredentialParams object.
      See Also:
    • fromConfig

      public static CredentialParams fromConfig(org.pipservices3.commons.config.ConfigParams config)
      Retrieves a single CredentialParams from configuration parameters from "credential" section. If "credentials" section is present instead, then is returns only the first credential element.
      Parameters:
      config - ConfigParams, containing a section named "credential(s)".
      Returns:
      the generated CredentialParams object.
      See Also:
    • fromValue

      public static CredentialParams fromValue(Object value)
      Creates a new CredentialParams object filled with key-value pairs from specified object.
      Parameters:
      value - an object with key-value pairs used to initialize a new ConfigParams.
      Returns:
      a new CredentialParams object.
      See Also:
      • RecursiveObjectReader.getProperties(Object)
    • fromTuples

      public static CredentialParams fromTuples(Object... tuples)
      Creates a new CredentialParams object filled with provided key-value pairs called tuples. Tuples parameters contain a sequence of key1, value1, key2, value2, ... pairs.
      Parameters:
      tuples - the tuples to fill a new ConfigParams object.
      Returns:
      a new CredentialParams object.
      See Also:
      • StringValueMap.fromTuplesArray(Object[])
    • mergeConfigs

      public static CredentialParams mergeConfigs(org.pipservices3.commons.config.ConfigParams... configs)
      Merges two or more CredentialParams into one. The following ConfigParams override previously defined parameters.
      Parameters:
      configs - a list of CredentialParams objects to be merged.
      Returns:
      a new CredentialParams object.
      See Also:
      • StringValueMap.fromMaps(Map...)
    • mergeConfigs

      public static CredentialParams mergeConfigs(List<org.pipservices3.commons.config.ConfigParams> configs)
      Merges two or more CredentialParams into one. The following ConfigParams override previously defined parameters.
      Parameters:
      configs - a list of CredentialParams objects to be merged.
      Returns:
      a new CredentialParams object.
      See Also:
      • StringValueMap.fromMaps(Map...)