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:
ConfigParams, ConnectionParams, CredentialResolver, ICredentialStore, Serialized Form
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.util.AbstractMap

    AbstractMap.SimpleEntry<K extends Object,​V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,​V extends Object>

    Nested classes/interfaces inherited from interface java.util.Map

    Map.Entry<K extends Object,​V extends Object>
  • Constructor Summary

    Constructors
    Constructor Description
    CredentialParams()
    Creates an empty instance of credential parameters.
    CredentialParams​(Map<?,​?> map)
    Creates a new CredentialParams and fills it with values.
  • Method Summary

    Modifier and Type Method Description
    static CredentialParams fromConfig​(org.pipservices3.commons.config.ConfigParams config)
    Retrieves a single CredentialParams from configuration parameters from "credential" section.
    static CredentialParams fromConfig​(org.pipservices3.commons.config.ConfigParams config, boolean configAsDefault)
    Retrieves a single CredentialParams from configuration parameters from "credential" section.
    static CredentialParams fromString​(String line)
    Creates a new CredentialParams object filled with key-value pairs serialized as a string.
    String getAccessId()
    Gets the application access id.
    String getAccessKey()
    Gets the application secret key.
    String getPassword()
    Get the user password.
    String getStoreKey()
    Gets the key to retrieve these credentials from CredentialStore.
    String getUsername()
    Gets the user name.
    static List<CredentialParams> manyFromConfig​(org.pipservices3.commons.config.ConfigParams config)
    Retrieves all CredentialParams from configuration parameters from "credentials" section.
    static List<CredentialParams> manyFromConfig​(org.pipservices3.commons.config.ConfigParams config, boolean configAsDefault)
    Retrieves all CredentialParams from configuration parameters from "credentials" section.
    void setAccessId​(String value)
    Sets the application access id.
    void setAccessKey​(String value)
    Sets the application secret key.
    void setPassword​(String password)
    Sets the user password.
    void setStoreKey​(String value)
    Sets the key to retrieve these parameters from CredentialStore.
    void setUsername​(String value)
    Sets the user name.
    boolean useCredentialStore()
    Checks if these credential parameters shall be retrieved from CredentialStore.

    Methods inherited from class org.pipservices3.commons.config.ConfigParams

    addSection, fromTuples, fromValue, getSection, getSectionNames, mergeConfigs, override, setDefaults

    Methods inherited from class org.pipservices3.commons.data.StringValueMap

    append, clone, fromMaps, fromTuplesArray, get, getAsArray, getAsArrayWithDefault, getAsBoolean, getAsBooleanWithDefault, getAsDateTime, getAsDateTimeWithDefault, getAsDouble, getAsDoubleWithDefault, getAsDuration, getAsDurationWithDefault, getAsEnum, getAsEnumWithDefault, getAsFloat, getAsFloatWithDefault, getAsInteger, getAsIntegerWithDefault, getAsLong, getAsLongWithDefault, getAsMap, getAsMapWithDefault, getAsNullableArray, getAsNullableBoolean, getAsNullableDateTime, getAsNullableDouble, getAsNullableDuration, getAsNullableEnum, getAsNullableFloat, getAsNullableInteger, getAsNullableLong, getAsNullableMap, getAsNullableString, getAsNullableType, getAsObject, getAsObject, getAsString, getAsStringWithDefault, getAsType, getAsTypeWithDefault, getAsValue, setAsObject, setAsObject, toString

    Methods inherited from class java.util.AbstractMap

    equals, hashCode

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Map

    equals, hashCode
  • 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()
    • 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:
      useCredentialStore()
    • 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:
      manyFromConfig(ConfigParams, boolean)
    • 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:
      manyFromConfig(org.pipservices3.commons.config.ConfigParams,boolean)