org.owasp.esapi.reference.crypto
Class ReferenceEncryptedProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<Object,Object>
          extended by java.util.Properties
              extended by org.owasp.esapi.reference.crypto.ReferenceEncryptedProperties
All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>, EncryptedProperties

public class ReferenceEncryptedProperties
extends Properties
implements EncryptedProperties

Reference implementation of the EncryptedProperties interface. This implementation wraps a normal properties file, and creates surrogates for the getProperty and setProperty methods that perform encryption and decryption based on Encryptor.

This implementation differs from DefaultEncryptedProperties in that it actually extends from java.util.Properties for applications that need an instance of that class. In order to do so, the getProperty and setProperty methods were modified to throw EncryptionRuntimeException instead of EncryptionException.

Since:
October 8, 2010
Author:
August Detlefsen (augustd at codemagi dot com) CodeMagi, Inc., [email protected]
See Also:
EncryptedProperties, DefaultEncryptedProperties, Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
ReferenceEncryptedProperties()
          Instantiates a new encrypted properties.
ReferenceEncryptedProperties(Properties defaults)
           
 
Method Summary
 Enumeration elements()
          This method has been overridden to throw an UnsupportedOperationException
 Set entrySet()
          This method has been overridden to throw an UnsupportedOperationException
 String getProperty(String key)
          Gets the property value from the encrypted store, decrypts it, and returns the plaintext value to the caller.
 String getProperty(String key, String defaultValue)
          
 void list(PrintStream out)
          This method has been overridden to throw an UnsupportedOperationException
 void list(PrintWriter out)
          This method has been overridden to throw an UnsupportedOperationException
 void load(InputStream in)
          Reads a property list (key and element pairs) from the input stream.
 void load(Reader in)
           For JDK 1.5 compatibility, this method has been overridden convert the Reader into an InputStream and call the superclass constructor.
 Object put(Object key, Object value)
          This method has been overridden to only accept Strings for key and value, and to encrypt those Strings before storing them.
 String setProperty(String key, String value)
          Encrypts the plaintext property value and stores the ciphertext value in the encrypted store.
 String toString()
          This method has been overridden to not print out the keys and values stored in this properties file.
 Collection values()
          This method has been overridden to throw an UnsupportedOperationException
 
Methods inherited from class java.util.Properties
loadFromXML, propertyNames, save, store, store, storeToXML, storeToXML, stringPropertyNames
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, equals, get, hashCode, isEmpty, keys, keySet, putAll, rehash, remove, size
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.owasp.esapi.EncryptedProperties
keySet, store
 

Constructor Detail

ReferenceEncryptedProperties

public ReferenceEncryptedProperties()
Instantiates a new encrypted properties.


ReferenceEncryptedProperties

public ReferenceEncryptedProperties(Properties defaults)
Method Detail

getProperty

public String getProperty(String key)
                   throws EncryptionRuntimeException
Gets the property value from the encrypted store, decrypts it, and returns the plaintext value to the caller.

Specified by:
getProperty in interface EncryptedProperties
Overrides:
getProperty in class 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 String getProperty(String key,
                          String defaultValue)
                   throws EncryptionRuntimeException

Overrides:
getProperty in class Properties
Throws:
EncryptionRuntimeException - Thrown if decryption fails.

setProperty

public String setProperty(String key,
                          String value)
                   throws EncryptionRuntimeException
Encrypts the plaintext property value and stores the ciphertext value in the encrypted store.

Specified by:
setProperty in interface EncryptedProperties
Overrides:
setProperty in class Properties
Parameters:
key - the name of the property to set
value - the value of the property to set
Returns:
the previously encrypted property value for the specified key, or null if it did not have one.
Throws:
EncryptionRuntimeException - Thrown if encryption fails.

load

public void load(InputStream in)
          throws IOException
Reads a property list (key and element pairs) from the input stream.

Specified by:
load in interface EncryptedProperties
Overrides:
load in class Properties
Parameters:
in - the input stream that contains the properties file
Throws:
IOException - Thrown if input stream invalid or does not correspond to Java properties file format.

load

public void load(Reader in)
          throws IOException
For JDK 1.5 compatibility, this method has been overridden convert the Reader into an InputStream and call the superclass constructor.

Overrides:
load in class Properties
Throws:
IOException - Thrown if Reader input stream invalid or does not correspond to Java properties file format.

list

public void list(PrintStream out)
This method has been overridden to throw an UnsupportedOperationException

Overrides:
list in class Properties

list

public void list(PrintWriter out)
This method has been overridden to throw an UnsupportedOperationException

Overrides:
list in class Properties

values

public Collection values()
This method has been overridden to throw an UnsupportedOperationException

Specified by:
values in interface Map<Object,Object>
Overrides:
values in class Hashtable<Object,Object>

entrySet

public Set entrySet()
This method has been overridden to throw an UnsupportedOperationException

Specified by:
entrySet in interface Map<Object,Object>
Overrides:
entrySet in class Hashtable<Object,Object>

elements

public Enumeration elements()
This method has been overridden to throw an UnsupportedOperationException

Overrides:
elements in class Hashtable<Object,Object>

put

public Object put(Object key,
                  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 use setProperty to add values to the Properties map. If an outside class does erroneously call this method with non-String parameters an IllegalArgumentException will be thrown.

Specified by:
put in interface Map<Object,Object>
Overrides:
put in class Hashtable<Object,Object>
Parameters:
key - A String key to add
value - A String value to add
Returns:
The old value associated with the specified key, or null if the key did not exist.

toString

public String toString()
This method has been overridden to not print out the keys and values stored in this properties file.

Overrides:
toString in class Hashtable<Object,Object>
Returns:
The minimal String representation of this class, as per java.lang.Object.


Copyright © 2013 The Open Web Application Security Project (OWASP). All Rights Reserved.