com.jp.protection.pub
Class FileSecretStorage

java.lang.Object
  extended by com.jp.protection.pub.FileSecretStorage
All Implemented Interfaces:
SecretStorage
Direct Known Subclasses:
JarFileSecretStorage

public class FileSecretStorage
extends java.lang.Object
implements SecretStorage

Default implementation of the SecretStorage interface that stores data in a local file

See Also:
SecretStorage

Nested Class Summary
protected static class FileSecretStorage.DecodeInputStream
           
protected static class FileSecretStorage.DecryptInputStream
           
protected static class FileSecretStorage.EncodeOutputStream
           
protected static class FileSecretStorage.EncryptOutputStream
           
static class FileSecretStorage.Provider
           
 
Field Summary
protected  boolean fDirty
           
protected  java.lang.String fFileName
           
protected  java.lang.String fFolder
           
protected  boolean fLoaded
           
protected  java.util.Properties fProperties
           
protected  boolean fSkipEncryption
           
protected  boolean fUseLockFile
           
protected  boolean fUserHomeRelative
           
protected  boolean fUseStrongEncryption
           
protected  boolean fVerbose
           
 
Constructor Summary
FileSecretStorage()
          Creates a new instance of FileSecretStorage
FileSecretStorage(java.lang.String aFolder, java.lang.String aFileName)
          Creates a new instance of FileSecretStorage and initializes it
FileSecretStorage(java.lang.String aFolder, java.lang.String aFileName, boolean aUserHomeRelative)
          Creates a new instance of FileSecretStorage and initializes it
FileSecretStorage(java.lang.String aFolder, java.lang.String aFileName, boolean aUserHomeRelative, boolean aUseStrongEncryption)
          Creates a new instance of FileSecretStorage and initializes it
FileSecretStorage(java.lang.String aFolder, java.lang.String aFileName, boolean aUserHomeRelative, boolean aUseStrongEncryption, boolean aUseLockFile)
          Creates a new instance of FileSecretStorage and initializes it
 
Method Summary
protected  java.lang.String composePassword(java.io.File aFile)
           
protected  void error(java.lang.Throwable ex)
           
protected  void fileLockError(java.io.File aFile)
           
protected  long generateTimestamp(java.io.File aFile)
           
protected static javax.crypto.Cipher getCipher(boolean isEncrypt, java.lang.String aPassword)
           
 java.io.File getFile()
          Returns the secret storage file
 java.lang.String getFileName()
          Returns the name of the storage file
 java.lang.String getFolder()
          Returns the folder of the storage file
protected  java.io.InputStream getInputStream()
           
protected  java.io.OutputStream getOutputStream()
           
protected  java.util.Properties getProperties()
           
 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
protected  long getTimestamp(java.io.File aFile)
           
 boolean isDirty()
          Checks whether secret storage is changed
protected  boolean isLoaded()
           
 boolean isSkipEncryption()
          Checks whether encryption should be skipped during storage saving
 boolean isUseLockFile()
          Checks whether a lock file should be used to prevent concurrent modifications of the Secret Storage
 boolean isUserHomeRelative()
          Checks whether folder to find storage file is relative to the user home.
 boolean isUseStrongEncryption()
          Checks whether strong encryption should be used
 boolean isVerbose()
          Checks whether verbose output is enabled.
 void load()
          Loads Secret Storage from a file and takes care on avoiding synchronization conflicts.
protected  void loadImpl()
           
 void save()
          Saves Secret Storage to a file and takes care on avoiding synchronization conflicts.
protected  void saveImpl()
           
 void setDirty(boolean aDirty)
          Specifies that secret storage is changed
 void setFileName(java.lang.String aFileName)
          Specifies the name of the storage file
 void setFolder(java.lang.String aFolder)
          Specifies the folder of the storage file
protected  void setLoaded(boolean aLoaded)
           
 java.lang.Object setProperty(java.lang.String key, java.lang.String value)
          Specifies property value for the given key
 void setSkipEncryption(boolean aSkipEncryption)
          Specifies that encryption should be skipped during storage saving
 void setUseLockFile(boolean useLockFile)
          Specifies whether a lock file should be used to prevent concurrent modifications of the Secret Storage
 void setUserHomeRelative(boolean aUserHomeRelative)
          Specifies that folder to find storage file is relative to the user home.
 void setUseStrongEncryption(boolean aUseStrongEncryption)
          Specifies that strong encryption should be used
 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

fFileName

protected java.lang.String fFileName

fFolder

protected java.lang.String fFolder

fUserHomeRelative

protected boolean fUserHomeRelative

fProperties

protected java.util.Properties fProperties

fDirty

protected boolean fDirty

fLoaded

protected boolean fLoaded

fVerbose

protected boolean fVerbose

fUseLockFile

protected boolean fUseLockFile

fSkipEncryption

protected boolean fSkipEncryption

fUseStrongEncryption

protected boolean fUseStrongEncryption
Constructor Detail

FileSecretStorage

public FileSecretStorage()
Creates a new instance of FileSecretStorage


FileSecretStorage

public FileSecretStorage(java.lang.String aFolder,
                         java.lang.String aFileName)
Creates a new instance of FileSecretStorage and initializes it

Parameters:
aFolder - a folder to locate secret storage file
aFileName - a name of secret storage file

