Implemets: ConfigParams
Description
The CredentialParams class allows you to create credential parameters that can be used to authenticate against external services.
Important points
- Credential parameters 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’s 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.
Constructors
Creates a new credential parameters and fills it with values.
publicCredentialParams(Map map)
- map: Map<? - (optional) map to be converted into key-value pairs to initialize these credentials.
Creates an empty instance of credential parameters.
publicCredentialParams()
Instance methods
useCredentialStore
Checks if these credential parameters shall be retrieved from ICredentialStore. The credential parameters are redirected to ICredentialStore when store_key parameter is set.
publicboolean useCredentialStore()
- returns: boolean - true if credential parameters must be retrieved from ICredentialStore.
getStoreKey
Gets the key to retrieve these credentials from CredentialStore. If this key is null, then all parameters are already present.
publicString getStoreKey()
- returns: String - the store key to retrieve credentials.
setStoreKey
Sets the key to retrieve these parameters from CredentialStore.
publicvoid setStoreKey(String value)
- value: String - value a new key to retrieve credentials.
getUsername
Gets the user name. The value can be stored in parameters “username” or “user”.
publicString getStoreKey()
- returns: String - username.
setUsername
Sets the username.
publicvoid setUsername(String value)
- value: String - value a new user name.
getPassword
Gets the user password. The value can be stored in parameters “password” or “pass”.
publicString getPassword()
- returns: String - user’s password.
setPassword
Sets the username.
publicvoid setPassword(String password)
- password: String - new user’s password.
getAccessId
Gets the application access id. The value can be stored in parameters “access_id” pr “client_id”
publicString getAccessId()
- returns: String - application access id.
setAccessId
Sets the application access id.
publicvoid setAccessId(String value)
- value: String - new application access id.
getAccessKey
Gets the application secret key. The value can be stored in parameters “access_key”, “client_key” or “secret_key”.
publicString getAccessKey()
- returns: String - application secret key.
setAccessId
Sets the application secret key.
publicvoid setAccessKey(String value)
- value: String - value a new application secret key.
Static methods
fromConfig
Retrieves a single CredentialParams from configuration parameters from “credential” section. If “credentials” section is present instead, then it returns only the first credential element.
public staticCredentialParams fromConfig(ConfigParams config)
- config: ConfigParams - containing a section named “credential(s)”.
- returns: CredentialParams - generated CredentialParams object.
fromString
Creates a new CredentialParams object filled with key-value pairs serialized as a string.
public staticCredentialParams fromString(String line)
- line: String - string with serialized key-value pairs as “key1=value1;key2=value2;…" Example: “Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z”
- returns: CredentialParams - new CredentialParams 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.
public staticCredentialParams fromTuples(Object… tuples)
- returns: CredentialParams - new CredentialParams object.
fromValue
Creates a new CredentialParams object filled with key-value pairs from specified object.
public staticCredentialParams fromValue(Object value)
- returns: CredentialParams - CredentialParams object.
ManyFromConfig
Retrieves all CredentialParams from configuration parameters from the “credentials” section. If the “credential” section is present instead, then it returns a list with only one CredentialParams.
public staticList<CredentialParams> manyFromConfig(ConfigParams config)
- config: ConfigParams - configuration parameters to retrieve credentials
- returns: List<CredentialParams> - list of retrieved CredentialParams
mergeConfigs
Merges two or more CredentialParams into one. The following ConfigParams override previously defined parameters.
public staticCredentialParams mergeConfigs(List<CConfigParams> configs)
- configs: ConfigParams - configuration parameters.
- returns: CredentialParams - CredentialParams object.
Examples
{
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
}