Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch '2.0' of https://github.com/datastax/java-driver into 2.0

  • Loading branch information...
commit f3fe8108de573786c1e761d4720c960c60af2051 2 parents 2fd0f36 + e32c7c4
@pcmanus pcmanus authored
View
22 driver-core/src/main/java/com/datastax/driver/core/Connection.java
@@ -137,7 +137,13 @@ private void initializeTransport(int version) throws ConnectionException, Interr
case AUTHENTICATE:
Authenticator authenticator = factory.authProvider.newAuthenticator(address);
if (version == 1)
- authenticateV1(authenticator);
+ {
+ if (authenticator instanceof ProtocolV1Authenticator)
+ authenticateV1(authenticator);
+ else
+ // DSE 3.x always uses SASL authentication backported from protocol v2
+ authenticateV2(authenticator);
+ }
else
authenticateV2(authenticator);
break;
@@ -161,10 +167,6 @@ private UnsupportedProtocolVersionException unsupportedProtocolVersionException(
}
private void authenticateV1(Authenticator authenticator) throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException {
- if (!(authenticator instanceof ProtocolV1Authenticator))
- throw new AuthenticationException(address, String.format("Cannot use authenticator %s with protocol version 1, "
- + "only plain text authentication is supported with this protocol version", authenticator));
-
Requests.Credentials creds = new Requests.Credentials(((ProtocolV1Authenticator)authenticator).getCredentials());
Message.Response authResponse = write(creds).get();
switch (authResponse.type) {
@@ -207,7 +209,15 @@ private void waitForAuthCompletion(Message.Response authResponse, Authenticator
}
break;
case ERROR:
- throw new AuthenticationException(address, ((Responses.Error)authResponse).message);
+ // This is not very nice, but we're trying to identify if we
+ // attempted v2 auth against a server which only supports v1
+ // The AIOOBE indicates that the server didn't recognise the
+ // initial AuthResponse message
+ String message = ((Responses.Error)authResponse).message;
+ if (message.startsWith("java.lang.ArrayIndexOutOfBoundsException: 15"))
+ message = String.format("Cannot use authenticator %s with protocol version 1, "
+ + "only plain text authentication is supported with this protocol version", authenticator);
+ throw new AuthenticationException(address, message);
default:
throw new TransportException(address, String.format("Unexpected %s response message from server to authentication message", authResponse.type));
}
View
6 driver-core/src/main/java/com/datastax/driver/core/Message.java
@@ -69,7 +69,7 @@ public int getStreamId() {
EXECUTE (10, Requests.Execute.coderV1, Requests.Execute.coderV2),
REGISTER (11, Requests.Register.coder, Requests.Register.coder),
BATCH (13, null, Requests.Batch.coder),
- AUTH_RESPONSE (15, null, Requests.AuthResponse.coder);
+ AUTH_RESPONSE (15, Requests.AuthResponse.coder, Requests.AuthResponse.coder);
public final int opcode;
private final Coder<?> coderV1;
@@ -113,8 +113,8 @@ public boolean isTracingRequested() {
SUPPORTED (6, Responses.Supported.decoder, Responses.Supported.decoder),
RESULT (8, Responses.Result.decoderV1, Responses.Result.decoderV2),
EVENT (12, Responses.Event.decoder, Responses.Event.decoder),
- AUTH_CHALLENGE (14, Responses.AuthChallenge.decoderV1, Responses.AuthChallenge.decoderV2),
- AUTH_SUCCESS (16, Responses.AuthSuccess.decoderV1, Responses.AuthSuccess.decoderV2);
+ AUTH_CHALLENGE (14, Responses.AuthChallenge.decoder, Responses.AuthChallenge.decoder),
+ AUTH_SUCCESS (16, Responses.AuthSuccess.decoder, Responses.AuthSuccess.decoder);
public final int opcode;
private final Decoder<?> decoderV1;
View
18 driver-core/src/main/java/com/datastax/driver/core/Responses.java
@@ -523,14 +523,7 @@ public String toString() {
public static class AuthChallenge extends Message.Response {
- public static final Message.Decoder<AuthChallenge> decoderV1 = new Message.Decoder<AuthChallenge>() {
- public AuthChallenge decode(ChannelBuffer body) {
- // AUTH_CHALLENGE is protocol v2 only.
- throw new DriverInternalError("Got AUTH_CHALLENGE in protocol V1, this shouldn't happen since AUTH_CHALLENGE is a protocol V2 only message");
- }
- };
-
- public static final Message.Decoder<AuthChallenge> decoderV2 = new Message.Decoder<AuthChallenge>() {
+ public static final Message.Decoder<AuthChallenge> decoder = new Message.Decoder<AuthChallenge>() {
public AuthChallenge decode(ChannelBuffer body) {
ByteBuffer b = CBUtil.readValue(body);
if (b == null)
@@ -552,14 +545,7 @@ private AuthChallenge(byte[] token) {
public static class AuthSuccess extends Message.Response {
- public static final Message.Decoder<AuthSuccess> decoderV1 = new Message.Decoder<AuthSuccess>() {
- public AuthSuccess decode(ChannelBuffer body) {
- // AUTH_SUCCESS is protocol v2 only.
- throw new DriverInternalError("Got AUTH_SUCCESS in protocol V1, this shouldn't happen since AUTH_SUCCESS is a protocol V2 only message");
- }
- };
-
- public static final Message.Decoder<AuthSuccess> decoderV2 = new Message.Decoder<AuthSuccess>() {
+ public static final Message.Decoder<AuthSuccess> decoder = new Message.Decoder<AuthSuccess>() {
public AuthSuccess decode(ChannelBuffer body) {
ByteBuffer b = CBUtil.readValue(body);
if (b == null)
Please sign in to comment.
Something went wrong with that request. Please try again.