Class CredentialStoreSpi
- java.lang.Object
-
- org.wildfly.security.credential.store.CredentialStoreSpi
-
public abstract class CredentialStoreSpi extends Object
SPI for credential store provider to implement.- Author:
- Peter Skopek
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
initialized
Field indicating successful initialization (initialize(Map, CredentialStore.ProtectionParameter, Provider[])
.
-
Constructor Summary
Constructors Modifier Constructor Description protected
CredentialStoreSpi()
Construct a new instance of this SPI.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
exists(String credentialAlias, Class<? extends Credential> credentialType)
Check whether credential store service has an entry associated with the given credential alias of specified credential type.void
flush()
Flush the credential store contents to storage.Set<String>
getAliases()
Returns credential aliases stored in this store asSet<String>
.Set<String>
getCredentialTypesForAlias(String credentialAlias)
Returns credential types stored in this store with given alias asSet<String>
.abstract void
initialize(Map<String,String> attributes, CredentialStore.ProtectionParameter protectionParameter, Provider[] providers)
Initialize credential store service with given attributes.boolean
isInitialized()
Checks whether underlying credential store service is initialized.abstract boolean
isModifiable()
Check if credential store service supports modification of its storeabstract void
remove(String credentialAlias, Class<? extends Credential> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec)
Remove the credentialType with from given alias from the credential store service.abstract <C extends Credential>
Cretrieve(String credentialAlias, Class<C> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec, CredentialStore.ProtectionParameter protectionParameter)
Retrieve the credential stored in the store under the given alias, matching the given criteria.abstract void
store(String credentialAlias, Credential credential, CredentialStore.ProtectionParameter protectionParameter)
Store credential to the credential store service under the given alias.void
validateAttribute(Map<String,String> attributes, List<String> validAttributes)
Validate given attributes in credential store implementation.
-
-
-
Field Detail
-
initialized
protected boolean initialized
Field indicating successful initialization (initialize(Map, CredentialStore.ProtectionParameter, Provider[])
. Each subclass should set this field.
-
-
Method Detail
-
initialize
public abstract void initialize(Map<String,String> attributes, CredentialStore.ProtectionParameter protectionParameter, Provider[] providers) throws CredentialStoreException
Initialize credential store service with given attributes. This procedure should setinitialized
after successful initialization.- Parameters:
attributes
- attributes to used to pass information to credential store serviceprotectionParameter
- the store-wide protection parameter to apply, ornull
for noneproviders
- providers to be injected into SPI implementation to get custom object instances of various type from, ornull
for none- Throws:
CredentialStoreException
- if initialization fails due to any reason
-
isInitialized
public boolean isInitialized()
Checks whether underlying credential store service is initialized.- Returns:
true
in case of initialization passed successfully,false
otherwise.
-
isModifiable
public abstract boolean isModifiable()
Check if credential store service supports modification of its store- Returns:
true
in case of modification of the store is supported,false
otherwise
-
exists
public boolean exists(String credentialAlias, Class<? extends Credential> credentialType) throws CredentialStoreException
Check whether credential store service has an entry associated with the given credential alias of specified credential type. The default implementation simply attempts to retrieve the credential without a protection parameter, and returnstrue
if any credential was returned. Credential stores which use a protection parameter should override this method.- Parameters:
credentialAlias
- key to check existencecredentialType
- to class of credential to look for- Returns:
true
in case key exist in store otherwisefalse
- Throws:
CredentialStoreException
- when there is a problem with credential store
-
store
public abstract void store(String credentialAlias, Credential credential, CredentialStore.ProtectionParameter protectionParameter) throws CredentialStoreException, UnsupportedCredentialTypeException
Store credential to the credential store service under the given alias. If given alias already contains specific credential type type the credential replaces older one. Note:CredentialStoreSpi
supports storing of multiple entries (credential types) per alias. Each must be of different credential type, or differing algorithm, or differing parameters.- Parameters:
credentialAlias
- to store the credential to the storecredential
- instance ofCredential
to storeprotectionParameter
- the protection parameter to apply to the entry, ornull
for none- Throws:
CredentialStoreException
- when the credential cannot be storedUnsupportedCredentialTypeException
- when the credentialType is not supported
-
retrieve
public abstract <C extends Credential> C retrieve(String credentialAlias, Class<C> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec, CredentialStore.ProtectionParameter protectionParameter) throws CredentialStoreException
Retrieve the credential stored in the store under the given alias, matching the given criteria.- Type Parameters:
C
- the credential type- Parameters:
credentialAlias
- to find the credential in the storecredentialType
- the credential type class (must not benull
)credentialAlgorithm
- the credential algorithm to match, ornull
to match any algorithmparameterSpec
- the parameter specification to match, ornull
to match any parametersprotectionParameter
- the protection parameter to use to access the entry, ornull
for none- Returns:
- instance of
Credential
stored in the store, ornull
if the credential is not found - Throws:
CredentialStoreException
- if the credential cannot be retrieved due to an error
-
remove
public abstract void remove(String credentialAlias, Class<? extends Credential> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec) throws CredentialStoreException
Remove the credentialType with from given alias from the credential store service.- Parameters:
credentialAlias
- alias to removecredentialType
- the credential type class to match (must not benull
)credentialAlgorithm
- the credential algorithm to match, ornull
to match all algorithmsparameterSpec
- the credential parameters to match, ornull
to match all parameters- Throws:
CredentialStoreException
- if the credential cannot be removed due to an error
-
flush
public void flush() throws CredentialStoreException
Flush the credential store contents to storage. If the credential store does not support or require explicit flushing, this method should do nothing and simply return.- Throws:
CredentialStoreException
- if the flush fails for some reason.
-
getAliases
public Set<String> getAliases() throws UnsupportedOperationException, CredentialStoreException
Returns credential aliases stored in this store asSet<String>
. It is not mandatory to override this method (throwsUnsupportedOperationException
by default).- Returns:
Set<String>
of all keys stored in this store- Throws:
UnsupportedOperationException
- when this method is not supported by the underlying credential storeCredentialStoreException
- if there is any problem with internal store
-
getCredentialTypesForAlias
public Set<String> getCredentialTypesForAlias(String credentialAlias) throws UnsupportedOperationException
Returns credential types stored in this store with given alias asSet<String>
. It is not mandatory to override this method (throwsUnsupportedOperationException
by default).- Parameters:
credentialAlias
- to find the credentials types in the store- Returns:
Set<String>
of all credential types stored in this store with credential alias- Throws:
UnsupportedOperationException
- when this method is not supported by the underlying credential store
-
validateAttribute
public void validateAttribute(Map<String,String> attributes, List<String> validAttributes) throws CredentialStoreException
Validate given attributes in credential store implementation.- Parameters:
attributes
- attributes to used to pass information to credential store service.validAttributes
- valid attributes based on credential store implementation.- Throws:
CredentialStoreException
- if validation fails
-
-