Permalink
Browse files

JAVA-691: Change from STRONGEST to NEGOTIATE. Removed SERVER-8100 wor…

…karound
  • Loading branch information...
1 parent 1f07df6 commit 021bc1dabe4b2c2a603f673f8f456ffa7a9d0ac8 @jyemin jyemin committed Jan 29, 2013
@@ -15,14 +15,14 @@
*/
import com.mongodb.DB;
-import com.mongodb.MongoAuthority;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredentials;
import com.mongodb.ServerAddress;
import java.net.UnknownHostException;
import java.security.Security;
+import java.util.Arrays;
/**
* Example usage of Kerberos (GSSAPI) credentials.
@@ -66,9 +66,8 @@ public static void main(String[] args) throws UnknownHostException, InterruptedE
System.out.println();
- MongoClient mongoClient = new MongoClient(
- MongoAuthority.direct(new ServerAddress(server),
- new MongoCredentials(user, MongoCredentials.Protocol.GSSAPI)),
+ MongoClient mongoClient = new MongoClient(new ServerAddress(server),
+ Arrays.asList(new MongoCredentials(user, MongoCredentials.Protocol.GSSAPI)),
new MongoClientOptions.Builder().socketKeepAlive(true).socketTimeout(30000).build());
DB testDB = mongoClient.getDB(databaseName);
@@ -16,33 +16,33 @@
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
-import com.mongodb.MongoAuthority;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredentials;
import com.mongodb.ServerAddress;
import java.net.UnknownHostException;
+import java.util.Arrays;
/**
- * Example usage of STRONGEST authentication protocol.
+ * Example usage of NEGOTIATE authentication protocol.
* <p>
* Usage:
* </p>
* <pre>
- * java StrongestAuthenticationProtocolExample server userName password databaseName
+ * java NegotiatedAuthenticationProtocolExample server userName password databaseName
* </pre>
*/
-public class StrongestAuthenticationProtocolExample {
+public class NegotiatedAuthenticationProtocolExample {
public static void main(String[] args) throws UnknownHostException, InterruptedException {
String server = args[0];
String user = args[1];
String pwd = args[2];
String db = args[3];
- MongoCredentials credentials = new MongoCredentials(user, pwd.toCharArray(), MongoCredentials.Protocol.STRONGEST, db);
+ MongoCredentials credentials = new MongoCredentials(user, pwd.toCharArray(), MongoCredentials.Protocol.NEGOTIATE, db);
- MongoClient mongoClient = new MongoClient(MongoAuthority.direct(new ServerAddress(server), credentials), new MongoClientOptions.Builder().build());
+ MongoClient mongoClient = new MongoClient(new ServerAddress(server), Arrays.asList(credentials), new MongoClientOptions.Builder().build());
DB testDB = mongoClient.getDB(db);
testDB.getCollection("test").insert(new BasicDBObject());
@@ -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.STRONGEST, getName());
+ MongoCredentials credentials = new MongoCredentials(username, password, MongoCredentials.Protocol.NEGOTIATE, getName());
if (getAuthenticationCredentials() != null) {
if (getAuthenticationCredentials().equals(credentials)) {
@@ -313,7 +313,7 @@ protected void close(){
CommandResult authenticate(Mongo mongo, final MongoCredentials credentials) {
Authenticator authenticator;
- if (credentials.getProtocol() == MongoCredentials.Protocol.STRONGEST) {
+ if (credentials.getProtocol() == MongoCredentials.Protocol.NEGOTIATE) {
authenticator = getStrongestAuthenticator(mongo, credentials);
} else if (credentials.getProtocol().equals(MongoCredentials.Protocol.GSSAPI)) {
authenticator = new GSSAPIAuthenticator(mongo, credentials);
@@ -523,9 +523,6 @@ public CommandResult authenticate() {
res = sendSaslContinue(conversationId, response);
res.throwOnError();
- if (res.getCode() > 0) { // SEE https://jira.mongodb.org/browse/SERVER-8100
- throw new MongoException(res.getCode(), res.getErrorMessage());
- }
}
return res;
} catch (IOException e) {
@@ -125,7 +125,7 @@
* </ul>
* <p>Authentication configuration:</p>
* <ul>
- * <li>{@code authProtocol=STRONGEST|GSSAPI}: The authentication protocol to use. The default is STRONGEST.
+ * <li>{@code authProtocol=NEGOTIATE|GSSAPI}: The authentication protocol to use. The default is NEGOTIATE.
* </li>
* <li>{@code authSource=string}: The source of the authentication credentials. This is typically the database that
* the credentials have been created. The value defaults to the database specified in the path portion of the URI.
@@ -381,7 +381,7 @@ private MongoCredentials createCredentials(Map<String, List<String>> optionsMap,
return null;
}
- MongoCredentials.Protocol protocol = MongoCredentials.Protocol.STRONGEST;
+ MongoCredentials.Protocol protocol = MongoCredentials.Protocol.NEGOTIATE;
String authSource = database;
for (String key : authKeys) {
@@ -53,9 +53,9 @@ public String getDefaultSource() {
}
},
/**
- * Uses the strongest available protocol available. This is the default protocol.
+ * Negotiate the strongest available protocol available. This is the default protocol.
*/
- STRONGEST {
+ NEGOTIATE {
/**
* The default source is the "admin" database.
* @return
@@ -81,7 +81,7 @@ public String getDefaultSource() {
* @param password the password
*/
public MongoCredentials(final String userName, final char[] password) {
- this(userName, password, Protocol.STRONGEST);
+ this(userName, password, Protocol.NEGOTIATE);
}
/**
@@ -92,7 +92,7 @@ public MongoCredentials(final String userName, final char[] password) {
* @param source the source of the credentials
*/
public MongoCredentials(final String userName, final char[] password, String source) {
- this(userName, password, Protocol.STRONGEST, source);
+ this(userName, password, Protocol.NEGOTIATE, source);
}
/**
@@ -134,8 +134,8 @@ public MongoCredentials(final String userName, final char[] password, Protocol p
throw new IllegalArgumentException();
}
- if (protocol == Protocol.STRONGEST && password == null) {
- throw new IllegalArgumentException("password can not be null for " + Protocol.STRONGEST);
+ if (protocol == Protocol.NEGOTIATE && password == null) {
+ throw new IllegalArgumentException("password can not be null for " + Protocol.NEGOTIATE);
}
if (protocol == Protocol.GSSAPI && password != null) {
@@ -85,7 +85,7 @@ 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.STRONGEST, "bar"), u.getCredentials());
+ assertEquals(new MongoCredentials("user", "pass".toCharArray(), MongoCredentials.Protocol.NEGOTIATE, "bar"), u.getCredentials());
u = new MongoClientURI("mongodb://user@host/?authProtocol=GSSAPI");
assertEquals(new MongoCredentials("user", MongoCredentials.Protocol.GSSAPI), u.getCredentials());
@@ -34,19 +34,19 @@ public void testCredentials() {
credentials = new MongoCredentials("user", "pwd".toCharArray());
assertEquals("user", credentials.getUserName());
assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
- assertEquals(MongoCredentials.Protocol.STRONGEST, credentials.getProtocol());
+ assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
assertEquals("admin", credentials.getSource());
credentials = new MongoCredentials("user", "pwd".toCharArray(), "test");
assertEquals("user", credentials.getUserName());
assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
- assertEquals(MongoCredentials.Protocol.STRONGEST, credentials.getProtocol());
+ assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
assertEquals("test", credentials.getSource());
- credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.STRONGEST);
+ credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.NEGOTIATE);
assertEquals("user", credentials.getUserName());
assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
- assertEquals(MongoCredentials.Protocol.STRONGEST, credentials.getProtocol());
+ assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
assertEquals("admin", credentials.getSource());
credentials = new MongoCredentials("user", MongoCredentials.Protocol.GSSAPI);
@@ -55,14 +55,14 @@ public void testCredentials() {
assertEquals(MongoCredentials.Protocol.GSSAPI, credentials.getProtocol());
assertEquals("$external", credentials.getSource());
- credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.STRONGEST, "test");
+ credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.NEGOTIATE, "test");
assertEquals("user", credentials.getUserName());
assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
- assertEquals(MongoCredentials.Protocol.STRONGEST, credentials.getProtocol());
+ assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
assertEquals("test", credentials.getSource());
try {
- new MongoCredentials("user", null, MongoCredentials.Protocol.STRONGEST, "test");
+ new MongoCredentials("user", null, MongoCredentials.Protocol.NEGOTIATE, "test");
fail("STRONGEST must have a password");
} catch (IllegalArgumentException e) {
// all good
@@ -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.STRONGEST, "test"), mongoURI.getCredentials());
+ assertEquals(new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.NEGOTIATE, "test"), mongoURI.getCredentials());
assertEquals(Arrays.asList("localhost"), mongoURI.getHosts());
assertEquals("test", mongoURI.getDatabase());
assertEquals("mongoURITest", mongoURI.getCollection());

0 comments on commit 021bc1d

Please sign in to comment.