com.jp.protection.pub
Class PreferencesSecretStorage

java.lang.Object
  extended by com.jp.protection.pub.PreferencesSecretStorage
All Implemented Interfaces:
SecretStorage

public class PreferencesSecretStorage
extends java.lang.Object
implements SecretStorage

Implementation of SecretStorage that stores properties using the Preferences API. Clients provide their own instance of Preferences. Clients can also specify whether or not to encrypt the properties. Encryption is enabled by default.


Nested Class Summary
static class PreferencesSecretStorage.Provider
          Provider responsible of creation new PreferencesSecretStorage instances
 
Field Summary
protected  boolean fVerbose
           
 
Constructor Summary
PreferencesSecretStorage(java.util.prefs.Preferences preferences)
          Creates a new PreferencesSecretStorage that uses the specified preferences.
PreferencesSecretStorage(java.util.prefs.Preferences preferences, boolean skipEncryption)
          Creates a new PreferencesSecretStorage that uses the specified preferences and encryption scheme.
PreferencesSecretStorage(java.lang.String aNodeName, boolean isUserPreferences)
          Creates a new PreferencesSecretStorage that uses the specified preferences.
PreferencesSecretStorage(java.lang.String aNodeName, boolean isUserPreferences, boolean skipEncryption)
          Creates a new PreferencesSecretStorage that uses the specified preferences.
 
Method Summary
protected  void error(java.lang.Throwable ex)
           
 java.util.prefs.Preferences getPreferences()
          Returns the preferences in which this secret storage's properties are stored.
 java.lang.String getProperty(java.lang.String key)
          Gets property value by its key
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          Gets property value by its key
 boolean isSkipEncryption()
          Returns true if this secret storage does not encrypt its properties.
 boolean isVerbose()
          Checks whether verbose output is enabled.
 void load()
          Loads the storage from some persistent state
 void save()
          Saves the storage to some persistent state
 void setPreferences(java.util.prefs.Preferences preferences)
          Sets the preferences in which this secret storage's properties are stored to the specified preferences.
 java.lang.Object setProperty(java.lang.String key, java.lang.String value)
          Specifies property value for the given key
 void setVerbose(boolean aVerbose)
          Specifies that verbose output is enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fVerbose

protected boolean fVerbose
Constructor Detail

PreferencesSecretStorage

public PreferencesSecretStorage(java.lang.String aNodeName,
                                boolean isUserPreferences,
                                boolean skipEncryption)
Creates a new PreferencesSecretStorage that uses the specified preferences.

Parameters:
aNodeName - name of the node to put preferences to. The "." denotes path names used to employ hierarchical preferences. For example "com.acme.app" defines node with the "/com/acme/app" absolute path.
isUserPreferences - specifies whether User of System preferences should be used
skipEncryption - true to not use encryption and false to use it.

PreferencesSecretStorage

public PreferencesSecretStorage(java.lang.String aNodeName,
                                boolean isUserPreferences)
Creates a new PreferencesSecretStorage that uses the specified preferences. This constructor just calls this(aNodeName, isUserPreferences, false).

Parameters:
aNodeName - name of the node to put preferences to. The "." denotes path names used to employ hierarchical preferences. For example "com.acme.app" defines node with the "/com/acme/app" absolute path.
isUserPreferences - specifies whether User of System preferences should be used

PreferencesSecretStorage

public PreferencesSecretStorage(java.util.prefs.Preferences preferences)
Creates a new PreferencesSecretStorage that uses the specified preferences. This constructor just calls this(preferences, false).

Parameters:
preferences - preferences in which to store the properties.
Throws:
java.lang.NullPointerException - if the specified preferences is null.

PreferencesSecretStorage

public PreferencesSecretStorage(java.util.prefs.Preferences preferences,
                                boolean skipEncryption)
Creates a new PreferencesSecretStorage that uses the specified preferences and encryption scheme.

Parameters:
preferences - preferences in which to store the properties.
skipEncryption - true to not use encryption and false to use it.
Throws:
java.lang.NullPointerException - if the specified preferences is null.
Method Detail

getProperty

public java.lang.String getProperty(java.lang.String key)
Description copied from interface: SecretStorage
Gets property value by its key

Specified by:
getProperty in interface SecretStorage
Parameters:
key - identifies value to return
Returns:
property value

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)
Description copied from interface: SecretStorage
Gets property value by its key

Specified by:
getProperty in interface SecretStorage
Parameters:
key - identifies value to be return
defaultValue - a value should be returned if there is no value for the given key
Returns:
property value

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    java.lang.String value)
Description copied from interface: SecretStorage
Specifies property value for the given key

Specified by:
setProperty in interface SecretStorage
Parameters:
key - identifies value to specify
value - value to be associated with the key
Returns:
previous property value

load

public void load()
Description copied from interface: SecretStorage
Loads the storage from some persistent state

Specified by:
load in interface SecretStorage

save

public void save()
Description copied from interface: SecretStorage
Saves the storage to some persistent state

Specified by:
save in interface SecretStorage

getPreferences

public java.util.prefs.Preferences getPreferences()
Returns the preferences in which this secret storage's properties are stored.

Returns:
the preferences in which this secret storage's properties are stored.

setPreferences

public void setPreferences(java.util.prefs.Preferences preferences)
Sets the preferences in which this secret storage's properties are stored to the specified preferences.

Parameters:
preferences - preferences in which to store the properties.
Throws:
java.lang.NullPointerException - if the specified preferences is null.

isSkipEncryption

public boolean isSkipEncryption()
Returns true if this secret storage does not encrypt its properties.

Returns:
true if this secret storage does not encrypt its properties.

isVerbose

public boolean isVerbose()
Checks whether verbose output is enabled.

Returns:
true if verbose output is enabled; false otherwise.

setVerbose

public void setVerbose(boolean aVerbose)
Specifies that verbose output is enabled.

Parameters:
aVerbose - true if verbose output should be enabled; false otherwise.

error

protected void error(java.lang.Throwable ex)