public class Password extends java.lang.Object implements ConfigElement
Modifier and Type | Field and Description |
---|---|
protected boolean |
modified |
static java.lang.String |
TAG_PASSWORD
Default tag name for XML element enclosing password data
|
static char |
ZERO_CHAR
Convenience value: ' '
|
Constructor and Description |
---|
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(org.w3c.dom.Element pwdElement,
boolean secure)
Construct a Password instance from an Element containing password data.
|
Password(org.w3c.dom.Node parent,
boolean secure)
Construct a Password instance from a <password> element.
|
Password(org.w3c.dom.Node parent,
java.lang.String tagName,
boolean secure)
Construct a Password instance from an element with the passed tag name.
|
Modifier and Type | Method and Description |
---|---|
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.
|
java.lang.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(java.lang.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.
|
org.w3c.dom.Element |
toXML(org.w3c.dom.Node parent)
Construct an XML representation of this Password instance.
|
public static final java.lang.String TAG_PASSWORD
public static final char ZERO_CHAR
protected boolean modified
public Password()
Password
instance.public Password(char[] plainPassword)
plainPassword
- password characterspublic Password(char[] plainPassword, char[] pwdPassword) throws CipherException
plainPassword
- password characterspwdPassword
- password used to encrypt the plain password charactersCipherException
- if an error occurs while encrypting the
plaintext passwordpublic Password(org.w3c.dom.Node parent, boolean secure) throws XMLException
parent
- Node with a <password> element childsecure
- true if the content of the <password> element is
base-64 encoded encrypted password dataXMLException
- if the XML data is incorrectpublic Password(org.w3c.dom.Node parent, java.lang.String tagName, boolean secure) throws XMLException
parent
- Node with an element child containing password datatagName
- name of element containing password datasecure
- true if the content of the <password> element is
base-64 encoded encrypted password dataXMLException
- if the XML data is incorrectpublic Password(org.w3c.dom.Element pwdElement, boolean secure) throws java.lang.IllegalArgumentException, XMLException
pwdElement
- Element containing password datasecure
- true if the content of the <password> element is
base-64 encoded encrypted password dataXMLException
- if the XML data is incorrectjava.lang.IllegalArgumentException
- if pwdElement is nullpublic boolean hasBeenModified()
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:
resetModified()
was last calledhasBeenModified
in interface ConfigElement
true
or false
resetModified()
,
toXML(org.w3c.dom.Node)
public void resetModified()
hasBeenModified()
will return false
.resetModified
in interface ConfigElement
hasBeenModified()
public static void clearPassword(char[] passwordChars)
passwordChars
- char array to clearpublic org.w3c.dom.Element toXML(org.w3c.dom.Node parent)
resetModified()
.toXML
in interface ConfigElement
parent
- Node under which to construct XML representationhasBeenModified()
,
resetModified()
public java.lang.String getTagName()
public void setTagName(java.lang.String tagName) throws java.lang.IllegalArgumentException
tagName
- tag namejava.lang.IllegalArgumentException
- if tagName
is null
, empty, or
doesn't match the XML Name productionpublic boolean isEmpty() throws java.lang.IllegalStateException
true
if no password is set, or the empty string
has been set.true
if no password or empty string is passwordjava.lang.IllegalStateException
- thrown if the password is encryptedpublic boolean isEmpty(char[] pwdPassword) throws CipherException
pwdPassword
- password value for decrypting the encrypted password
value for this instance.true
if no password or empty string is passwordCipherException
- thrown if an error occurs decrypting the passwordpublic void clear()
null
.public char[] getPassword() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the password is encrypted
(use getPassword(final char [] pwdPassword) insteadpublic char[] getPassword(char[] pwdPassword) throws CipherException
pwdPassword
- password value for decrypting the encrypted password
value for this instance.CipherException
- if an error occurs decrypting the passwordpublic void setPassword(char[] password)
password
- the plaintext password characterspublic void setPassword(byte[] passwordData)
passwordData
- encrypted password data bytespublic void setPassword(char[] password, char[] passwordPwd) throws CipherException
password
- plaintext password characterspasswordPwd
- password with which to encrypt the plaintext passwordCipherException
- if an error occurs while encrypting the plaintext
password value.public boolean isEncrypted()
public void setEncrypted(char[] passwordPwd) throws java.lang.IllegalStateException, CipherException
passwordPwd
- password used to encrypt the password associated
with this instance.java.lang.IllegalStateException
- if password is already encryptedCipherException
- if an error occurs while encrypting the plaintext
password value.public void setUnencrypted(char[] passwordPwd) throws CipherException
passwordPwd
- password needed to unencrypt the password associated
with this instance.CipherException
- if an error occurs decrypting the passwordprotected void finalize()
finalize
in class java.lang.Object