Class CredentialStore
- java.lang.Object
-
- org.wildfly.security.credential.store.CredentialStore
-
public final class CredentialStore extends Object
This class represents credential store functionality. Type of the credential store is determined by instance type and is loaded fromProvider
.- Author:
- Peter Skopek.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CredentialStore.CredentialSourceProtectionParameter
A protection parameter which uses a credential source to acquire a credential to use.static interface
CredentialStore.ProtectionParameter
The protection parameter to use when accessing a credential store or entry.
-
Field Summary
Fields Modifier and Type Field Description static String
CREDENTIAL_STORE_TYPE
JCA service type for a credential store.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <C extends Credential>
booleanexists(String credentialAlias, Class<C> credentialType)
Check whether credential store has an entry associated with the given credential alias of specified credential type.void
flush()
Flush the contents of this credential store to storage.Set<String>
getAliases()
ReturnsSet<String>
stored in this store.static CredentialStore
getInstance(String algorithm)
Get aCredentialStore
instance.static CredentialStore
getInstance(String algorithm, String providerName)
Get aCredentialStore
instance.static CredentialStore
getInstance(String algorithm, String providerName, Supplier<Provider[]> providers)
Get aCredentialStore
instance.static CredentialStore
getInstance(String algorithm, Provider provider)
Get aCredentialStore
instance.static CredentialStore
getInstance(String algorithm, Supplier<Provider[]> providers)
Get aCredentialStore
instance.Provider
getProvider()
ReturnsProvider
which providesCredentialStoreSpi
for this instance.String
getType()
Returns JCA service type ofCredentialStoreSpi
for this instance.void
initialize(Map<String,String> attributes)
Initialize Credential Store service with given attributes.void
initialize(Map<String,String> attributes, CredentialStore.ProtectionParameter protectionParameter)
Initialize Credential Store service with given attributes.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 is initialized.boolean
isModifiable()
Check if credential store supports modification of actual storevoid
remove(String credentialAlias, Class<? extends Credential> credentialType)
Remove the credentialType with from given alias matching the given criteria from the store.void
remove(String credentialAlias, Class<? extends Credential> credentialType, String credentialAlgorithm)
Remove the credentialType with from given alias matching the given criteria from the store.void
remove(String credentialAlias, Class<? extends Credential> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec)
Remove the credentialType with from given alias matching the given criteria from the store.<C extends Credential>
Cretrieve(String credentialAlias, Class<C> credentialType)
Retrieve credential stored in the store under the key and of the credential type<C extends Credential>
Cretrieve(String credentialAlias, Class<C> credentialType, String credentialAlgorithm)
Retrieve credential stored in the store under the key and of the credential type.<C extends Credential>
Cretrieve(String credentialAlias, Class<C> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec)
Retrieve credential stored in the store under the key and of the credential type.<C extends Credential>
Cretrieve(String credentialAlias, Class<C> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec, CredentialStore.ProtectionParameter protectionParameter)
Retrieve credential stored in the store under the key and of the credential type.<C extends Credential>
voidstore(String credentialAlias, C credential)
Store credential to the store under the given alias.<C extends Credential>
voidstore(String credentialAlias, C credential, CredentialStore.ProtectionParameter protectionParameter)
Store credential to the store under the given alias.
-
-
-
Field Detail
-
CREDENTIAL_STORE_TYPE
public static final String CREDENTIAL_STORE_TYPE
JCA service type for a credential store.- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static CredentialStore getInstance(String algorithm) throws NoSuchAlgorithmException
Get aCredentialStore
instance. The returned CredentialStore object will implement the given algorithm.- Parameters:
algorithm
- the name of the algorithm- Returns:
- a
CredentialStore
instance - Throws:
NoSuchAlgorithmException
- if the given algorithm has no available implementations
-
getInstance
public static CredentialStore getInstance(String algorithm, Supplier<Provider[]> providers) throws NoSuchAlgorithmException
Get aCredentialStore
instance. The returned CredentialStore object will implement the given algorithm.- Parameters:
algorithm
- the name of the algorithmproviders
- supplier of provider instances to search.- Returns:
- a
CredentialStore
instance - Throws:
NoSuchAlgorithmException
- if the given algorithm has no available implementations
-
getInstance
public static CredentialStore getInstance(String algorithm, String providerName) throws NoSuchAlgorithmException, NoSuchProviderException
Get aCredentialStore
instance. The returned CredentialStore object will implement the given algorithm.- Parameters:
algorithm
- the name of the algorithmproviderName
- the name of the provider to use- Returns:
- a
CredentialStore
instance - Throws:
NoSuchAlgorithmException
- if the given algorithm has no available implementationsNoSuchProviderException
- if given provider name cannot match any registeredProvider
-
getInstance
public static CredentialStore getInstance(String algorithm, String providerName, Supplier<Provider[]> providers) throws NoSuchAlgorithmException, NoSuchProviderException
Get aCredentialStore
instance. The returned CredentialStore object will implement the given algorithm.- Parameters:
algorithm
- the name of the algorithmproviderName
- the name of the provider to useproviders
- supplier of provider instances to search- Returns:
- a
CredentialStore
instance - Throws:
NoSuchAlgorithmException
- if the given algorithm has no available implementationsNoSuchProviderException
- if given provider name cannot match any registeredProvider
-
getInstance
public static CredentialStore getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
Get aCredentialStore
instance. The returned CredentialStore object will implement the given algorithm.- Parameters:
algorithm
- the name of the algorithmprovider
- the provider to use- Returns:
- a
CredentialStore
instance - Throws:
NoSuchAlgorithmException
- if the given algorithm has no available implementations
-
initialize
public void initialize(Map<String,String> attributes, CredentialStore.ProtectionParameter protectionParameter, Provider[] providers) throws CredentialStoreException
Initialize Credential Store service with given attributes. This procedure should setCredentialStoreSpi.initialized
after successful initialization.- Parameters:
attributes
- attributes to used to pass information to Credential Store serviceprotectionParameter
- the protection parameter to use when accessing the storeproviders
- providers to be injected into SPI implementation to get custom object instances of various type from- Throws:
CredentialStoreException
- if initialization fails due to any reason
-
initialize
public void initialize(Map<String,String> attributes, CredentialStore.ProtectionParameter protectionParameter) throws CredentialStoreException
Initialize Credential Store service with given attributes. This procedure should setCredentialStoreSpi.initialized
after successful initialization.- Parameters:
attributes
- attributes to used to pass information to Credential Store serviceprotectionParameter
- the protection parameter to use when accessing the store- Throws:
CredentialStoreException
- if initialization fails due to any reason
-
initialize
public void initialize(Map<String,String> attributes) throws CredentialStoreException
Initialize Credential Store service with given attributes. This procedure should setCredentialStoreSpi.initialized
after successful initialization.- Parameters:
attributes
- attributes to used to pass information to Credential Store service- Throws:
CredentialStoreException
- if initialization fails due to any reason
-
isInitialized
public boolean isInitialized()
Checks whether underlying credential store is initialized.- Returns:
true
in case of initialization passed successfully,false
otherwise.
-
isModifiable
public boolean isModifiable()
Check if credential store supports modification of actual store- Returns:
- true in case of modification of store is supported
-
exists
public <C extends Credential> boolean exists(String credentialAlias, Class<C> credentialType) throws CredentialStoreException, UnsupportedCredentialTypeException
Check whether credential store has an entry associated with the given credential alias of specified credential type.- Type Parameters:
C
- the class of type to which should be credential casted- Parameters:
credentialAlias
- alias to check existencecredentialType
- to check existence in the credential store- Returns:
- true in case key exist in store
- Throws:
CredentialStoreException
- when there is a problem with credential storeUnsupportedCredentialTypeException
- when the credentialType is not supported
-
store
public <C extends Credential> void store(String credentialAlias, C credential) throws CredentialStoreException, UnsupportedCredentialTypeException
Store credential to the store 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.- Type Parameters:
C
- the class of type to which should be credential casted- Parameters:
credentialAlias
- to store the credential to the storecredential
- instance ofCredential
to store- Throws:
CredentialStoreException
- when the credential cannot be storedUnsupportedCredentialTypeException
- when the credentialType is not supported
-
store
public <C extends Credential> void store(String credentialAlias, C credential, CredentialStore.ProtectionParameter protectionParameter) throws CredentialStoreException, UnsupportedCredentialTypeException
Store credential to the store 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.- Type Parameters:
C
- the class of type to which should be credential casted- Parameters:
credentialAlias
- to store the credential to the storecredential
- instance ofCredential
to storeprotectionParameter
- the protection parameter to use, ornull
for none- Throws:
CredentialStoreException
- when the credential cannot be storedUnsupportedCredentialTypeException
- when the credentialType is not supported
-
retrieve
public <C extends Credential> C retrieve(String credentialAlias, Class<C> credentialType) throws CredentialStoreException, UnsupportedCredentialTypeException
Retrieve credential stored in the store under the key and of the credential type- Type Parameters:
C
- the class of type to which should be credential casted- Parameters:
credentialAlias
- to find the credential in the storecredentialType
- - credential type to retrieve from under the credentialAlias from the store- Returns:
- instance of
Credential
stored in the store - Throws:
CredentialStoreException
- - if credentialAlias credentialType combination doesn't exist or credentialAlias cannot be retrievedUnsupportedCredentialTypeException
- when the credentialType is not supported
-
retrieve
public <C extends Credential> C retrieve(String credentialAlias, Class<C> credentialType, String credentialAlgorithm) throws CredentialStoreException
Retrieve credential stored in the store under the key and of the credential type.- Type Parameters:
C
- the class of type to which should be credential casted- Parameters:
credentialAlias
- to find the credential in the storecredentialType
- credential type to retrieve from under the credentialAlias from the storecredentialAlgorithm
- the credential algorithm to match, ornull
to match any- Returns:
- instance of
Credential
stored in the store - Throws:
CredentialStoreException
- if credentialAlias credentialType combination doesn't exist or credentialAlias cannot be retrieved
-
retrieve
public <C extends Credential> C retrieve(String credentialAlias, Class<C> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec) throws CredentialStoreException
Retrieve credential stored in the store under the key and of the credential type.- Type Parameters:
C
- the class of type to which should be credential casted- Parameters:
credentialAlias
- to find the credential in the storecredentialType
- credential type to retrieve from under the credentialAlias from the storecredentialAlgorithm
- the credential algorithm to match, ornull
to match anyparameterSpec
- the parameter specification to match, ornull
to match any- Returns:
- instance of
Credential
stored in the store - Throws:
CredentialStoreException
- if credentialAlias credentialType combination doesn't exist or credentialAlias cannot be retrieved
-
retrieve
public <C extends Credential> C retrieve(String credentialAlias, Class<C> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec, CredentialStore.ProtectionParameter protectionParameter) throws CredentialStoreException
Retrieve credential stored in the store under the key and of the credential type.- Type Parameters:
C
- the class of type to which should be credential casted- Parameters:
credentialAlias
- to find the credential in the storecredentialType
- credential type to retrieve from under the credentialAlias from the storecredentialAlgorithm
- the credential algorithm to match, ornull
to match anyparameterSpec
- the parameter specification to match, ornull
to match anyprotectionParameter
- the protection parameter to use, ornull
to use none- Returns:
- instance of
Credential
stored in the store - Throws:
CredentialStoreException
- if credentialAlias credentialType combination doesn't exist or credentialAlias cannot be retrieved
-
remove
public void remove(String credentialAlias, Class<? extends Credential> credentialType) throws CredentialStoreException
Remove the credentialType with from given alias matching the given criteria from the store.- Parameters:
credentialAlias
- alias to remove credential(s) fromcredentialType
- credential type to match (must not benull
)- Throws:
CredentialStoreException
- if credential removal fails
-
remove
public void remove(String credentialAlias, Class<? extends Credential> credentialType, String credentialAlgorithm) throws CredentialStoreException
Remove the credentialType with from given alias matching the given criteria from the store.- Parameters:
credentialAlias
- alias to remove credential(s) fromcredentialType
- credential type to match (must not benull
)credentialAlgorithm
- the algorithm name to match, ornull
to match any- Throws:
CredentialStoreException
- if credential removal fails
-
remove
public void remove(String credentialAlias, Class<? extends Credential> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec) throws CredentialStoreException
Remove the credentialType with from given alias matching the given criteria from the store.- Parameters:
credentialAlias
- alias to remove credential(s) fromcredentialType
- credential type to match (must not benull
)credentialAlgorithm
- the algorithm name to match, ornull
to match anyparameterSpec
- the parameters to match, ornull
to match any- Throws:
CredentialStoreException
- if credential removal fails
-
getAliases
public Set<String> getAliases() throws UnsupportedOperationException, CredentialStoreException
ReturnsSet<String>
stored in this store.- 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
-
flush
public void flush() throws CredentialStoreException
Flush the contents of this credential store to storage. This method may be a no-op on credential stores without backing storage or which do not buffer changes.- Throws:
CredentialStoreException
- if flushing the store fails for some reason
-
getProvider
public Provider getProvider()
ReturnsProvider
which providesCredentialStoreSpi
for this instance.- Returns:
Provider
of thisCredentialStoreSpi
-
getType
public String getType()
Returns JCA service type ofCredentialStoreSpi
for this instance.- Returns:
- type of service of this
CredentialStoreSpi
-
-