com.novell.nds.dirxml.shimhost
Class Password

java.lang.Object
  extended bycom.novell.nds.dirxml.shimhost.Password
All Implemented Interfaces:
ConfigElement
Direct Known Subclasses:
NamedPasswords.NamedPassword

public class Password
extends Object
implements ConfigElement

Encapsulation of common password behavior needed by other classes in this package.


Field Summary
protected  boolean modified
           
static String TAG_PASSWORD
          Default tag name for XML element enclosing password data
static char ZERO_CHAR
          Convenience value: ''
 
Constructor Summary
Password()
          Create an empty Password instance.
Password(char[] plainPassword)
          Create a Password instance with the passed plain password value and a default tag name of "password".
Password(char[] plainPassword, char[] pwdPassword)
          Create a Password instance with the passed plain password value and a default tag name of "password".
Password(Element pwdElement, boolean secure)
          Construct a Password instance from an Element containing password data.
Password(Node parent, boolean secure)
          Construct a Password instance from a <password> element.
Password(Node parent, String tagName, boolean secure)
          Construct a Password instance from an element with the passed tag name.
 
Method Summary
 void clear()
          Set the password to null.
static void clearPassword(char[] passwordChars)
          Convenience method to fill an array of characters with zero.
protected  void finalize()
          Finalizer.
 char[] getPassword()
          Get the plaintext password value from this instance.
 char[] getPassword(char[] pwdPassword)
          Get the plaintext password value from this instance.
 String getTagName()
          Get the tag name to use for XML representations of this instance.
 boolean hasBeenModified()
          Return true if this instance has been modified.
 boolean isEmpty()
          Return whether or not there is a non-empty password set.
 boolean isEmpty(char[] pwdPassword)
          Return whether or not there is a non-empty password set.
 boolean isEncrypted()
          Return true if the password associated with this instance is encrypted.
 void resetModified()
          Reset the modified flag for this instance such that hasBeenModified() will return false.
 void setEncrypted(char[] passwordPwd)
          Encrypt the unencrypted password associated with this instance.
 void setPassword(byte[] passwordData)
          Set encrypted password data for this instance.
 void setPassword(char[] password)
          Set the plaintext password value for this instance.
 void setPassword(char[] password, char[] passwordPwd)
          Set an encrypted password for this instance.
 void setTagName(String tagName)
          Set the tag name to use for XML representations of this instance
 void setUnencrypted(char[] passwordPwd)
          Unencrypt the encryped password associated with this instance.
 Element toXML(Node parent)
          Construct an XML representation of this Password instance.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG_PASSWORD

public static final String TAG_PASSWORD
Default tag name for XML element enclosing password data

See Also:
Constant Field Values

ZERO_CHAR

public static final char ZERO_CHAR
Convenience value: ''

See Also:
Constant Field Values

modified

protected boolean modified
Constructor Detail

Password

public Password()
Create an empty Password instance.


Password

public Password(char[] plainPassword)
Create a Password instance with the passed plain password value and a default tag name of "password".

Parameters:
plainPassword - password characters

Password

public Password(char[] plainPassword,
                char[] pwdPassword)
         throws CipherException
Create a Password instance with the passed plain password value and a default tag name of "password". The plain password value will be encrypted using the "password password" parameter.

Parameters:
plainPassword - password characters
pwdPassword - password used to encrypt the plain password characters
Throws:
CipherException - if an error occurs while encrypting the plaintext password

Password

public Password(Node parent,
                boolean secure)
         throws XMLException
Construct a Password instance from a <password> element.

Parameters:
parent - Node with a <password> element child
secure - true if the content of the <password> element is base-64 encoded encrypted password data
Throws:
XMLException - if the XML data is incorrect

Password

public Password(Node parent,
                String tagName,
                boolean secure)
         throws XMLException
Construct a Password instance from an element with the passed tag name.

Parameters:
parent - Node with an element child containing password data
tagName - name of element containing password data
secure - true if the content of the <password> element is base-64 encoded encrypted password data
Throws:
XMLException - if the XML data is incorrect

Password

public Password(Element pwdElement,
                boolean secure)
         throws IllegalArgumentException,
                XMLException
Construct a Password instance from an Element containing password data.

Parameters:
pwdElement - Element containing password data
secure - true if the content of the <password> element is base-64 encoded encrypted password data
Throws:
XMLException - if the XML data is incorrect
IllegalArgumentException - if pwdElement is null
Method Detail

