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 classCredentialStore.CredentialSourceProtectionParameterA protection parameter which uses a credential source to acquire a credential to use.static interfaceCredentialStore.ProtectionParameterThe protection parameter to use when accessing a credential store or entry.
-
Field Summary
Fields Modifier and Type Field Description static StringCREDENTIAL_STORE_TYPEJCA 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.voidflush()Flush the contents of this credential store to storage.Set<String>getAliases()ReturnsSet<String>stored in this store.static CredentialStoregetInstance(String algorithm)Get aCredentialStoreinstance.static CredentialStoregetInstance(String algorithm, String providerName)Get aCredentialStoreinstance.static CredentialStoregetInstance(String algorithm, String providerName, Supplier<Provider[]> providers)Get aCredentialStoreinstance.static CredentialStoregetInstance(String algorithm, Provider provider)Get aCredentialStoreinstance.static CredentialStoregetInstance(String algorithm, Supplier<Provider[]> providers)Get aCredentialStoreinstance.ProvidergetProvider()ReturnsProviderwhich providesCredentialStoreSpifor this instance.StringgetType()Returns JCA service type ofCredentialStoreSpifor this instance.voidinitialize(Map<String,String> attributes)Initialize Credential Store service with given attributes.voidinitialize(Map<String,String> attributes, CredentialStore.ProtectionParameter protectionParameter)Initialize Credential Store service with given attributes.voidinitialize(Map<String,String> attributes, CredentialStore.ProtectionParameter protectionParameter, Provider[] providers)Initialize Credential Store service with given attributes.booleanisInitialized()Checks whether underlying credential store is initialized.booleanisModifiable()Check if credential store supports modification of actual storevoidremove(String credentialAlias, Class<? extends Credential> credentialType)Remove the credentialType with from given alias matching the given criteria from the store.voidremove(String credentialAlias, Class<? extends Credential> credentialType, String credentialAlgorithm)Remove the credentialType with from given alias matching the given criteria from the store.voidremove(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 aCredentialStoreinstance. The returned CredentialStore object will implement the given algorithm.- Parameters:
algorithm- the name of the algorithm- Returns:
- a
CredentialStoreinstance - Throws:
NoSuchAlgorithmException- if the given algorithm has no available implementations
-
getInstance
public static CredentialStore getInstance(String algorithm, Supplier<Provider[]> providers) throws NoSuchAlgorithmException
Get aCredentialStoreinstance. The returned CredentialStore object will implement the given algorithm.- Parameters:
algorithm- the name of the algorithmproviders- supplier of provider instances to search.- Returns:
- a
CredentialStoreinstance - Throws:
NoSuchAlgorithmException- if the given algorithm has no available implementations
-
getInstance
public static CredentialStore getInstance(String algorithm, String providerName) throws NoSuchAlgorithmException, NoSuchProviderException
Get aCredentialStoreinstance. 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
CredentialStoreinstance - 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 aCredentialStoreinstance. 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
CredentialStoreinstance - 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 aCredentialStoreinstance. The returned CredentialStore object will implement the given algorithm.- Parameters:
algorithm- the name of the algorithmprovider- the provider to use- Returns:
- a
CredentialStoreinstance - 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.initializedafter 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.initializedafter 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.initializedafter 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:
truein case of initialization passed successfully,falseotherwise.
-
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:CredentialStoreSpisupports 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 ofCredentialto 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:CredentialStoreSpisupports 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 ofCredentialto storeprotectionParameter- the protection parameter to use, ornullfor 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
Credentialstored 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, ornullto match any- Returns:
- instance of
Credentialstored 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, ornullto match anyparameterSpec- the parameter specification to match, ornullto match any- Returns:
- instance of
Credentialstored 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, ornullto match anyparameterSpec- the parameter specification to match, ornullto match anyprotectionParameter- the protection parameter to use, ornullto use none- Returns:
- instance of
Credentialstored 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, ornullto 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, ornullto match anyparameterSpec- the parameters to match, ornullto 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 CredentialStoreExceptionFlush 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()
ReturnsProviderwhich providesCredentialStoreSpifor this instance.- Returns:
Providerof thisCredentialStoreSpi
-
getType
public String getType()
Returns JCA service type ofCredentialStoreSpifor this instance.- Returns:
- type of service of this
CredentialStoreSpi
-
-