public final class Credential extends Object implements Serializable
A given client can support a different set of credential for each database the client is accessing. The client can also authenticate against the "admin" database which will apply across all databases.
Note: While we use the term user name/password within this class the values may not actually be a user name or a password. In addition not all authentication mechanisms may use all of the fields in this class. See the documentation for the authenticator being used for details on what values are expected for each of the fields in this class.
Modifier and Type | Class and Description |
---|---|
static class |
Credential.Builder
Builder provides a helper for creating a
Credential . |
Modifier and Type | Field and Description |
---|---|
static String |
ADMIN_DB
The name of the administration database used to authenticate a
administrator to MongoDB.
|
static String |
KERBEROS
Constant for Kerberos authentication.
|
static String |
MONGODB_CR
Constant for traditional MongoDB Challenge/Response.
|
static char[] |
NO_PASSWORD
An empty password array.
|
static String |
PLAIN_SASL
Constant for authentication using plain SASL (LDAP/PAM) client
certificates passed at connection establishment.
|
static String |
X509
Constant for authentication using x.509 client certificates passed at
connection establishment.
|
Constructor and Description |
---|
Credential(Credential.Builder builder)
Creates a new Credential.
|
Modifier and Type | Method and Description |
---|---|
Authenticator |
authenticator()
Returns an authenticator for the credential.
|
static Credential.Builder |
builder()
Creates a
Credential.Builder for creating a Credential . |
boolean |
equals(Object object) |
String |
getAuthenticationType()
Returns the authentication type or mode that the credential should be
used with.
|
Authenticator |
getAuthenticator()
Returns the authenticator value.
|
String |
getDatabase()
Returns the database the credential are valid for.
|
File |
getFile()
Returns the file containing the full credentials.
|
boolean |
getOption(String optionName,
boolean defaultValue)
Returns the option value.
|
int |
getOption(String optionName,
int defaultValue)
Returns the option value.
|
String |
getOption(String optionName,
String defaultValue)
Returns the option value.
|
char[] |
getPassword()
Returns the password for the credential set.
|
String |
getUserName()
Returns the user name for the credential set.
|
int |
hashCode() |
boolean |
hasPassword()
Returns true if the password has atleast a single character.
|
String |
toString() |
public static final String ADMIN_DB
public static final String KERBEROS
Note: Use of the Kerberos for authentication requires the driver's extensions. See the Kerberos Usage Guide for details.
public static final String MONGODB_CR
public static final char[] NO_PASSWORD
public static final String PLAIN_SASL
Note: Use of Plain SASL for authentication requires the driver's extensions. See the Plain SASL Usage Guide for details.
public static final String X509
Note: Use of the x.509 for authentication requires the driver's extensions. See the TLS/SSL Usage Guide for details.
public Credential(Credential.Builder builder)
builder
- The builder for the credentials.public static Credential.Builder builder()
Credential.Builder
for creating a Credential
.Credential.Builder
for creating a Credential
.public Authenticator authenticator() throws MongoDbAuthenticationException
MongoDbAuthenticationException
- On a failure to load the authenticator for the credential.public boolean equals(Object object)
Overridden to return true if the passed value equals these credential.
public String getAuthenticationType()
public Authenticator getAuthenticator()
public String getDatabase()
ADMIN_DB
to authenticate as an administrator.public File getFile()
null
.public boolean getOption(String optionName, boolean defaultValue)
optionName
- The name of the option to set.defaultValue
- The value of the option if it is not set or cannot be parsed
via Boolean.parseBoolean(String)
.public int getOption(String optionName, int defaultValue)
optionName
- The name of the option to set.defaultValue
- The value of the option if it is not set or cannot be parsed
via Integer.parseInt(String)
.public String getOption(String optionName, String defaultValue)
optionName
- The name of the option to set.defaultValue
- The value of the option if it is not set.public char[] getPassword()
Arrays.fill(password, 0)
public String getUserName()
public int hashCode()
Overridden to hash the credential.
public boolean hasPassword()
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.