Class Credentials
- java.lang.Object
-
- com.norconex.commons.lang.security.Credentials
-
- All Implemented Interfaces:
IXMLConfigurable
,Serializable
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.
Password encryption:
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. XML configuration usage:
<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.
XML usage example:
<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).
- Since:
- 2.0.0
- Author:
- Pascal Essiembre
- See Also:
EncryptionKey
,EncryptionUtil
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Credentials()
Credentials(Credentials copy)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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()
-
-
-
Constructor Detail
-
Credentials
public Credentials()
-
Credentials
public Credentials(Credentials copy)
-
-
Method Detail
-
isSet
public boolean isSet()
-
isEmpty
public boolean isEmpty()
-
getPassword
public String getPassword()
-
setPassword
public Credentials setPassword(String password)
-
getPasswordKey
public EncryptionKey getPasswordKey()
-
setPasswordKey
public Credentials setPasswordKey(EncryptionKey passwordKey)
-
getUsername
public String getUsername()
-
setUsername
public Credentials setUsername(String username)
-
copyTo
public void copyTo(Credentials creds)
-
copyFrom
public void copyFrom(Credentials creds)
-
loadFromXML
public void loadFromXML(XML xml)
Description copied from interface:IXMLConfigurable
Load XML configuration values and initialized this object with them.- Specified by:
loadFromXML
in interfaceIXMLConfigurable
- Parameters:
xml
- the XML to load into this object
-
saveToXML
public void saveToXML(XML xml)
Description copied from interface:IXMLConfigurable
Saves this object as XML.- Specified by:
saveToXML
in interfaceIXMLConfigurable
- Parameters:
xml
- the XML that will representing this object
-
-