kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 08758edd9a11a2c7030c5984bd4ed5f0a7304a4b3cbd90e69e53d6c0137ea5a6 |
|---|---|
| Author | Alexandre Dutra <alexdut@gmail.com> · 2015-11-03 09:23 +01:00 |
| Committer | Alexandre Dutra <alexdut@gmail.com> · 2015-11-03 09:23 +01:00 |
| Parents | 482c2681785f, db355548edcb |
7 files changed
modified changelog/README.md +1 −0
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | - [improvement] Make TableOrView.Order visible (JAVA-958) |
| 6 | 6 | - [improvement] Update metrics to the latest version (JAVA-968) |
| 7 | 7 | - [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) | |
| 8 | 9 | |
| 9 | 10 | ### 3.0.0-alpha4 |
| 10 | 11 |
modified driver-core/src/main/java/com/datastax/driver/core/AuthProvider.java +3 −2
| @@ -34,7 +34,7 @@ | ||
| 34 | 34 | * This is only useful as a placeholder when no authentication is to be used. |
| 35 | 35 | */ |
| 36 | 36 | public static final AuthProvider NONE = new AuthProvider() { |
| 37 | - public Authenticator newAuthenticator(InetSocketAddress host) { | |
| 37 | + public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) { | |
| 38 | 38 | throw new AuthenticationException(host, |
| 39 | 39 | String.format("Host %s requires authentication, but no authenticator found in Cluster configuration", host)); |
| 40 | 40 | } |
| @@ -44,7 +44,8 @@ | ||
| 44 | 44 | * The {@code Authenticator} to use when connecting to {@code host} |
| 45 | 45 | * |
| 46 | 46 | * @param host the Cassandra host to connect to. |
| 47 | + * @param authenticator the configured authenticator on the host. | |
| 47 | 48 | * @return The authentication implementation to use. |
| 48 | 49 | */ |
| 49 | - public Authenticator newAuthenticator(InetSocketAddress host) throws AuthenticationException; | |
| 50 | + public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) throws AuthenticationException; | |
| 50 | 51 | } |
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +2 −1
| @@ -255,7 +255,8 @@ | ||
| 255 | 255 | throw unsupportedProtocolVersionException(protocolVersion, error.serverProtocolVersion); |
| 256 | 256 | throw new TransportException(address, String.format("Error initializing connection: %s", error.message)); |
| 257 | 257 | 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); | |
| 259 | 260 | switch (protocolVersion) { |
| 260 | 261 | case V1: |
| 261 | 262 | if (authenticator instanceof ProtocolV1Authenticator) |
modified driver-core/src/main/java/com/datastax/driver/core/PlainTextAuthProvider.java +2 −1
| @@ -73,10 +73,11 @@ | ||
| 73 | 73 | * to the server. |
| 74 | 74 | * |
| 75 | 75 | * @param host the Cassandra host with which we want to authenticate |
| 76 | + * @param authenticator the configured authenticator on the host | |
| 76 | 77 | * @return an Authenticator instance which can be used to perform |
| 77 | 78 | * authentication negotiations on behalf of the client |
| 78 | 79 | */ |
| 79 | - public Authenticator newAuthenticator(InetSocketAddress host) { | |
| 80 | + public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) { | |
| 80 | 81 | return new PlainTextAuthenticator(username, password); |
| 81 | 82 | } |
| 82 | 83 |
modified driver-core/src/test/java/com/datastax/driver/core/AuthenticationTest.java +9 −1
| @@ -23,9 +23,15 @@ | ||
| 23 | 23 | import org.testng.annotations.BeforeClass; |
| 24 | 24 | import org.testng.annotations.Test; |
| 25 | 25 | |
| 26 | +import static org.mockito.Mockito.atLeastOnce; | |
| 27 | +import static org.mockito.Mockito.spy; | |
| 28 | +import static org.mockito.Mockito.verify; | |
| 29 | + | |
| 26 | 30 | import com.datastax.driver.core.exceptions.AuthenticationException; |
| 27 | 31 | import com.datastax.driver.core.exceptions.NoHostAvailableException; |
| 28 | 32 | |
| 33 | +import static com.datastax.driver.core.TestUtils.findHost; | |
| 34 | + | |
| 29 | 35 | /** |
| 30 | 36 | * Tests for authenticated cluster access |
| 31 | 37 | */ |
| @@ -59,11 +65,13 @@ | ||
| 59 | 65 | |
| 60 | 66 | @Test(groups = "short") |
| 61 | 67 | public void should_connect_with_credentials() throws InterruptedException { |
| 68 | + PlainTextAuthProvider authProvider = spy(new PlainTextAuthProvider("cassandra", "cassandra")); | |
| 62 | 69 | Cluster cluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + '1') |
| 63 | - .withCredentials("cassandra", "cassandra") | |
| 70 | + .withAuthProvider(authProvider) | |
| 64 | 71 | .build(); |
| 65 | 72 | try { |
| 66 | 73 | cluster.connect(); |
| 74 | + verify(authProvider, atLeastOnce()).newAuthenticator(findHost(cluster, 1).getSocketAddress(), "org.apache.cassandra.auth.PasswordAuthenticator"); | |
| 67 | 75 | } catch (NoHostAvailableException e) { |
| 68 | 76 | logger.error(e.getCustomMessage(1, true, true)); |
| 69 | 77 | } finally { |
modified driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java +2 −2
| @@ -308,9 +308,9 @@ | ||
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | @Override |
| 311 | - public Authenticator newAuthenticator(InetSocketAddress host) { | |
| 311 | + public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) { | |
| 312 | 312 | count.incrementAndGet(); |
| 313 | - return super.newAuthenticator(host); | |
| 313 | + return super.newAuthenticator(host, authenticator); | |
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 |
modified driver-dse/src/main/java/com/datastax/driver/auth/DseAuthProvider.java +1 −1
| @@ -80,7 +80,7 @@ | ||
| 80 | 80 | public class DseAuthProvider implements AuthProvider |
| 81 | 81 | { |
| 82 | 82 | @Override |
| 83 | - public Authenticator newAuthenticator(InetSocketAddress host) throws AuthenticationException | |
| 83 | + public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) throws AuthenticationException | |
| 84 | 84 | { |
| 85 | 85 | return new KerberosAuthenticator(host); |
| 86 | 86 | } |