Class PropertiesCredentialStore
- java.lang.Object
-
- org.wildfly.security.credential.store.CredentialStoreSpi
-
- org.wildfly.security.credential.store.impl.PropertiesCredentialStore
-
public class PropertiesCredentialStore extends CredentialStoreSpi
ACredentialStore
implementation backed by a properties file. This is a simple implementation which only supports the storage ofSecretKey
credentials, additionally password protection of the store is not supported.- Author:
- Darran Lofthouse
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interface
PropertiesCredentialStore.Lock
-
Field Summary
Fields Modifier and Type Field Description private static char
COMMENT
private static String
CREATE
private File
credentialStoreLocation
private static char
DELIMITER
private AtomicReference<Map<String,SecretKey>>
entries
private String
HEADER
private static String
LOCATION
static String
NAME
private static Pattern
PATTERN
private ReadWriteLock
readWriteLock
-
Fields inherited from class org.wildfly.security.credential.store.CredentialStoreSpi
initialized
-
-
Constructor Summary
Constructors Constructor Description PropertiesCredentialStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
assertInitialised()
void
flush()
Flush the credential store contents to storage.Set<String>
getAliases()
Returns credential aliases stored in this store asSet<String>
.void
initialize(Map<String,String> attributes, CredentialStore.ProtectionParameter protectionParameter, Provider[] providers)
Initialize credential store service with given attributes.boolean
isModifiable()
Check if credential store service supports modification of its storeprivate Map<String,SecretKey>
load()
private PropertiesCredentialStore.Lock
lockForRead()
private PropertiesCredentialStore.Lock
lockForWrite()
void
remove(String credentialAlias, Class<? extends Credential> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec)
Remove the credentialType with from given alias from the credential store service.<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.private void
save()
void
store(String credentialAlias, Credential credential, CredentialStore.ProtectionParameter protectionParameter)
Store credential to the credential store service under the given alias.-
Methods inherited from class org.wildfly.security.credential.store.CredentialStoreSpi
exists, getCredentialTypesForAlias, isInitialized, validateAttribute
-
-
-
-
Field Detail
-
PATTERN
private static final Pattern PATTERN
-
NAME
public static final String NAME
-
HEADER
private final String HEADER
- See Also:
- Constant Field Values
-
COMMENT
private static final char COMMENT
- See Also:
- Constant Field Values
-
DELIMITER
private static final char DELIMITER
- See Also:
- Constant Field Values
-
CREATE
private static final String CREATE
- See Also:
- Constant Field Values
-
LOCATION
private static final String LOCATION
- See Also:
- Constant Field Values
-
readWriteLock
private final ReadWriteLock readWriteLock
-
entries
private final AtomicReference<Map<String,SecretKey>> entries
-
credentialStoreLocation
private volatile File credentialStoreLocation
-
-
Method Detail
-
initialize
public void initialize(Map<String,String> attributes, CredentialStore.ProtectionParameter protectionParameter, Provider[] providers) throws CredentialStoreException
Description copied from class:CredentialStoreSpi
Initialize credential store service with given attributes. This procedure should setCredentialStoreSpi.initialized
after successful initialization.- Specified by:
initialize
in classCredentialStoreSpi
- 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
-
isModifiable
public boolean isModifiable()
Description copied from class:CredentialStoreSpi
Check if credential store service supports modification of its store- Specified by:
isModifiable
in classCredentialStoreSpi
- Returns:
true
in case of modification of the store is supported,false
otherwise
-
store
public void store(String credentialAlias, Credential credential, CredentialStore.ProtectionParameter protectionParameter) throws CredentialStoreException, UnsupportedCredentialTypeException
Description copied from class:CredentialStoreSpi
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.- Specified by:
store
in classCredentialStoreSpi
- 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 <C extends Credential> C retrieve(String credentialAlias, Class<C> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec, CredentialStore.ProtectionParameter protectionParameter) throws CredentialStoreException
Description copied from class:CredentialStoreSpi
Retrieve the credential stored in the store under the given alias, matching the given criteria.- Specified by:
retrieve
in classCredentialStoreSpi
- 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 void remove(String credentialAlias, Class<? extends Credential> credentialType, String credentialAlgorithm, AlgorithmParameterSpec parameterSpec) throws CredentialStoreException
Description copied from class:CredentialStoreSpi
Remove the credentialType with from given alias from the credential store service.- Specified by:
remove
in classCredentialStoreSpi
- 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
-
getAliases
public Set<String> getAliases() throws UnsupportedOperationException, CredentialStoreException
Description copied from class:CredentialStoreSpi
Returns credential aliases stored in this store asSet<String>
. It is not mandatory to override this method (throwsUnsupportedOperationException
by default).- Overrides:
getAliases
in classCredentialStoreSpi
- 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
Description copied from class:CredentialStoreSpi
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.- Overrides:
flush
in classCredentialStoreSpi
- Throws:
CredentialStoreException
- if the flush fails for some reason.
-
save
private void save() throws CredentialStoreException
- Throws:
CredentialStoreException
-
load
private Map<String,SecretKey> load() throws CredentialStoreException, IOException
- Throws:
CredentialStoreException
IOException
-
assertInitialised
private void assertInitialised() throws CredentialStoreException
- Throws:
CredentialStoreException
-
lockForRead
private PropertiesCredentialStore.Lock lockForRead()
-
lockForWrite
private PropertiesCredentialStore.Lock lockForWrite()
-
-