CredentialResolver

Helper class used to retrieve component credentials.

Inherits: IConfigurable, IReferenceable

Description

The CredentialResolver class is used to retrieve component credentials.

Important points

  • If credentials are configured to be retrieved from ICredentialStore, it will automatically locate ICredentialStore in component references and retrieve the credentials from there using the store_key parameter.

Configuration parameters

credential:

  • store_key: (optional) key to retrieve the credentials from ICredentialStore
  • : other credential parameters

credentials: alternative to credential

  • [credential params 1]: first credential parameters
    • : credential parameters for key 1
  • [credential params N]: Nth credential parameters
    • : credential parameters for key N

References

  • *:credential-store:*:*:1.0 - (optional) Credential stores to resolve credentials

Constructors

Creates a new instance of credentials resolver.

public CredentialResolver(ConfigParams config, IReferences references)

  • config: ConfigParams - (optional) component configuration parameters
  • references: IReferences - (optional) component references

Instance methods

add

Adds a new credential to component credentials

public void add(CredentialParams connection)

configure

Configures component by passing configuration parameters.

public void configure(ConfigParams config, boolean configAsDefault)

  • config: ConfigParams - configuration parameters to be set.
  • configAsDefault: boolean - boolean parameter for default configuration. If “true” the default value will be added to the result.

getAll

Gets all credentials configured in component configuration.

Redirect to CredentialStores is not done at this point. If you need fully fleshed credential use the lookup method instead.

public List<CredentialParams> getAll()

lookup

public CredentialParams lookup(IContext context) throws ApplicationException

  • context: IContext - (optional) a context to trace execution through a call chain.
  • returns: CredentialParams - resolved credential parameters or null if nothing was found.

lookupInStores

public CredentialParams lookupInStores(IContext context, CredentialParams credential) throws ApplicationException

  • context: IContext - (optional) a context to trace execution through a call chain.
  • credential: CredentialParams - credential.
  • returns: CredentialParams - resolved credential parameters or null if nothing was found.

SetReferences

Sets references to dependent components.

public void setReferences(IReferences references)

  • references: IReferences - references to locate the component’s dependencies.

Examples

var config = ConfigParams.FromTuples(
    "credential.user", "jdoe",
    "credential.pass",  "pass123" 
);

var credentialResolver = new CredentialResolver();
credentialResolver.Configure(config);

credentialResolver.SetReferences(references);
credentialResolver.LookupAsync("123");

See also