hasBeenModified

public boolean hasBeenModified()
Return true if this instance has been modified.

The instance is considered to have been modified if a change was made that affects the persistent representation since:

  1. The instance was constructed from an XML representation.
  2. resetModified() was last called

Specified by:
hasBeenModified in interface ConfigElement
Returns:
true or false
See Also:
resetModified(), toXML(org.w3c.dom.Node)

resetModified

public void resetModified()
Reset the modified flag for this instance such that hasBeenModified() will return false.

Specified by:
resetModified in interface ConfigElement
See Also:
hasBeenModified()

clearPassword

public static void clearPassword(char[] passwordChars)
Convenience method to fill an array of characters with zero.

Parameters:
passwordChars - char array to clear

toXML

public Element toXML(Node parent)
Construct an XML representation of this Password instance. The tag name associated with this instance is used to construct the containing Element.

Note that the act of creating an XML representation does not reset this instance's modified flag. It must be reset by calling resetModified().

Specified by:
toXML in interface ConfigElement
Parameters:
parent - Node under which to construct XML representation
Returns:
constructed Element
See Also:
hasBeenModified(), resetModified()

getTagName

public String getTagName()
Get the tag name to use for XML representations of this instance.

Returns:
element tag name

setTagName

public void setTagName(String tagName)
                throws IllegalArgumentException
Set the tag name to use for XML representations of this instance

Parameters:
tagName - tag name
Throws:
IllegalArgumentException - if tagName is null, empty, or doesn't match the XML Name production

isEmpty

public boolean isEmpty()
                throws IllegalStateException
Return whether or not there is a non-empty password set.

This will return true if no password is set, or the empty string has been set.

Returns:
true if no password or empty string is password
Throws:
IllegalStateException - thrown if the password is encrypted

isEmpty

public boolean isEmpty(char[] pwdPassword)
                throws CipherException
Return whether or not there is a non-empty password set.

This will return true if no password is set, or the empty string has been set.

Parameters:
pwdPassword - password value for decrypting the encrypted password value for this instance.
Returns:
true if no password or empty string is password
Throws:
CipherException - thrown if an error occurs decrypting the password

clear

public void clear()
Set the password to null.


getPassword

public char[] getPassword()
                   throws IllegalStateException
Get the plaintext password value from this instance. This returns a copy of the password, so it may be manipulated in any way desired (such as cleared when finished with).

Returns:
character array containing the password chars, or null
Throws:
IllegalStateException - if the password is encrypted (use getPassword(final char [] pwdPassword) instead

getPassword

public char[] getPassword(char[] pwdPassword)
                   throws CipherException
Get the plaintext password value from this instance. This returns a copy of the password, so it may be manipulated in any way desired (such as cleared when finished with).

Parameters:
pwdPassword - password value for decrypting the encrypted password value for this instance.
Returns:
character array containing the password chars, or null
Throws:
CipherException - if an error occurs decrypting the password

setPassword

public void setPassword(char[] password)
Set the plaintext password value for this instance.

Parameters:
password - the plaintext password characters

setPassword

public void setPassword(byte[] passwordData)
Set encrypted password data for this instance.

Parameters:
passwordData - encrypted password data bytes

setPassword

public void setPassword(char[] password,
                        char[] passwordPwd)
                 throws CipherException
Set an encrypted password for this instance.

Parameters:
password - plaintext password characters
passwordPwd - password with which to encrypt the plaintext password
Throws:
CipherException - if an error occurs while encrypting the plaintext password value.

isEncrypted

public boolean isEncrypted()
Return true if the password associated with this instance is encrypted.

Returns:
true or false

setEncrypted

public void setEncrypted(char[] passwordPwd)
                  throws IllegalStateException,
                         CipherException
Encrypt the unencrypted password associated with this instance.

Parameters:
passwordPwd - password used to encrypt the password associated with this instance.
Throws:
IllegalStateException - if password is already encrypted
CipherException - if an error occurs while encrypting the plaintext password value.

setUnencrypted

public void setUnencrypted(char[] passwordPwd)
                    throws CipherException
Unencrypt the encryped password associated with this instance.

Parameters:
passwordPwd - password needed to unencrypt the password associated with this instance.
Throws:
CipherException - if an error occurs decrypting the password

finalize

protected void finalize()
Finalizer. Clean up and clear any password data.