Elffuss BraidHub

kikocis/java-driver public

JAVA-885: Pass server authenticator class through to new authenticator.
Changesetdb355548edcbfd6278be6f6d02470a88d541fffedb6f41262c4ba7fc50622132
AuthorMike Adamson <madamson@datastax.com> · 2015-08-19 19:33 +01:00
CommitterAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-11-03 09:21 +01:00
Parents482c2681785f

Browse the files at this changeset

7 files changed

modified changelog/README.md +1 −0
@@ -5,6 +5,7 @@
55 - [improvement] Make TableOrView.Order visible (JAVA-958)
66 - [improvement] Update metrics to the latest version (JAVA-968)
77 - [improvement] Improve error handling for when a non-type 1 UUID is given to bind() on a timeuuid column (JAVA-965)
8+- [improvement] Pass the authenticator name from the server to the auth provider (JAVA-885)
89
910 ### 3.0.0-alpha4
1011
modified driver-core/src/main/java/com/datastax/driver/core/AuthProvider.java +3 −2
@@ -34,7 +34,7 @@
3434 * This is only useful as a placeholder when no authentication is to be used.
3535 */
3636 public static final AuthProvider NONE = new AuthProvider() {
37- public Authenticator newAuthenticator(InetSocketAddress host) {
37+ public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) {
3838 throw new AuthenticationException(host,
3939 String.format("Host %s requires authentication, but no authenticator found in Cluster configuration", host));
4040 }
@@ -44,7 +44,8 @@
4444 * The {@code Authenticator} to use when connecting to {@code host}
4545 *
4646 * @param host the Cassandra host to connect to.
47+ * @param authenticator the configured authenticator on the host.
4748 * @return The authentication implementation to use.
4849 */
49- public Authenticator newAuthenticator(InetSocketAddress host) throws AuthenticationException;
50+ public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) throws AuthenticationException;
5051 }
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +2 −1
@@ -255,7 +255,8 @@
255255 throw unsupportedProtocolVersionException(protocolVersion, error.serverProtocolVersion);
256256 throw new TransportException(address, String.format("Error initializing connection: %s", error.message));
257257 case AUTHENTICATE:
258- Authenticator authenticator = factory.authProvider.newAuthenticator(address);
258+ Responses.Authenticate authenticate = (Responses.Authenticate)response;
259+ Authenticator authenticator = factory.authProvider.newAuthenticator(address, authenticate.authenticator);
259260 switch (protocolVersion) {
260261 case V1:
261262 if (authenticator instanceof ProtocolV1Authenticator)
modified driver-core/src/main/java/com/datastax/driver/core/PlainTextAuthProvider.java +2 −1
@@ -73,10 +73,11 @@
7373 * to the server.
7474 *
7575 * @param host the Cassandra host with which we want to authenticate
76+ * @param authenticator the configured authenticator on the host
7677 * @return an Authenticator instance which can be used to perform
7778 * authentication negotiations on behalf of the client
7879 */
79- public Authenticator newAuthenticator(InetSocketAddress host) {
80+ public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) {
8081 return new PlainTextAuthenticator(username, password);
8182 }
8283
modified driver-core/src/test/java/com/datastax/driver/core/AuthenticationTest.java +9 −1
@@ -23,9 +23,15 @@
2323 import org.testng.annotations.BeforeClass;
2424 import org.testng.annotations.Test;
2525
26+import static org.mockito.Mockito.atLeastOnce;
27+import static org.mockito.Mockito.spy;
28+import static org.mockito.Mockito.verify;
29+
2630 import com.datastax.driver.core.exceptions.AuthenticationException;
2731 import com.datastax.driver.core.exceptions.NoHostAvailableException;
2832
33+import static com.datastax.driver.core.TestUtils.findHost;
34+
2935 /**
3036 * Tests for authenticated cluster access
3137 */
@@ -59,11 +65,13 @@
5965
6066 @Test(groups = "short")
6167 public void should_connect_with_credentials() throws InterruptedException {
68+ PlainTextAuthProvider authProvider = spy(new PlainTextAuthProvider("cassandra", "cassandra"));
6269 Cluster cluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1')
63- .withCredentials("cassandra", "cassandra")
70+ .withAuthProvider(authProvider)
6471 .build();
6572 try {
6673 cluster.connect();
74+ verify(authProvider, atLeastOnce()).newAuthenticator(findHost(cluster, 1).getSocketAddress(), "org.apache.cassandra.auth.PasswordAuthenticator");
6775 } catch (NoHostAvailableException e) {
6876 logger.error(e.getCustomMessage(1, true, true));
6977 } finally {
modified driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java +2 −2
@@ -308,9 +308,9 @@
308308 }
309309
310310 @Override
311- public Authenticator newAuthenticator(InetSocketAddress host) {
311+ public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) {
312312 count.incrementAndGet();
313- return super.newAuthenticator(host);
313+ return super.newAuthenticator(host, authenticator);
314314 }
315315 }
316316
modified driver-dse/src/main/java/com/datastax/driver/auth/DseAuthProvider.java +1 −1
@@ -80,7 +80,7 @@
8080 public class DseAuthProvider implements AuthProvider
8181 {
8282 @Override
83- public Authenticator newAuthenticator(InetSocketAddress host) throws AuthenticationException
83+ public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) throws AuthenticationException
8484 {
8585 return new KerberosAuthenticator(host);
8686 }