Class EncryptableProperties
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<java.lang.Object,java.lang.Object>
-
- java.util.Properties
-
- org.jasypt.properties.EncryptableProperties
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<java.lang.Object,java.lang.Object>
public final class EncryptableProperties extends java.util.PropertiesSubclass of java.util.Properties which can make use of a
StringEncryptororTextEncryptorobject to decrypt property values if they are encrypted in the .properties file.A value is considered "encrypted" when it appears surrounded by ENC(...), like:
my.value=ENC(!"DGAS24FaIO$) Decryption is performed on-the-fly when the
getProperty(String)orgetProperty(String, String)methods are called, and only these two methods perform decryption (note that neitherget(Object)norProperties.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.
- Since:
- 1.4
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Integeridentprivate static longserialVersionUIDprivate StringEncryptorstringEncryptorprivate TextEncryptortextEncryptor
-
Constructor Summary
Constructors Constructor Description EncryptableProperties(java.util.Properties defaults, StringEncryptor stringEncryptor)Creates an EncryptableProperties instance which will use the passedStringEncryptorobject to decrypt encrypted values, and the passed defaults as default values (may contain encrypted values).EncryptableProperties(java.util.Properties defaults, TextEncryptor textEncryptor)Creates an EncryptableProperties instance which will use the passedTextEncryptorobject 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 passedStringEncryptorobject to decrypt encrypted values.EncryptableProperties(TextEncryptor textEncryptor)Creates an EncryptableProperties instance which will use the passedTextEncryptorobject to decrypt encrypted values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.Stringdecode(java.lang.String encodedValue)java.lang.Objectget(java.lang.Object key)Obtains the property value for the specified key (seeHashtable#get(Object)), decrypting it if needed.(package private) java.lang.IntegergetIdent()java.lang.StringgetProperty(java.lang.String key)Obtains the property value for the specified key (seeProperties.getProperty(String)), decrypting it if needed.java.lang.StringgetProperty(java.lang.String key, java.lang.String defaultValue)Obtains the property value for the specified key (seeProperties.getProperty(String)), decrypting it if needed.private voidreadObject(java.io.ObjectInputStream in)private voidwriteObject(java.io.ObjectOutputStream outputStream)-
Methods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
ident
private final java.lang.Integer ident
-
stringEncryptor
private transient StringEncryptor stringEncryptor
-
textEncryptor
private transient TextEncryptor textEncryptor
-
-
Constructor Detail
-
EncryptableProperties
public EncryptableProperties(StringEncryptor stringEncryptor)
Creates an EncryptableProperties instance which will use the passed
StringEncryptorobject to decrypt encrypted values.- Parameters:
stringEncryptor- theStringEncryptorto be used do decrypt values. It can not be null.
-
EncryptableProperties
public EncryptableProperties(TextEncryptor textEncryptor)
Creates an EncryptableProperties instance which will use the passed
TextEncryptorobject to decrypt encrypted values.- Parameters:
textEncryptor- theTextEncryptorto be used do decrypt values. It can not be null.
-
EncryptableProperties
public EncryptableProperties(java.util.Properties defaults, StringEncryptor stringEncryptor)Creates an EncryptableProperties instance which will use the passed
StringEncryptorobject to decrypt encrypted values, and the passed defaults as default values (may contain encrypted values).- Parameters:
defaults- default values for properties (may be encrypted).stringEncryptor- theStringEncryptorto be used do decrypt values. It can not be null.
-
EncryptableProperties
public EncryptableProperties(java.util.Properties defaults, TextEncryptor textEncryptor)Creates an EncryptableProperties instance which will use the passed
TextEncryptorobject to decrypt encrypted values, and the passed defaults as default values (may contain encrypted values).- Parameters:
defaults- default values for properties (may be encrypted).textEncryptor- theTextEncryptorto be used do decrypt values. It can not be null.
-
-
Method Detail
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Obtains the property value for the specified key (see
Properties.getProperty(String)), decrypting it if needed.- Overrides:
getPropertyin classjava.util.Properties- Parameters:
key- the property key- Returns:
- the (decrypted) value
-
getProperty
public java.lang.String getProperty(java.lang.String key, java.lang.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).
- Overrides:
getPropertyin classjava.util.Properties- Parameters:
key- the property keydefaultValue- the default value to return- Returns:
- the (decrypted) value
-
get
public java.lang.Object get(java.lang.Object key)
Obtains the property value for the specified key (see
Hashtable#get(Object)), decrypting it if needed.- Specified by:
getin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
getin classjava.util.Properties- Parameters:
key- the property key- Returns:
- the (decrypted) value
- Since:
- 1.9.0
-
getIdent
java.lang.Integer getIdent()
-
decode
private java.lang.String decode(java.lang.String encodedValue)
-
readObject
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
writeObject
private void writeObject(java.io.ObjectOutputStream outputStream) throws java.io.IOException- Throws:
java.io.IOException
-
-