Skip to content

Commit 021bc1d

Browse files
committed
JAVA-691: Change from STRONGEST to NEGOTIATE. Removed SERVER-8100 workaround
1 parent 1f07df6 commit 021bc1d

File tree

9 files changed

+28
-32
lines changed

9 files changed

+28
-32
lines changed

examples/GSSAPICredentialsExample.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
*/
1616

1717
import com.mongodb.DB;
18-
import com.mongodb.MongoAuthority;
1918
import com.mongodb.MongoClient;
2019
import com.mongodb.MongoClientOptions;
2120
import com.mongodb.MongoCredentials;
2221
import com.mongodb.ServerAddress;
2322

2423
import java.net.UnknownHostException;
2524
import java.security.Security;
25+
import java.util.Arrays;
2626

2727
/**
2828
* Example usage of Kerberos (GSSAPI) credentials.
@@ -66,9 +66,8 @@ public static void main(String[] args) throws UnknownHostException, InterruptedE
6666

6767
System.out.println();
6868

69-
MongoClient mongoClient = new MongoClient(
70-
MongoAuthority.direct(new ServerAddress(server),
71-
new MongoCredentials(user, MongoCredentials.Protocol.GSSAPI)),
69+
MongoClient mongoClient = new MongoClient(new ServerAddress(server),
70+
Arrays.asList(new MongoCredentials(user, MongoCredentials.Protocol.GSSAPI)),
7271
new MongoClientOptions.Builder().socketKeepAlive(true).socketTimeout(30000).build());
7372
DB testDB = mongoClient.getDB(databaseName);
7473

examples/StrongestAuthenticationProtocolExample.java renamed to examples/NegotiatedAuthenticationProtocolExample.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@
1616

1717
import com.mongodb.BasicDBObject;
1818
import com.mongodb.DB;
19-
import com.mongodb.MongoAuthority;
2019
import com.mongodb.MongoClient;
2120
import com.mongodb.MongoClientOptions;
2221
import com.mongodb.MongoCredentials;
2322
import com.mongodb.ServerAddress;
2423

2524
import java.net.UnknownHostException;
25+
import java.util.Arrays;
2626

2727
/**
28-
* Example usage of STRONGEST authentication protocol.
28+
* Example usage of NEGOTIATE authentication protocol.
2929
* <p>
3030
* Usage:
3131
* </p>
3232
* <pre>
33-
* java StrongestAuthenticationProtocolExample server userName password databaseName
33+
* java NegotiatedAuthenticationProtocolExample server userName password databaseName
3434
* </pre>
3535
*/
36-
public class StrongestAuthenticationProtocolExample {
36+
public class NegotiatedAuthenticationProtocolExample {
3737
public static void main(String[] args) throws UnknownHostException, InterruptedException {
3838
String server = args[0];
3939
String user = args[1];
4040
String pwd = args[2];
4141
String db = args[3];
4242

43-
MongoCredentials credentials = new MongoCredentials(user, pwd.toCharArray(), MongoCredentials.Protocol.STRONGEST, db);
43+
MongoCredentials credentials = new MongoCredentials(user, pwd.toCharArray(), MongoCredentials.Protocol.NEGOTIATE, db);
4444

45-
MongoClient mongoClient = new MongoClient(MongoAuthority.direct(new ServerAddress(server), credentials), new MongoClientOptions.Builder().build());
45+
MongoClient mongoClient = new MongoClient(new ServerAddress(server), Arrays.asList(credentials), new MongoClientOptions.Builder().build());
4646

4747
DB testDB = mongoClient.getDB(db);
4848
testDB.getCollection("test").insert(new BasicDBObject());

src/main/com/mongodb/DB.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ public synchronized CommandResult authenticateCommand(String username, char[] pa
614614
}
615615

616616
private CommandResultPair authenticateCommandHelper(String username, char[] password) {
617-
MongoCredentials credentials = new MongoCredentials(username, password, MongoCredentials.Protocol.STRONGEST, getName());
617+
MongoCredentials credentials = new MongoCredentials(username, password, MongoCredentials.Protocol.NEGOTIATE, getName());
618618

619619
if (getAuthenticationCredentials() != null) {
620620
if (getAuthenticationCredentials().equals(credentials)) {

src/main/com/mongodb/DBPort.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ protected void close(){
313313

314314
CommandResult authenticate(Mongo mongo, final MongoCredentials credentials) {
315315
Authenticator authenticator;
316-
if (credentials.getProtocol() == MongoCredentials.Protocol.STRONGEST) {
316+
if (credentials.getProtocol() == MongoCredentials.Protocol.NEGOTIATE) {
317317
authenticator = getStrongestAuthenticator(mongo, credentials);
318318
} else if (credentials.getProtocol().equals(MongoCredentials.Protocol.GSSAPI)) {
319319
authenticator = new GSSAPIAuthenticator(mongo, credentials);
@@ -523,9 +523,6 @@ public CommandResult authenticate() {
523523

524524
res = sendSaslContinue(conversationId, response);
525525
res.throwOnError();
526-
if (res.getCode() > 0) { // SEE https://jira.mongodb.org/browse/SERVER-8100
527-
throw new MongoException(res.getCode(), res.getErrorMessage());
528-
}
529526
}
530527
return res;
531528
} catch (IOException e) {

src/main/com/mongodb/MongoClientURI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
* </ul>
126126
* <p>Authentication configuration:</p>
127127
* <ul>
128-
* <li>{@code authProtocol=STRONGEST|GSSAPI}: The authentication protocol to use. The default is STRONGEST.
128+
* <li>{@code authProtocol=NEGOTIATE|GSSAPI}: The authentication protocol to use. The default is NEGOTIATE.
129129
* </li>
130130
* <li>{@code authSource=string}: The source of the authentication credentials. This is typically the database that
131131
* 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,
381381
return null;
382382
}
383383

384-
MongoCredentials.Protocol protocol = MongoCredentials.Protocol.STRONGEST;
384+
MongoCredentials.Protocol protocol = MongoCredentials.Protocol.NEGOTIATE;
385385
String authSource = database;
386386

387387
for (String key : authKeys) {

src/main/com/mongodb/MongoCredentials.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public String getDefaultSource() {
5353
}
5454
},
5555
/**
56-
* Uses the strongest available protocol available. This is the default protocol.
56+
* Negotiate the strongest available protocol available. This is the default protocol.
5757
*/
58-
STRONGEST {
58+
NEGOTIATE {
5959
/**
6060
* The default source is the "admin" database.
6161
* @return
@@ -81,7 +81,7 @@ public String getDefaultSource() {
8181
* @param password the password
8282
*/
8383
public MongoCredentials(final String userName, final char[] password) {
84-
this(userName, password, Protocol.STRONGEST);
84+
this(userName, password, Protocol.NEGOTIATE);
8585
}
8686

8787
/**
@@ -92,7 +92,7 @@ public MongoCredentials(final String userName, final char[] password) {
9292
* @param source the source of the credentials
9393
*/
9494
public MongoCredentials(final String userName, final char[] password, String source) {
95-
this(userName, password, Protocol.STRONGEST, source);
95+
this(userName, password, Protocol.NEGOTIATE, source);
9696
}
9797

9898
/**
@@ -134,8 +134,8 @@ public MongoCredentials(final String userName, final char[] password, Protocol p
134134
throw new IllegalArgumentException();
135135
}
136136

137-
if (protocol == Protocol.STRONGEST && password == null) {
138-
throw new IllegalArgumentException("password can not be null for " + Protocol.STRONGEST);
137+
if (protocol == Protocol.NEGOTIATE && password == null) {
138+
throw new IllegalArgumentException("password can not be null for " + Protocol.NEGOTIATE);
139139
}
140140

141141
if (protocol == Protocol.GSSAPI && password != null) {

src/test/com/mongodb/MongoClientURITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void testUserPass() {
8585
assertEquals("host", u.getHosts().get(0));
8686
assertEquals("user", u.getUsername());
8787
assertEquals("pass", new String(u.getPassword()));
88-
assertEquals(new MongoCredentials("user", "pass".toCharArray(), MongoCredentials.Protocol.STRONGEST, "bar"), u.getCredentials());
88+
assertEquals(new MongoCredentials("user", "pass".toCharArray(), MongoCredentials.Protocol.NEGOTIATE, "bar"), u.getCredentials());
8989

9090
u = new MongoClientURI("mongodb://user@host/?authProtocol=GSSAPI");
9191
assertEquals(new MongoCredentials("user", MongoCredentials.Protocol.GSSAPI), u.getCredentials());

src/test/com/mongodb/MongoCredentialsTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ public void testCredentials() {
3434
credentials = new MongoCredentials("user", "pwd".toCharArray());
3535
assertEquals("user", credentials.getUserName());
3636
assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
37-
assertEquals(MongoCredentials.Protocol.STRONGEST, credentials.getProtocol());
37+
assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
3838
assertEquals("admin", credentials.getSource());
3939

4040
credentials = new MongoCredentials("user", "pwd".toCharArray(), "test");
4141
assertEquals("user", credentials.getUserName());
4242
assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
43-
assertEquals(MongoCredentials.Protocol.STRONGEST, credentials.getProtocol());
43+
assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
4444
assertEquals("test", credentials.getSource());
4545

46-
credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.STRONGEST);
46+
credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.NEGOTIATE);
4747
assertEquals("user", credentials.getUserName());
4848
assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
49-
assertEquals(MongoCredentials.Protocol.STRONGEST, credentials.getProtocol());
49+
assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
5050
assertEquals("admin", credentials.getSource());
5151

5252
credentials = new MongoCredentials("user", MongoCredentials.Protocol.GSSAPI);
@@ -55,14 +55,14 @@ public void testCredentials() {
5555
assertEquals(MongoCredentials.Protocol.GSSAPI, credentials.getProtocol());
5656
assertEquals("$external", credentials.getSource());
5757

58-
credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.STRONGEST, "test");
58+
credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.NEGOTIATE, "test");
5959
assertEquals("user", credentials.getUserName());
6060
assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
61-
assertEquals(MongoCredentials.Protocol.STRONGEST, credentials.getProtocol());
61+
assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
6262
assertEquals("test", credentials.getSource());
6363

6464
try {
65-
new MongoCredentials("user", null, MongoCredentials.Protocol.STRONGEST, "test");
65+
new MongoCredentials("user", null, MongoCredentials.Protocol.NEGOTIATE, "test");
6666
fail("STRONGEST must have a password");
6767
} catch (IllegalArgumentException e) {
6868
// all good

src/test/com/mongodb/MongoURITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void testGetters() {
3232
MongoURI mongoURI = new MongoURI( "mongodb://user:pwd@localhost/test.mongoURITest?safe=false");
3333
assertEquals("user", mongoURI.getUsername());
3434
assertEquals("pwd", new String(mongoURI.getPassword()));
35-
assertEquals(new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.STRONGEST, "test"), mongoURI.getCredentials());
35+
assertEquals(new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.NEGOTIATE, "test"), mongoURI.getCredentials());
3636
assertEquals(Arrays.asList("localhost"), mongoURI.getHosts());
3737
assertEquals("test", mongoURI.getDatabase());
3838
assertEquals("mongoURITest", mongoURI.getCollection());

0 commit comments

Comments
 (0)