FileSecretStorage

public FileSecretStorage(java.lang.String aFolder,
                         java.lang.String aFileName,
                         boolean aUserHomeRelative)
Creates a new instance of FileSecretStorage and initializes it

Parameters:
aFolder - folder to locate secret storage file
aFileName - a name of secret storage file
aUserHomeRelative - specifies whether a folder is user HOME folder relative

FileSecretStorage

public FileSecretStorage(java.lang.String aFolder,
                         java.lang.String aFileName,
                         boolean aUserHomeRelative,
                         boolean aUseStrongEncryption)
Creates a new instance of FileSecretStorage and initializes it

Parameters:
aFolder - folder to locate secret storage file
aFileName - a name of secret storage file
aUserHomeRelative - specifies whether a folder is user HOME folder relative
aUseStrongEncryption - specifies whether strong encryption should be used

FileSecretStorage

public FileSecretStorage(java.lang.String aFolder,
                         java.lang.String aFileName,
                         boolean aUserHomeRelative,
                         boolean aUseStrongEncryption,
                         boolean aUseLockFile)
Creates a new instance of FileSecretStorage and initializes it

Parameters:
aFolder - folder to locate secret storage file
aFileName - a name of secret storage file
aUserHomeRelative - specifies whether a folder is user HOME folder relative
aUseStrongEncryption - specifies whether strong encryption should be used
aUseLockFile - specifies whether lock file (.lck) should be used to prevent concurrent modifications of the Secret Storage
Method Detail

isUserHomeRelative

public boolean isUserHomeRelative()
Checks whether folder to find storage file is relative to the user home.

Returns:
true if folder to find storage file is relative to the user home; false otherwise.

getFileName

public java.lang.String getFileName()
Returns the name of the storage file

Returns:
the name of the storage file

setFileName

public void setFileName(java.lang.String aFileName)
Specifies the name of the storage file

Parameters:
aFileName - a name of the storage file to assign

getFolder

public java.lang.String getFolder()
Returns the folder of the storage file

Returns:
the folder of the storage file

setFolder

public void setFolder(java.lang.String aFolder)
Specifies the folder of the storage file

Parameters:
aFolder - a folder of the storage file to assign

setUserHomeRelative

public void setUserHomeRelative(boolean aUserHomeRelative)
Specifies that folder to find storage file is relative to the user home.

Parameters:
aUserHomeRelative - true if folder to find storage file is relative to the user home; false otherwise.

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.

setLoaded

protected void setLoaded(boolean aLoaded)

getProperties

protected java.util.Properties getProperties()

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

isLoaded

protected boolean isLoaded()

isDirty

public boolean isDirty()
Checks whether secret storage is changed

Returns:
true if secret storage is changed; false otherwise

setDirty

public void setDirty(boolean aDirty)
Specifies that secret storage is changed

Parameters:
aDirty - true if secret storage should be marked as changed; false otherwise

load

public final void load()
Loads Secret Storage from a file and takes care on avoiding synchronization conflicts. Override loadImpl() method to make custom implementation of Secret Storage loading

Specified by:
load in interface SecretStorage

loadImpl

protected void loadImpl()

fileLockError

protected void fileLockError(java.io.File aFile)

generateTimestamp

protected long generateTimestamp(java.io.File aFile)

getTimestamp

protected long getTimestamp(java.io.File aFile)

save

public final void save()
Saves Secret Storage to a file and takes care on avoiding synchronization conflicts. Override saveImpl() method to make custom implementation of Secret Storage saving

Specified by:
save in interface SecretStorage

saveImpl

protected void saveImpl()

isSkipEncryption

public boolean isSkipEncryption()
Checks whether encryption should be skipped during storage saving

Returns:
true if encryption should be skipped during storage saving; false otherwise

setSkipEncryption

public void setSkipEncryption(boolean aSkipEncryption)
Specifies that encryption should be skipped during storage saving

Parameters:
aSkipEncryption - true if encryption should be skipped during storage saving; false otherwise

isUseLockFile

public boolean isUseLockFile()
Checks whether a lock file should be used to prevent concurrent modifications of the Secret Storage

Returns:
true if a lock file will be used to prevent concurrent modifications of the Secret Storage; false otherwise

setUseLockFile

public void setUseLockFile(boolean useLockFile)
Specifies whether a lock file should be used to prevent concurrent modifications of the Secret Storage

Parameters:
useLockFile - true if a lock file should be used to prevent concurrent modifications of the Secret Storage; false otherwise

isUseStrongEncryption

public boolean isUseStrongEncryption()
Checks whether strong encryption should be used

Returns:
true if strong encryption will be used; false otherwise

setUseStrongEncryption

public void setUseStrongEncryption(boolean aUseStrongEncryption)
Specifies that strong encryption should be used

Parameters:
aUseStrongEncryption - true if strong encryption should be used; * false otherwise

getFile

public java.io.File getFile()
Returns the secret storage file

Returns:
a secret storage file

getInputStream

protected java.io.InputStream getInputStream()

composePassword

protected java.lang.String composePassword(java.io.File aFile)

getOutputStream

protected java.io.OutputStream getOutputStream()

error

protected void error(java.lang.Throwable ex)

getCipher

protected static javax.crypto.Cipher getCipher(boolean isEncrypt,
                                               java.lang.String aPassword)