Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

JAVA-691: Renamed MongoCredentials to MongoCredential and moved inner…

… Protocol enum to top level enum MongoAuthenticationProtocol
  • Loading branch information...
commit f5150708b4f8bb9fe0eadf94f2b2501cc8c1f951 1 parent 021bc1d
@jyemin jyemin authored
View
5 examples/GSSAPICredentialsExample.java
@@ -15,9 +15,10 @@
*/
import com.mongodb.DB;
+import com.mongodb.MongoAuthenticationProtocol;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
-import com.mongodb.MongoCredentials;
+import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import java.net.UnknownHostException;
@@ -67,7 +68,7 @@ public static void main(String[] args) throws UnknownHostException, InterruptedE
System.out.println();
MongoClient mongoClient = new MongoClient(new ServerAddress(server),
- Arrays.asList(new MongoCredentials(user, MongoCredentials.Protocol.GSSAPI)),
+ Arrays.asList(new MongoCredential(user, MongoAuthenticationProtocol.GSSAPI)),
new MongoClientOptions.Builder().socketKeepAlive(true).socketTimeout(30000).build());
DB testDB = mongoClient.getDB(databaseName);
View
5 examples/NegotiatedAuthenticationProtocolExample.java
@@ -16,9 +16,10 @@
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
+import com.mongodb.MongoAuthenticationProtocol;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
-import com.mongodb.MongoCredentials;
+import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import java.net.UnknownHostException;
@@ -40,7 +41,7 @@ public static void main(String[] args) throws UnknownHostException, InterruptedE
String pwd = args[2];
String db = args[3];
- MongoCredentials credentials = new MongoCredentials(user, pwd.toCharArray(), MongoCredentials.Protocol.NEGOTIATE, db);
+ MongoCredential credentials = new MongoCredential(user, pwd.toCharArray(), MongoAuthenticationProtocol.NEGOTIATE, db);
MongoClient mongoClient = new MongoClient(new ServerAddress(server), Arrays.asList(credentials), new MongoClientOptions.Builder().build());
View
6 src/main/com/mongodb/DB.java
@@ -614,7 +614,7 @@ public synchronized CommandResult authenticateCommand(String username, char[] pa
}
private CommandResultPair authenticateCommandHelper(String username, char[] password) {
- MongoCredentials credentials = new MongoCredentials(username, password, MongoCredentials.Protocol.NEGOTIATE, getName());
+ MongoCredential credentials = new MongoCredential(username, password, MongoAuthenticationProtocol.NEGOTIATE, getName());
if (getAuthenticationCredentials() != null) {
if (getAuthenticationCredentials().equals(credentials)) {
@@ -647,7 +647,7 @@ public CommandResultPair(final CommandResult.CommandFailure failure) {
}
}
- abstract CommandResult doAuthenticate(MongoCredentials credentials);
+ abstract CommandResult doAuthenticate(MongoCredential credentials);
/**
* Adds a new user for this db
@@ -804,7 +804,7 @@ public int getOptions(){
public abstract void cleanCursors( boolean force );
- MongoCredentials getAuthenticationCredentials() {
+ MongoCredential getAuthenticationCredentials() {
return getMongo().getAuthority().getCredentialsStore().get(getName());
}
View
2  src/main/com/mongodb/DBApiLayer.java
@@ -176,7 +176,7 @@ void killCursors( ServerAddress addr , List<Long> all ){
}
@Override
- CommandResult doAuthenticate(MongoCredentials credentials) {
+ CommandResult doAuthenticate(MongoCredential credentials) {
return _connector.authenticate(credentials);
}
View
2  src/main/com/mongodb/DBConnector.java
@@ -112,5 +112,5 @@ public Response call( DB db , DBCollection coll , OutMessage m ,
* @throws com.mongodb.CommandResult.CommandFailure if the authentication failed
* @since 2.11.0
*/
- public CommandResult authenticate(MongoCredentials credentials);
+ public CommandResult authenticate(MongoCredential credentials);
}
View
22 src/main/com/mongodb/DBPort.java
@@ -311,11 +311,11 @@ protected void close(){
_socket = null;
}
- CommandResult authenticate(Mongo mongo, final MongoCredentials credentials) {
+ CommandResult authenticate(Mongo mongo, final MongoCredential credentials) {
Authenticator authenticator;
- if (credentials.getProtocol() == MongoCredentials.Protocol.NEGOTIATE) {
+ if (credentials.getProtocol() == MongoAuthenticationProtocol.NEGOTIATE) {
authenticator = getStrongestAuthenticator(mongo, credentials);
- } else if (credentials.getProtocol().equals(MongoCredentials.Protocol.GSSAPI)) {
+ } else if (credentials.getProtocol().equals(MongoAuthenticationProtocol.GSSAPI)) {
authenticator = new GSSAPIAuthenticator(mongo, credentials);
} else {
throw new IllegalArgumentException("Unsupported authentication protocol: " + credentials.getProtocol());
@@ -335,7 +335,7 @@ void checkAuth(Mongo mongo) throws IOException {
}
}
- private Authenticator getStrongestAuthenticator(final Mongo mongo, MongoCredentials credentials) {
+ private Authenticator getStrongestAuthenticator(final Mongo mongo, MongoCredential credentials) {
if (useCRAMAuthenticationProtocol == null) {
cacheStrongestAuthenticationProtocol(mongo);
}
@@ -407,7 +407,7 @@ public DBPortPool getPool() {
private final String mechanism;
- GenericSaslAuthenticator(final Mongo mongo, MongoCredentials credentials, String mechanism) {
+ GenericSaslAuthenticator(final Mongo mongo, MongoCredential credentials, String mechanism) {
super(mongo, credentials);
this.mechanism = mechanism;
}
@@ -456,10 +456,10 @@ public void handle(final Callback[] callbacks) throws IOException, UnsupportedCa
public static final String GSSAPI_OID = "1.2.840.113554.1.2.2";
public static final String GSSAPI_MECHANISM = "GSSAPI";
- GSSAPIAuthenticator(final Mongo mongo, final MongoCredentials credentials) {
+ GSSAPIAuthenticator(final Mongo mongo, final MongoCredential credentials) {
super(mongo, credentials);
- if (!this.credentials.getProtocol().equals(MongoCredentials.Protocol.GSSAPI)) {
+ if (!this.credentials.getProtocol().equals(MongoAuthenticationProtocol.GSSAPI)) {
throw new MongoException("Incorrect mechanism: " + this.credentials.getProtocol());
}
}
@@ -501,7 +501,7 @@ private GSSCredential getGSSCredential(String userName) throws GSSException {
abstract class SaslAuthenticator extends Authenticator {
public static final String MONGODB_PROTOCOL = "mongodb";
- SaslAuthenticator(final Mongo mongo, MongoCredentials credentials) {
+ SaslAuthenticator(final Mongo mongo, MongoCredential credentials) {
super(mongo, credentials);
}
@@ -558,7 +558,7 @@ private CommandResult sendSaslContinue(final int conversationId, final byte[] ou
}
class NativeAuthenticator extends Authenticator {
- NativeAuthenticator(Mongo mongo, MongoCredentials credentials) {
+ NativeAuthenticator(Mongo mongo, MongoCredential credentials) {
super(mongo, credentials);
}
@@ -581,9 +581,9 @@ public CommandResult authenticate() {
abstract class Authenticator {
protected final Mongo mongo;
- protected final MongoCredentials credentials;
+ protected final MongoCredential credentials;
- Authenticator(Mongo mongo, MongoCredentials credentials) {
+ Authenticator(Mongo mongo, MongoCredential credentials) {
this.mongo = mongo;
this.credentials = credentials;
}
View
2  src/main/com/mongodb/DBTCPConnector.java
@@ -597,7 +597,7 @@ public boolean isOpen(){
}
@Override
- public CommandResult authenticate(MongoCredentials credentials) {
+ public CommandResult authenticate(MongoCredential credentials) {
final MyPort mp = _myPort.get();
final DBPort port = mp.get(false, ReadPreference.primaryPreferred(), null);
View
57 src/main/com/mongodb/MongoAuthenticationProtocol.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2008 - 2013 10gen, Inc. <http://10gen.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.mongodb;
+
+/**
+ * An enumeration of the supported authentication protocols.
+ */
+public enum MongoAuthenticationProtocol {
+ /**
+ * The GSSAPI protocol, to support Kerberos v5 via a SASL-based authentication protocol
+ */
+ GSSAPI {
+ /**
+ * The default source for GSSAPI is a reserved name that doesn't correspond to any database.
+ * @return the default source.
+ */
+ @Override
+ public String getDefaultSource() {
+ return "$external";
+ }
+ },
+ /**
+ * Negotiate the strongest available protocol available. This is the default protocol.
+ */
+ NEGOTIATE {
+ /**
+ * The default source is the "admin" database.
+ * @return
+ */
+ @Override
+ public String getDefaultSource() {
+ return "admin";
+ }
+ };
+
+ /**
+ * Gets the default source for this mechanism, usually a database name.
+ *
+ * @return the default database for this protocol
+ */
+ public abstract String getDefaultSource();
+}
View
8 src/main/com/mongodb/MongoAuthority.java
@@ -52,7 +52,7 @@
* @return
*/
public static MongoAuthority direct(ServerAddress serverAddress) {
- return direct(serverAddress, (MongoCredentials) null);
+ return direct(serverAddress, (MongoCredential) null);
}
/**
@@ -61,7 +61,7 @@ public static MongoAuthority direct(ServerAddress serverAddress) {
* @param credentials
* @return
*/
- public static MongoAuthority direct(ServerAddress serverAddress, MongoCredentials credentials) {
+ public static MongoAuthority direct(ServerAddress serverAddress, MongoCredential credentials) {
return direct(serverAddress, new MongoCredentialsStore(credentials));
}
@@ -81,7 +81,7 @@ public static MongoAuthority direct(ServerAddress serverAddress, MongoCredential
* @return
*/
public static MongoAuthority dynamicSet(List<ServerAddress> serverAddresses) {
- return dynamicSet(serverAddresses, (MongoCredentials) null);
+ return dynamicSet(serverAddresses, (MongoCredential) null);
}
/**
@@ -90,7 +90,7 @@ public static MongoAuthority dynamicSet(List<ServerAddress> serverAddresses) {
* @param credentials
* @return
*/
- public static MongoAuthority dynamicSet(List<ServerAddress> serverAddresses, MongoCredentials credentials) {
+ public static MongoAuthority dynamicSet(List<ServerAddress> serverAddresses, MongoCredential credentials) {
return dynamicSet(serverAddresses, new MongoCredentialsStore(credentials));
}
View
10 src/main/com/mongodb/MongoClient.java
@@ -135,7 +135,7 @@ public MongoClient(ServerAddress addr) {
* @see com.mongodb.ServerAddress
* @since 2.11.0
*/
- public MongoClient(ServerAddress addr, List<MongoCredentials> credentialsList) {
+ public MongoClient(ServerAddress addr, List<MongoCredential> credentialsList) {
this(addr, credentialsList, new MongoClientOptions.Builder().build());
}
@@ -161,7 +161,7 @@ public MongoClient(ServerAddress addr, MongoClientOptions options) {
* @see com.mongodb.ServerAddress
* @since 2.11.0
*/
- public MongoClient(ServerAddress addr, List<MongoCredentials> credentialsList, MongoClientOptions options) {
+ public MongoClient(ServerAddress addr, List<MongoCredential> credentialsList, MongoClientOptions options) {
super(MongoAuthority.direct(addr, new MongoCredentialsStore(credentialsList)), new MongoOptions(options));
}
@@ -201,7 +201,7 @@ public MongoClient(List<ServerAddress> seeds) {
* @see com.mongodb.ServerAddress
* @since 2.11.0
*/
- public MongoClient(List<ServerAddress> seeds, List<MongoCredentials> credentialsList) {
+ public MongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsList) {
this(seeds, credentialsList, new MongoClientOptions.Builder().build());
}
@@ -244,7 +244,7 @@ public MongoClient(List<ServerAddress> seeds, MongoClientOptions options) {
* @see com.mongodb.ServerAddress
* @since 2.11.0
*/
- public MongoClient(List<ServerAddress> seeds, List<MongoCredentials> credentialsList, MongoClientOptions options) {
+ public MongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsList, MongoClientOptions options) {
super(MongoAuthority.dynamicSet(seeds, new MongoCredentialsStore(credentialsList)), new MongoOptions(options));
}
@@ -268,7 +268,7 @@ public MongoClient(MongoClientURI uri) throws UnknownHostException {
* @return the list of credentials
* @since 2.11.0
*/
- public List<MongoCredentials> getCredentialsList() {
+ public List<MongoCredential> getCredentialsList() {
return getAuthority().getCredentialsStore().asList();
}
}
View
12 src/main/com/mongodb/MongoClientURI.java
@@ -375,13 +375,13 @@ private ReadPreference createReadPreference(final Map<String, List<String>> opti
return buildReadPreference(readPreferenceType, firstTagSet, remainingTagSets, slaveOk);
}
- private MongoCredentials createCredentials(Map<String, List<String>> optionsMap, final String userName,
+ private MongoCredential createCredentials(Map<String, List<String>> optionsMap, final String userName,
final char[] password, String database) {
if (userName == null) {
return null;
}
- MongoCredentials.Protocol protocol = MongoCredentials.Protocol.NEGOTIATE;
+ MongoAuthenticationProtocol protocol = MongoAuthenticationProtocol.NEGOTIATE;
String authSource = database;
for (String key : authKeys) {
@@ -392,13 +392,13 @@ private MongoCredentials createCredentials(Map<String, List<String>> optionsMap,
}
if (key.equals("authprotocol")) {
- protocol = MongoCredentials.Protocol.valueOf(value);
+ protocol = MongoAuthenticationProtocol.valueOf(value);
} else if (key.equals("authsource")) {
authSource = value;
}
}
- return new MongoCredentials(userName, password, protocol, authSource);
+ return new MongoCredential(userName, password, protocol, authSource);
}
private String getLastValue(final Map<String, List<String>> optionsMap, final String key) {
@@ -551,7 +551,7 @@ public String getURI() {
*
* @return the credentials
*/
- public MongoCredentials getCredentials() {
+ public MongoCredential getCredentials() {
return credentials;
}
@@ -567,7 +567,7 @@ public MongoClientOptions getOptions() {
// ---------------------------------
private final MongoClientOptions options;
- private final MongoCredentials credentials;
+ private final MongoCredential credentials;
private final List<String> hosts;
private final String database;
private final String collection;
View
71 src/main/com/mongodb/MongoCredentials.java → src/main/com/mongodb/MongoCredential.java
@@ -28,60 +28,21 @@
* @since 2.11.0
*/
@Immutable
-public class MongoCredentials {
+public class MongoCredential {
- private final Protocol protocol;
+ private final MongoAuthenticationProtocol protocol;
private final String userName;
private final char[] password;
private final String source;
/**
- * An enumeration of the supported authentication protocols.
- */
- public enum Protocol {
- /**
- * The GSSAPI protocol, to support Kerberos v5 via a SASL-based authentication protocol
- */
- GSSAPI {
- /**
- * The default source for GSSAPI is a reserved name that doesn't correspond to any database.
- * @return the default source.
- */
- @Override
- public String getDefaultSource() {
- return "$external";
- }
- },
- /**
- * Negotiate the strongest available protocol available. This is the default protocol.
- */
- NEGOTIATE {
- /**
- * The default source is the "admin" database.
- * @return
- */
- @Override
- public String getDefaultSource() {
- return "admin";
- }
- };
-
- /**
- * Gets the default source for this mechanism, usually a database name.
- *
- * @return the default database for this protocol
- */
- public abstract String getDefaultSource();
- }
-
- /**
* Constructs a new instance using the given user name and password and the default protocol and source.
*
* @param userName the user name
* @param password the password
*/
- public MongoCredentials(final String userName, final char[] password) {
- this(userName, password, Protocol.NEGOTIATE);
+ public MongoCredential(final String userName, final char[] password) {
+ this(userName, password, MongoAuthenticationProtocol.NEGOTIATE);
}
/**
@@ -91,8 +52,8 @@ public MongoCredentials(final String userName, final char[] password) {
* @param password the password
* @param source the source of the credentials
*/
- public MongoCredentials(final String userName, final char[] password, String source) {
- this(userName, password, Protocol.NEGOTIATE, source);
+ public MongoCredential(final String userName, final char[] password, String source) {
+ this(userName, password, MongoAuthenticationProtocol.NEGOTIATE, source);
}
/**
@@ -102,7 +63,7 @@ public MongoCredentials(final String userName, final char[] password, String sou
* @param password the password
* @param protocol the protocol to use for authentication
*/
- public MongoCredentials(final String userName, final char[] password, Protocol protocol) {
+ public MongoCredential(final String userName, final char[] password, MongoAuthenticationProtocol protocol) {
this(userName, password, protocol, null);
}
@@ -113,7 +74,7 @@ public MongoCredentials(final String userName, final char[] password, Protocol p
* @param userName the user name
* @param protocol the protocol to use for authentication
*/
- public MongoCredentials(final String userName, final Protocol protocol) {
+ public MongoCredential(final String userName, final MongoAuthenticationProtocol protocol) {
this(userName, null, protocol);
}
@@ -126,7 +87,7 @@ public MongoCredentials(final String userName, final Protocol protocol) {
* @param protocol the protocol
* @param source the source of the credentials
*/
- public MongoCredentials(final String userName, final char[] password, Protocol protocol, String source) {
+ public MongoCredential(final String userName, final char[] password, MongoAuthenticationProtocol protocol, String source) {
if (userName == null) {
throw new IllegalArgumentException();
}
@@ -134,12 +95,12 @@ public MongoCredentials(final String userName, final char[] password, Protocol p
throw new IllegalArgumentException();
}
- if (protocol == Protocol.NEGOTIATE && password == null) {
- throw new IllegalArgumentException("password can not be null for " + Protocol.NEGOTIATE);
+ if (protocol == MongoAuthenticationProtocol.NEGOTIATE && password == null) {
+ throw new IllegalArgumentException("password can not be null for " + MongoAuthenticationProtocol.NEGOTIATE);
}
- if (protocol == Protocol.GSSAPI && password != null) {
- throw new IllegalArgumentException("password must be null for " + Protocol.GSSAPI);
+ if (protocol == MongoAuthenticationProtocol.GSSAPI && password != null) {
+ throw new IllegalArgumentException("password must be null for " + MongoAuthenticationProtocol.GSSAPI);
}
this.userName = userName;
@@ -153,7 +114,7 @@ public MongoCredentials(final String userName, final char[] password, Protocol p
*
* @return the mechanism. Can be null if the mechanism should be negotiated.
*/
- public Protocol getProtocol() {
+ public MongoAuthenticationProtocol getProtocol() {
return protocol;
}
@@ -192,7 +153,7 @@ public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
- final MongoCredentials that = (MongoCredentials) o;
+ final MongoCredential that = (MongoCredential) o;
if (!Arrays.equals(password, that.password)) return false;
if (protocol != that.protocol) return false;
@@ -221,7 +182,7 @@ public String toString() {
'}';
}
- private String getDefaultDatabase(final Protocol protocol) {
+ private String getDefaultDatabase(final MongoAuthenticationProtocol protocol) {
if (protocol == null) {
return "admin";
} else {
View
18 src/main/com/mongodb/MongoCredentialsStore.java
@@ -38,7 +38,7 @@
*/
@ThreadSafe
class MongoCredentialsStore {
- private final Map<String, MongoCredentials> credentialsMap = new HashMap<String, MongoCredentials>();
+ private final Map<String, MongoCredential> credentialsMap = new HashMap<String, MongoCredential>();
private volatile Set<String> allDatabasesWithCredentials = new HashSet<String>();
/**
@@ -52,7 +52,7 @@ public MongoCredentialsStore() {
*
* @param credentials A single credentials, which may be null.
*/
- public MongoCredentialsStore(MongoCredentials credentials) {
+ public MongoCredentialsStore(MongoCredential credentials) {
if (credentials == null) {
return;
}
@@ -64,11 +64,11 @@ public MongoCredentialsStore(MongoCredentials credentials) {
*
* @param credentialsList The list of credentials
*/
- public MongoCredentialsStore(Iterable<MongoCredentials> credentialsList) {
+ public MongoCredentialsStore(Iterable<MongoCredential> credentialsList) {
if (credentialsList == null) {
return;
}
- for (MongoCredentials cur : credentialsList) {
+ for (MongoCredential cur : credentialsList) {
add(cur);
}
}
@@ -79,8 +79,8 @@ public MongoCredentialsStore(Iterable<MongoCredentials> credentialsList) {
* @param credentials the new credentials
* @throws IllegalArgumentException if there already exist different credentials for the same database
*/
- synchronized void add(MongoCredentials credentials) {
- MongoCredentials existingCredentials = credentialsMap.get(credentials.getSource());
+ synchronized void add(MongoCredential credentials) {
+ MongoCredential existingCredentials = credentialsMap.get(credentials.getSource());
if (existingCredentials != null) {
if (existingCredentials.equals(credentials)) {
@@ -109,7 +109,7 @@ synchronized void add(MongoCredentials credentials) {
* @param database the database. This can be null, to get the credentials with the null database.
* @return the credentials for the given database. Can be null if not are stored.
*/
- public synchronized MongoCredentials get(String database) {
+ public synchronized MongoCredential get(String database) {
return credentialsMap.get(database);
}
@@ -117,8 +117,8 @@ public synchronized MongoCredentials get(String database) {
* Gets the MongoCredentials in this map as a List
* @return the list of credentials
*/
- public synchronized List<MongoCredentials> asList() {
- return new ArrayList<MongoCredentials>(credentialsMap.values());
+ public synchronized List<MongoCredential> asList() {
+ return new ArrayList<MongoCredential>(credentialsMap.values());
}
@Override
View
2  src/main/com/mongodb/MongoURI.java
@@ -190,7 +190,7 @@ public String getCollection(){
*
* @since 2.11.0
*/
- public MongoCredentials getCredentials() {
+ public MongoCredential getCredentials() {
return mongoClientURI.getCredentials();
}
View
6 src/test/com/mongodb/DBPortTest.java
@@ -44,8 +44,8 @@ public void testAuthentication() throws IOException {
assertEquals(expected, port.authenticatedDatabases);
- m.getAuthority().getCredentialsStore().add(new MongoCredentials("u1", "e".toCharArray(), "DBPortTest1"));
- m.getAuthority().getCredentialsStore().add(new MongoCredentials("u2", "e".toCharArray(), "DBPortTest2"));
+ m.getAuthority().getCredentialsStore().add(new MongoCredential("u1", "e".toCharArray(), "DBPortTest1"));
+ m.getAuthority().getCredentialsStore().add(new MongoCredential("u2", "e".toCharArray(), "DBPortTest2"));
port.checkAuth(m);
@@ -53,7 +53,7 @@ public void testAuthentication() throws IOException {
expected.add("DBPortTest2");
assertEquals(expected, port.authenticatedDatabases);
- m.getAuthority().getCredentialsStore().add(new MongoCredentials("u2", "e".toCharArray(), "DBPortTest3"));
+ m.getAuthority().getCredentialsStore().add(new MongoCredential("u2", "e".toCharArray(), "DBPortTest3"));
try {
port.checkAuth(m);
View
2  src/test/com/mongodb/JavaClientTest.java
@@ -661,7 +661,7 @@ public void testAuthenticate() throws UnknownHostException {
assertNull(db.getAuthenticationCredentials());
assertNull(_mongo.getAuthority().getCredentialsStore().get(db.getName()));
assertEquals(true, db.authenticate("xx", "e".toCharArray()));
- assertEquals(new MongoCredentials("xx", "e".toCharArray(), db.getName()), db.getAuthenticationCredentials());
+ assertEquals(new MongoCredential("xx", "e".toCharArray(), db.getName()), db.getAuthenticationCredentials());
assertEquals(db.getAuthenticationCredentials(), m.getAuthority().getCredentialsStore().get(db.getName()));
assertEquals(true, db.authenticate( "xx" , "e".toCharArray() ) );
View
4 src/test/com/mongodb/MongoClientTest.java
@@ -30,7 +30,7 @@ public void testConstructors() throws UnknownHostException {
MongoClientOptions customClientOptions = new MongoClientOptions.Builder().connectionsPerHost(500).build();
MongoOptions customOptions = new MongoOptions(customClientOptions);
MongoOptions defaultOptions = new MongoOptions(new MongoClientOptions.Builder().build());
- List<MongoCredentials> emptyCredentials = Arrays.asList();
+ List<MongoCredential> emptyCredentials = Arrays.asList();
MongoClient mc;
mc = new MongoClient();
@@ -63,7 +63,7 @@ public void testConstructors() throws UnknownHostException {
Assert.assertEquals(emptyCredentials, mc.getCredentialsList());
mc.close();
- final List<MongoCredentials> credentialsList = Arrays.asList(new MongoCredentials("user1", "pwd".toCharArray(), "test"));
+ final List<MongoCredential> credentialsList = Arrays.asList(new MongoCredential("user1", "pwd".toCharArray(), "test"));
mc = new MongoClient(new ServerAddress("127.0.0.1"), credentialsList);
Assert.assertEquals(new ServerAddress("127.0.0.1"), mc.getAddress());
Assert.assertEquals(defaultOptions, mc.getMongoOptions());
View
10 src/test/com/mongodb/MongoClientURITest.java
@@ -85,22 +85,22 @@ public void testUserPass() {
assertEquals("host", u.getHosts().get(0));
assertEquals("user", u.getUsername());
assertEquals("pass", new String(u.getPassword()));
- assertEquals(new MongoCredentials("user", "pass".toCharArray(), MongoCredentials.Protocol.NEGOTIATE, "bar"), u.getCredentials());
+ assertEquals(new MongoCredential("user", "pass".toCharArray(), MongoAuthenticationProtocol.NEGOTIATE, "bar"), u.getCredentials());
u = new MongoClientURI("mongodb://user@host/?authProtocol=GSSAPI");
- assertEquals(new MongoCredentials("user", MongoCredentials.Protocol.GSSAPI), u.getCredentials());
+ assertEquals(new MongoCredential("user", MongoAuthenticationProtocol.GSSAPI), u.getCredentials());
u = new MongoClientURI("mongodb://user:pass@host/?authSource=test");
- assertEquals(new MongoCredentials("user", "pass".toCharArray(), "test"), u.getCredentials());
+ assertEquals(new MongoCredential("user", "pass".toCharArray(), "test"), u.getCredentials());
u = new MongoClientURI("mongodb://user:pass@host");
- assertEquals(new MongoCredentials("user", "pass".toCharArray(), "admin"), u.getCredentials());
+ assertEquals(new MongoCredential("user", "pass".toCharArray(), "admin"), u.getCredentials());
}
@Test
public void testURIEncoding() {
MongoClientURI u = new MongoClientURI("mongodb://use%24:he%21%21o@localhost");
- assertEquals(new MongoCredentials("use$", "he!!o".toCharArray()), u.getCredentials());
+ assertEquals(new MongoCredential("use$", "he!!o".toCharArray()), u.getCredentials());
}
@Test()
View
40 src/test/com/mongodb/MongoCredentialsTest.java → src/test/com/mongodb/MongoCredentialTest.java
@@ -25,51 +25,51 @@
import java.util.List;
import java.util.Set;
-public class MongoCredentialsTest extends TestCase {
+public class MongoCredentialTest extends TestCase {
@Test
public void testCredentials() {
- MongoCredentials credentials;
+ MongoCredential credentials;
- credentials = new MongoCredentials("user", "pwd".toCharArray());
+ credentials = new MongoCredential("user", "pwd".toCharArray());
assertEquals("user", credentials.getUserName());
assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
- assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
+ assertEquals(MongoAuthenticationProtocol.NEGOTIATE, credentials.getProtocol());
assertEquals("admin", credentials.getSource());
- credentials = new MongoCredentials("user", "pwd".toCharArray(), "test");
+ credentials = new MongoCredential("user", "pwd".toCharArray(), "test");
assertEquals("user", credentials.getUserName());
assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
- assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
+ assertEquals(MongoAuthenticationProtocol.NEGOTIATE, credentials.getProtocol());
assertEquals("test", credentials.getSource());
- credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.NEGOTIATE);
+ credentials = new MongoCredential("user", "pwd".toCharArray(), MongoAuthenticationProtocol.NEGOTIATE);
assertEquals("user", credentials.getUserName());
assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
- assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
+ assertEquals(MongoAuthenticationProtocol.NEGOTIATE, credentials.getProtocol());
assertEquals("admin", credentials.getSource());
- credentials = new MongoCredentials("user", MongoCredentials.Protocol.GSSAPI);
+ credentials = new MongoCredential("user", MongoAuthenticationProtocol.GSSAPI);
assertEquals("user", credentials.getUserName());
assertNull(credentials.getPassword());
- assertEquals(MongoCredentials.Protocol.GSSAPI, credentials.getProtocol());
+ assertEquals(MongoAuthenticationProtocol.GSSAPI, credentials.getProtocol());
assertEquals("$external", credentials.getSource());
- credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.NEGOTIATE, "test");
+ credentials = new MongoCredential("user", "pwd".toCharArray(), MongoAuthenticationProtocol.NEGOTIATE, "test");
assertEquals("user", credentials.getUserName());
assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
- assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
+ assertEquals(MongoAuthenticationProtocol.NEGOTIATE, credentials.getProtocol());
assertEquals("test", credentials.getSource());
try {
- new MongoCredentials("user", null, MongoCredentials.Protocol.NEGOTIATE, "test");
+ new MongoCredential("user", null, MongoAuthenticationProtocol.NEGOTIATE, "test");
fail("STRONGEST must have a password");
} catch (IllegalArgumentException e) {
// all good
}
try {
- new MongoCredentials("user", "a".toCharArray(), MongoCredentials.Protocol.GSSAPI);
+ new MongoCredential("user", "a".toCharArray(), MongoAuthenticationProtocol.GSSAPI);
fail("GSSAPI must not have a password");
} catch (IllegalArgumentException e) {
// all good
@@ -85,11 +85,11 @@ public void testCredentialsStore() {
assertTrue(store.getDatabases().isEmpty());
assertNull(store.get("test"));
- store = new MongoCredentialsStore((MongoCredentials) null);
+ store = new MongoCredentialsStore((MongoCredential) null);
assertTrue(store.getDatabases().isEmpty());
assertNull(store.get("test"));
- MongoCredentials credentials = new MongoCredentials("user", password);
+ MongoCredential credentials = new MongoCredential("user", password);
store = new MongoCredentialsStore(credentials);
Set<String> expected;
expected = new HashSet<String>();
@@ -98,10 +98,10 @@ public void testCredentialsStore() {
assertEquals(credentials, store.get("admin"));
assertNull(store.get("test"));
- List<MongoCredentials> credentialsList;
+ List<MongoCredential> credentialsList;
- final MongoCredentials credentials1 = new MongoCredentials("user", password, "db1");
- final MongoCredentials credentials2 = new MongoCredentials("user", "pwd".toCharArray(), "db2");
+ final MongoCredential credentials1 = new MongoCredential("user", password, "db1");
+ final MongoCredential credentials2 = new MongoCredential("user", "pwd".toCharArray(), "db2");
credentialsList = Arrays.asList(credentials1, credentials2);
store = new MongoCredentialsStore(credentialsList);
expected = new HashSet<String>();
@@ -113,7 +113,7 @@ public void testCredentialsStore() {
assertNull(store.get("db3"));
assertEquals(credentialsList, store.asList());
- credentialsList = Arrays.asList(credentials1, new MongoCredentials("user2", password, "db1"));
+ credentialsList = Arrays.asList(credentials1, new MongoCredential("user2", password, "db1"));
try {
new MongoCredentialsStore(credentialsList);
fail("should throw");
View
2  src/test/com/mongodb/MongoURITest.java
@@ -32,7 +32,7 @@ public void testGetters() {
MongoURI mongoURI = new MongoURI( "mongodb://user:pwd@localhost/test.mongoURITest?safe=false");
assertEquals("user", mongoURI.getUsername());
assertEquals("pwd", new String(mongoURI.getPassword()));
- assertEquals(new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.NEGOTIATE, "test"), mongoURI.getCredentials());
+ assertEquals(new MongoCredential("user", "pwd".toCharArray(), MongoAuthenticationProtocol.NEGOTIATE, "test"), mongoURI.getCredentials());
assertEquals(Arrays.asList("localhost"), mongoURI.getHosts());
assertEquals("test", mongoURI.getDatabase());
assertEquals("mongoURITest", mongoURI.getCollection());
Please sign in to comment.
Something went wrong with that request. Please try again.