Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…karound
  • Loading branch information...
commit 021bc1dabe4b2c2a603f673f8f456ffa7a9d0ac8 1 parent 1f07df6
Jeff Yemin authored January 29, 2013
7  examples/GSSAPICredentialsExample.java
@@ -15,7 +15,6 @@
15 15
  */
16 16
 
17 17
 import com.mongodb.DB;
18  
-import com.mongodb.MongoAuthority;
19 18
 import com.mongodb.MongoClient;
20 19
 import com.mongodb.MongoClientOptions;
21 20
 import com.mongodb.MongoCredentials;
@@ -23,6 +22,7 @@
23 22
 
24 23
 import java.net.UnknownHostException;
25 24
 import java.security.Security;
  25
+import java.util.Arrays;
26 26
 
27 27
 /**
28 28
  * Example usage of Kerberos (GSSAPI) credentials.
@@ -66,9 +66,8 @@ public static void main(String[] args) throws UnknownHostException, InterruptedE
66 66
 
67 67
         System.out.println();
68 68
 
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)),
72 71
                 new MongoClientOptions.Builder().socketKeepAlive(true).socketTimeout(30000).build());
73 72
         DB testDB = mongoClient.getDB(databaseName);
74 73
 
12  examples/StrongestAuthenticationProtocolExample.java → ...ples/NegotiatedAuthenticationProtocolExample.java
@@ -16,33 +16,33 @@
16 16
 
17 17
 import com.mongodb.BasicDBObject;
18 18
 import com.mongodb.DB;
19  
-import com.mongodb.MongoAuthority;
20 19
 import com.mongodb.MongoClient;
21 20
 import com.mongodb.MongoClientOptions;
22 21
 import com.mongodb.MongoCredentials;
23 22
 import com.mongodb.ServerAddress;
24 23
 
25 24
 import java.net.UnknownHostException;
  25
+import java.util.Arrays;
26 26
 
27 27
 /**
28  
- * Example usage of STRONGEST authentication protocol.
  28
+ * Example usage of NEGOTIATE authentication protocol.
29 29
  * <p>
30 30
  * Usage:
31 31
  * </p>
32 32
  * <pre>
33  
- *     java StrongestAuthenticationProtocolExample server userName password databaseName
  33
+ *     java NegotiatedAuthenticationProtocolExample server userName password databaseName
34 34
  * </pre>
35 35
  */
