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:keyThe actual encryption key. filePath to a file containing the encryption key. environmentName of an environment variable containing the key. propertyName 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 voidcopyFrom(Credentials creds)voidcopyTo(Credentials creds)booleanequals(Object other)StringgetPassword()EncryptionKeygetPasswordKey()StringgetUsername()inthashCode()booleanisEmpty()booleanisSet()voidloadFromXML(XML xml)Load XML configuration values and initialized this object with them.voidsaveToXML(XML xml)Saves this object as XML.CredentialssetPassword(String password)CredentialssetPasswordKey(EncryptionKey passwordKey)CredentialssetUsername(String username)StringtoString()
-
-
-
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:IXMLConfigurableLoad XML configuration values and initialized this object with them.- Specified by:
loadFromXMLin interfaceIXMLConfigurable- Parameters:
xml- the XML to load into this object
-
saveToXML
public void saveToXML(XML xml)
Description copied from interface:IXMLConfigurableSaves this object as XML.- Specified by:
saveToXMLin interfaceIXMLConfigurable- Parameters:
xml- the XML that will representing this object
-
-