public class Credentials extends Object implements IXMLConfigurable, Serializable
User credentials with an optionally encrypted password. To be encrypted, there needs to be an encryption key. Without one, the password is assumed not to be encrypted.
Passwords can be encrypted using EncryptionUtil
(or
command-line "encrypt.bat" or "encrypt.sh" if those are available to you).
In order for the password to be decrypted properly, you need
to specify the encryption key used to encrypt it. The key can obtained
from a few supported locations. The combination of the password key
"value" and "source" is used to properly locate the key.
The supported sources are:
key |
The actual encryption key. |
file |
Path to a file containing the encryption key. |
environment |
Name of an environment variable containing the key. |
property |
Name of a JVM system property containing the key. |
<username>(the username)</username>
<password>(the optionally encrypted password)</password>
<passwordKey>
<value>(The actual password encryption key or a reference to it.)</value>
<source>[key|file|environment|property]</source>
<size>(Size in bits of encryption key. Default is 128.)</size>
</passwordKey>
The expected parent tag name is defined by the consuming classes.
<sampleConfig>
<username>goldorak</username>
<password>3ncryp73d</password>
<passwordKey>
<value>/path/to/my.key</value>
<source>file</source>
</passwordKey>
</sampleConfig>
The above example has the password encrypted with a key. The encryption key is stored in a file (required to decrypt the password).
EncryptionKey
,
EncryptionUtil
,
Serialized FormConstructor and Description |
---|
Credentials() |
Credentials(Credentials copy) |
Modifier and Type | Method and Description |
---|---|
void |
copyFrom(Credentials creds) |
void |
copyTo(Credentials creds) |
boolean |
equals(Object other) |
String |
getPassword() |
EncryptionKey |
getPasswordKey() |
String |
getUsername() |
int |
hashCode() |
boolean |
isEmpty() |
boolean |
isSet() |
void |
loadFromXML(XML xml)
Load XML configuration values and initialized this object with them.
|
void |
saveToXML(XML xml)
Saves this object as XML.
|
Credentials |
setPassword(String password) |
Credentials |
setPasswordKey(EncryptionKey passwordKey) |
Credentials |
setUsername(String username) |
String |
toString() |
public Credentials()
public Credentials(Credentials copy)
public boolean isSet()
public boolean isEmpty()
public String getPassword()
public Credentials setPassword(String password)
public EncryptionKey getPasswordKey()
public Credentials setPasswordKey(EncryptionKey passwordKey)
public String getUsername()
public Credentials setUsername(String username)
public void copyTo(Credentials creds)
public void copyFrom(Credentials creds)
public void loadFromXML(XML xml)
IXMLConfigurable
loadFromXML
in interface IXMLConfigurable
xml
- the XML to load into this objectpublic void saveToXML(XML xml)
IXMLConfigurable
saveToXML
in interface IXMLConfigurable
xml
- the XML that will representing this objectCopyright © 2008–2023 Norconex Inc.. All rights reserved.