36  
-public class StrongestAuthenticationProtocolExample {
  36
+public class NegotiatedAuthenticationProtocolExample {
37 37
     public static void main(String[] args) throws UnknownHostException, InterruptedException {
38 38
         String server = args[0];
39 39
         String user = args[1];
40 40
         String pwd = args[2];
41 41
         String db = args[3];
42 42
 
43  
-        MongoCredentials credentials = new MongoCredentials(user, pwd.toCharArray(), MongoCredentials.Protocol.STRONGEST, db);
  43
+        MongoCredentials credentials = new MongoCredentials(user, pwd.toCharArray(), MongoCredentials.Protocol.NEGOTIATE, db);
44 44
 
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());
46 46
 
47 47
         DB testDB = mongoClient.getDB(db);
48 48
         testDB.getCollection("test").insert(new BasicDBObject());
2  src/main/com/mongodb/DB.java
@@ -614,7 +614,7 @@ public synchronized CommandResult authenticateCommand(String username, char[] pa
614 614
     }
615 615
 
616 616
     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());
618 618
 
619 619
         if (getAuthenticationCredentials() != null) {
620 620
             if (getAuthenticationCredentials().equals(credentials)) {
5  src/main/com/mongodb/DBPort.java
@@ -313,7 +313,7 @@ protected void close(){
313 313
 
314 314
     CommandResult authenticate(Mongo mongo, final MongoCredentials credentials) {
315 315
         Authenticator authenticator;
316  
-        if (credentials.getProtocol() == MongoCredentials.Protocol.STRONGEST) {
  316
+        if (credentials.getProtocol() == MongoCredentials.Protocol.NEGOTIATE) {
317 317
             authenticator = getStrongestAuthenticator(mongo, credentials);
318 318
         } else if (credentials.getProtocol().equals(MongoCredentials.Protocol.GSSAPI)) {
319 319
             authenticator = new GSSAPIAuthenticator(mongo, credentials);
@@ -523,9 +523,6 @@ public CommandResult authenticate()  {
523 523
 
524 524
                     res = sendSaslContinue(conversationId, response);
525 525
                     res.throwOnError();
526  
-                    if (res.getCode() > 0) {  // SEE https://jira.mongodb.org/browse/SERVER-8100
527  
-                       throw new MongoException(res.getCode(), res.getErrorMessage());
528  
-                    }
529 526
                 }
530 527
                 return res;
531 528
             } catch (IOException e) {
4  src/main/com/mongodb/MongoClientURI.java
@@ -125,7 +125,7 @@
125 125
  * </ul>
126 126
  * <p>Authentication configuration:</p>
127 127
  * <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.
129 129
  * </li>
130 130
  * <li>{@code authSource=string}: The source of the authentication credentials.  This is typically the database that
131 131
  * 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,
381 381
             return null;
382 382
         }
383 383
 
384  
-        MongoCredentials.Protocol protocol = MongoCredentials.Protocol.STRONGEST;
  384
+        MongoCredentials.Protocol protocol = MongoCredentials.Protocol.NEGOTIATE;
385 385
         String authSource = database;
386 386
 
387 387
         for (String key : authKeys) {
12  src/main/com/mongodb/MongoCredentials.java
@@ -53,9 +53,9 @@ public String getDefaultSource() {
53 53
             }
54 54
         },
55 55
         /**
56  
-         * Uses the strongest available protocol available.  This is the default protocol.
  56
+         * Negotiate the strongest available protocol available.  This is the default protocol.
57 57
          */
58  
-        STRONGEST {
  58
+        NEGOTIATE {
59 59
             /**
60 60
              * The default source is the "admin" database.
61 61
              * @return
@@ -81,7 +81,7 @@ public String getDefaultSource() {
81 81
      * @param password the password
82 82
      */
83 83
     public MongoCredentials(final String userName, final char[] password) {
84  
-        this(userName, password, Protocol.STRONGEST);
  84
+        this(userName, password, Protocol.NEGOTIATE);
85 85
     }
86 86
 
87 87
     /**
@@ -92,7 +92,7 @@ public MongoCredentials(final String userName, final char[] password) {
92 92
      * @param source   the source of the credentials
93 93
      */
94 94
     public MongoCredentials(final String userName, final char[] password, String source) {
95  
-        this(userName, password, Protocol.STRONGEST, source);
  95
+        this(userName, password, Protocol.NEGOTIATE, source);
96 96
     }
97 97
 
98 98
     /**
@@ -134,8 +134,8 @@ public MongoCredentials(final String userName, final char[] password, Protocol p
134 134
             throw new IllegalArgumentException();
135 135
         }
136 136
 
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);
139 139
         }
140 140
 
141 141
         if (protocol == Protocol.GSSAPI && password != null) {
2  src/test/com/mongodb/MongoClientURITest.java
@@ -85,7 +85,7 @@ public void testUserPass() {
85 85
         assertEquals("host", u.getHosts().get(0));
86 86
         assertEquals("user", u.getUsername());
87 87
         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());
89 89
 
90 90
         u = new MongoClientURI("mongodb://user@host/?authProtocol=GSSAPI");
91 91
         assertEquals(new MongoCredentials("user", MongoCredentials.Protocol.GSSAPI), u.getCredentials());
14  src/test/com/mongodb/MongoCredentialsTest.java
@@ -34,19 +34,19 @@ public void testCredentials() {
34 34
         credentials = new MongoCredentials("user", "pwd".toCharArray());
35 35
         assertEquals("user", credentials.getUserName());
36 36
         assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
37  
-        assertEquals(MongoCredentials.Protocol.STRONGEST, credentials.getProtocol());
  37
+        assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
38 38
         assertEquals("admin", credentials.getSource());
39 39
 
40 40
         credentials = new MongoCredentials("user", "pwd".toCharArray(), "test");
41 41
         assertEquals("user", credentials.getUserName());
42 42
         assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
43  
-        assertEquals(MongoCredentials.Protocol.STRONGEST, credentials.getProtocol());
  43
+        assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
44 44
         assertEquals("test", credentials.getSource());
45 45
 
46  
-        credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.STRONGEST);
  46
+        credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.NEGOTIATE);
47 47
         assertEquals("user", credentials.getUserName());
48 48
         assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
49  
-        assertEquals(MongoCredentials.Protocol.STRONGEST, credentials.getProtocol());
  49
+        assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
50 50
         assertEquals("admin", credentials.getSource());
51 51
 
52 52
         credentials = new MongoCredentials("user", MongoCredentials.Protocol.GSSAPI);
@@ -55,14 +55,14 @@ public void testCredentials() {
55 55
         assertEquals(MongoCredentials.Protocol.GSSAPI, credentials.getProtocol());
56 56
         assertEquals("$external", credentials.getSource());
57 57
 
58  
-        credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.STRONGEST, "test");
  58
+        credentials = new MongoCredentials("user", "pwd".toCharArray(), MongoCredentials.Protocol.NEGOTIATE, "test");
59 59
         assertEquals("user", credentials.getUserName());
60 60
         assertArrayEquals("pwd".toCharArray(), credentials.getPassword());
61  
-        assertEquals(MongoCredentials.Protocol.STRONGEST, credentials.getProtocol());
  61
+        assertEquals(MongoCredentials.Protocol.NEGOTIATE, credentials.getProtocol());
62 62
         assertEquals("test", credentials.getSource());
63 63
 
64 64
         try {
65  
-            new MongoCredentials("user", null, MongoCredentials.Protocol.STRONGEST, "test");
  65
+            new MongoCredentials("user", null, MongoCredentials.Protocol.NEGOTIATE, "test");
66 66
             fail("STRONGEST must have a password");
67 67
         } catch (IllegalArgumentException e) {
68 68
             // all good
2  src/test/com/mongodb/MongoURITest.java
@@ -32,7 +32,7 @@ public void testGetters() {
32 32
         MongoURI mongoURI = new MongoURI( "mongodb://user:pwd@localhost/test.mongoURITest?safe=false");
33 33
         assertEquals("user", mongoURI.getUsername());
34 34
         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());
36 36
         assertEquals(Arrays.asList("localhost"), mongoURI.getHosts());
37 37
         assertEquals("test", mongoURI.getDatabase());
38 38
         assertEquals("mongoURITest", mongoURI.getCollection());

0 notes on commit 021bc1d

Please sign in to comment.
Something went wrong with that request. Please try again.