public final class EncryptableProperties extends Properties
Subclass of java.util.Properties which can make use of a
StringEncryptor
or
TextEncryptor
object to decrypt property values
if they are encrypted in the .properties file.
A value is considered "encrypted" when it appears surrounded by ENC(...), like:
Decryption is performed on-the-fly when the getProperty(String)
or
getProperty(String, String)
methods are called, and only these two
methods perform decryption (note that neither get(Object)
nor
Hashtable.toString()
do). Load and store operations are not affected
by decryption in any manner.
Encrypted and unencrypted objects can be combined in the same properties file.
Please note that, altough objects of this class are Serializable, they cannot be serialized and then de-serialized in different classloaders or virtual machines. This is so because encryptors are not serializable themselves (they cannot, as they contain sensitive information) and so they remain in memory, and live for as long as the classloader lives.
defaults
Constructor and Description |
---|
EncryptableProperties(Properties defaults,
StringEncryptor stringEncryptor)
Creates an EncryptableProperties instance which will use
the passed
StringEncryptor object to decrypt encrypted values,
and the passed defaults as default values (may contain encrypted values). |
EncryptableProperties(Properties defaults,
TextEncryptor textEncryptor)
Creates an EncryptableProperties instance which will use
the passed
TextEncryptor object to decrypt encrypted values,
and the passed defaults as default values (may contain encrypted values). |
EncryptableProperties(StringEncryptor stringEncryptor)
Creates an EncryptableProperties instance which will use
the passed
StringEncryptor object to decrypt encrypted values. |
EncryptableProperties(TextEncryptor textEncryptor)
Creates an EncryptableProperties instance which will use
the passed
TextEncryptor object to decrypt encrypted values. |
Modifier and Type | Method and Description |
---|---|
Object |
get(Object key)
Obtains the property value for the specified key (see
Hashtable#get(Object) ), decrypting it if needed. |
String |
getProperty(String key)
Obtains the property value for the specified key (see
Properties.getProperty(String) ), decrypting it if needed. |
String |
getProperty(String key,
String defaultValue)
Obtains the property value for the specified key (see
Properties.getProperty(String) ), decrypting it if needed. |
list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNames
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keys, keySet, merge, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, size, toString, values
public EncryptableProperties(StringEncryptor stringEncryptor)
Creates an EncryptableProperties instance which will use
the passed StringEncryptor
object to decrypt encrypted values.
stringEncryptor
- the StringEncryptor
to be used do decrypt
values. It can not be null.public EncryptableProperties(TextEncryptor textEncryptor)
Creates an EncryptableProperties instance which will use
the passed TextEncryptor
object to decrypt encrypted values.
textEncryptor
- the TextEncryptor
to be used do decrypt
values. It can not be null.public EncryptableProperties(Properties defaults, StringEncryptor stringEncryptor)
Creates an EncryptableProperties instance which will use
the passed StringEncryptor
object to decrypt encrypted values,
and the passed defaults as default values (may contain encrypted values).
defaults
- default values for properties (may be encrypted).stringEncryptor
- the StringEncryptor
to be used do decrypt
values. It can not be null.public EncryptableProperties(Properties defaults, TextEncryptor textEncryptor)
Creates an EncryptableProperties instance which will use
the passed TextEncryptor
object to decrypt encrypted values,
and the passed defaults as default values (may contain encrypted values).
defaults
- default values for properties (may be encrypted).textEncryptor
- the TextEncryptor
to be used do decrypt
values. It can not be null.public String getProperty(String key)
Obtains the property value for the specified key (see
Properties.getProperty(String)
), decrypting it if needed.
getProperty
in class Properties
key
- the property keypublic String getProperty(String key, String defaultValue)
Obtains the property value for the specified key (see
Properties.getProperty(String)
), decrypting it if needed.
If no value is found for the specified key, the default value will be returned (decrypted if needed).
getProperty
in class Properties
key
- the property keydefaultValue
- the default value to returnCopyright © 2017 JBoss by Red Hat. All rights reserved.