Package org.owasp.esapi.reference.crypto
Class ReferenceEncryptedProperties
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<java.lang.Object,java.lang.Object>
-
- java.util.Properties
-
- org.owasp.esapi.reference.crypto.ReferenceEncryptedProperties
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<java.lang.Object,java.lang.Object>,EncryptedProperties
public class ReferenceEncryptedProperties extends java.util.Properties implements EncryptedProperties
Reference implementation of theEncryptedPropertiesinterface. This implementation wraps a normal properties file, and creates surrogates for thegetPropertyandsetPropertymethods that perform encryption and decryption based onEncryptor.This implementation differs from
DefaultEncryptedPropertiesin that it actually extends fromjava.util.Propertiesfor applications that need an instance of that class. In order to do so, thegetPropertyandsetPropertymethods were modified to throwEncryptionRuntimeExceptioninstead ofEncryptionException.- Since:
- October 8, 2010
- Author:
- August Detlefsen (augustd at codemagi dot com) CodeMagi, Inc., kevin.w.wall@gmail.com
- See Also:
EncryptedProperties,DefaultEncryptedProperties, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ReferenceEncryptedProperties()Instantiates a new encrypted properties.ReferenceEncryptedProperties(java.util.Properties defaults)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Enumerationelements()This method has been overridden to throw anUnsupportedOperationExceptionjava.util.SetentrySet()This method has been overridden to throw anUnsupportedOperationExceptionjava.lang.StringgetProperty(java.lang.String key)Gets the property value from the encrypted store, decrypts it, and returns the plaintext value to the caller.java.lang.StringgetProperty(java.lang.String key, java.lang.String defaultValue)voidlist(java.io.PrintStream out)This method has been overridden to throw anUnsupportedOperationExceptionvoidlist(java.io.PrintWriter out)This method has been overridden to throw anUnsupportedOperationExceptionvoidload(java.io.InputStream in)Reads a property list (key and element pairs) from the input stream.voidload(java.io.Reader in)For JDK 1.5 compatibility, this method has been overridden convert the Reader into an InputStream and call the superclass constructor.java.lang.Objectput(java.lang.Object key, java.lang.Object value)This method has been overridden to only accept Strings for key and value, and to encrypt those Strings before storing them.java.lang.StringsetProperty(java.lang.String key, java.lang.String value)Encrypts the plaintext property value and stores the ciphertext value in the encrypted store.java.lang.StringtoString()This method has been overridden to not print out the keys and values stored in this properties file.java.util.Collectionvalues()This method has been overridden to throw anUnsupportedOperationException-
Methods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, loadFromXML, merge, propertyNames, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.owasp.esapi.EncryptedProperties
keySet, store
-
-
-
-
Method Detail
-
getProperty
public java.lang.String getProperty(java.lang.String key) throws EncryptionRuntimeExceptionGets the property value from the encrypted store, decrypts it, and returns the plaintext value to the caller.- Specified by:
getPropertyin interfaceEncryptedProperties- Overrides:
getPropertyin classjava.util.Properties- Parameters:
key- the name of the property to get- Returns:
- The decrypted property value. null if the key is not set.
- Throws:
EncryptionRuntimeException- Thrown if decryption fails.
-
getProperty
public java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue) throws EncryptionRuntimeException- Overrides:
getPropertyin classjava.util.Properties- Throws:
EncryptionRuntimeException- Thrown if decryption fails.
-
setProperty
public java.lang.String setProperty(java.lang.String key, java.lang.String value) throws EncryptionRuntimeExceptionEncrypts the plaintext property value and stores the ciphertext value in the encrypted store.- Specified by:
setPropertyin interfaceEncryptedProperties- Overrides:
setPropertyin classjava.util.Properties- Parameters:
key- the name of the property to setvalue- the value of the property to set- Returns:
- the previously encrypted property value for the specified key, or
nullif it did not have one. - Throws:
EncryptionRuntimeException- Thrown if encryption fails.
-
load
public void load(java.io.InputStream in) throws java.io.IOExceptionReads a property list (key and element pairs) from the input stream.- Specified by:
loadin interfaceEncryptedProperties- Overrides:
loadin classjava.util.Properties- Parameters:
in- the input stream that contains the properties file- Throws:
java.io.IOException- Thrown if input stream invalid or does not correspond to Java properties file format.
-
load
public void load(java.io.Reader in) throws java.io.IOExceptionFor JDK 1.5 compatibility, this method has been overridden convert the Reader into an InputStream and call the superclass constructor.- Overrides:
loadin classjava.util.Properties- Throws:
java.io.IOException- Thrown ifReaderinput stream invalid or does not correspond to Java properties file format.
-
list
public void list(java.io.PrintStream out)
This method has been overridden to throw anUnsupportedOperationException- Overrides:
listin classjava.util.Properties
-
list
public void list(java.io.PrintWriter out)
This method has been overridden to throw anUnsupportedOperationException- Overrides:
listin classjava.util.Properties
-
values
public java.util.Collection values()
This method has been overridden to throw anUnsupportedOperationException- Specified by:
valuesin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
valuesin classjava.util.Properties
-
entrySet
public java.util.Set entrySet()
This method has been overridden to throw anUnsupportedOperationException- Specified by:
entrySetin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
entrySetin classjava.util.Properties
-
elements
public java.util.Enumeration elements()
This method has been overridden to throw anUnsupportedOperationException- Overrides:
elementsin classjava.util.Properties
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)This method has been overridden to only accept Strings for key and value, and to encrypt those Strings before storing them. Outside classes should always usesetPropertyto add values to the Properties map. If an outside class does erroneously call this method with non-String parameters anIllegalArgumentExceptionwill be thrown.- Specified by:
putin interfacejava.util.Map<java.lang.Object,java.lang.Object>- Overrides:
putin classjava.util.Properties- Parameters:
key- A String key to addvalue- A String value to add- Returns:
- The old value associated with the specified key, or
nullif the key did not exist.
-
toString
public java.lang.String toString()
This method has been overridden to not print out the keys and values stored in this properties file.- Overrides:
toStringin classjava.util.Properties- Returns:
- The minimal String representation of this class, as per java.lang.Object.
-
-