Package org.pipservices3.components.auth
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:
-
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> -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty instance of credential parameters.CredentialParams(Map<?, ?> map) Creates a new CredentialParams and fills it with values. -
Method Summary
Modifier and TypeMethodDescriptionstatic CredentialParamsfromConfig(org.pipservices3.commons.config.ConfigParams config) Retrieves a single CredentialParams from configuration parameters from "credential" section.static CredentialParamsfromConfig(org.pipservices3.commons.config.ConfigParams config, boolean configAsDefault) Retrieves a single CredentialParams from configuration parameters from "credential" section.static CredentialParamsfromString(String line) Creates a new CredentialParams object filled with key-value pairs serialized as a string.static CredentialParamsfromTuples(Object... tuples) Creates a new CredentialParams object filled with provided key-value pairs called tuples.static CredentialParamsCreates a new CredentialParams object filled with key-value pairs from specified object.Gets the application access id.Gets the application secret key.Get the user password.Gets the key to retrieve these credentials from CredentialStore.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.static CredentialParamsmergeConfigs(List<org.pipservices3.commons.config.ConfigParams> configs) Merges two or more CredentialParams into one.static CredentialParamsmergeConfigs(org.pipservices3.commons.config.ConfigParams... configs) Merges two or more CredentialParams into one.voidsetAccessId(String value) Sets the application access id.voidsetAccessKey(String value) Sets the application secret key.voidsetPassword(String password) Sets the user password.voidsetStoreKey(String value) Sets the key to retrieve these parameters from CredentialStore.voidsetUsername(String value) Sets the user name.booleanChecks if these credential parameters shall be retrieved from CredentialStore.Methods inherited from class org.pipservices3.commons.config.ConfigParams
addSection, getSection, getSectionNames, override, setDefaultsMethods 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, getKeys, length, put, setAsObject, setAsObject, toStringMethods inherited from class java.util.HashMap
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class java.util.AbstractMap
equals, hashCode
-
Constructor Details
-
CredentialParams
public CredentialParams()Creates an empty instance of credential parameters. -
CredentialParams
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
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
Sets the key to retrieve these parameters from CredentialStore.- Parameters:
value- a new key to retrieve credentials.
-
getUsername
Gets the user name. The value can be stored in parameters "username" or "user".- Returns:
- the user name.
-
setUsername
Sets the user name.- Parameters:
value- a new user name.
-
getPassword
Get the user password. The value can be stored in parameters "password" or "pass".- Returns:
- the user password.
-
setPassword
Sets the user password.- Parameters:
password- a new user password.
-
getAccessId
Gets the application access id. The value can be stored in parameters "access_id" pr "client_id"- Returns:
- the application access id.
-
setAccessId
Sets the application access id.- Parameters:
value- a new application access id.
-
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
Sets the application secret key.- Parameters:
value- a new application secret key.
-
fromString
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 credentialsconfigAsDefault- 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
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
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
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...)
-