Skip to content
Permalink
Browse files

[CONJ-675] Multiple alternative authentication methods for the same u…

…ser java implementation

(cherry picked from commit 4e49e33)
  • Loading branch information...
rusher committed Jan 23, 2019
1 parent d337275 commit add2498b2337a69918c9729d3571ce96dc067572
Showing with 3,895 additions and 3,857 deletions.
  1. +1 −1 pom.xml
  2. +84 −100 src/main/java/org/mariadb/jdbc/internal/com/send/ComStmtExecute.java
  3. +0 −63 src/main/java/org/mariadb/jdbc/internal/com/send/InterfaceAuthSwitchSendResponsePacket.java
  4. +15 −21 src/main/java/org/mariadb/jdbc/internal/com/send/SendChangeDbPacket.java
  5. +0 −87 src/main/java/org/mariadb/jdbc/internal/com/send/SendClearPasswordAuthPacket.java
  6. +0 −163 src/main/java/org/mariadb/jdbc/internal/com/send/SendEd25519PasswordAuthPacket.java
  7. +0 −133 src/main/java/org/mariadb/jdbc/internal/com/send/SendGssApiAuthPacket.java
  8. +0 −143 src/main/java/org/mariadb/jdbc/internal/com/send/SendOldPasswordAuthPacket.java
  9. +0 −228 src/main/java/org/mariadb/jdbc/internal/com/send/SendPamAuthPacket.java
  10. +20 −25 src/main/java/org/mariadb/jdbc/internal/com/send/SendSslConnectionRequestPacket.java
  11. +17 −13 ...ariadb/jdbc/internal/com/send/{gssapi/GssapiAuth.java → authentication/AuthenticationPlugin.java}
  12. +46 −38 ...al/com/send/{AbstractAuthSwitchSendResponsePacket.java → authentication/ClearPasswordPlugin.java}
  13. +172 −0 src/main/java/org/mariadb/jdbc/internal/com/send/authentication/Ed25519PasswordPlugin.java
  14. +54 −32 .../internal/com/send/{SendNativePasswordAuthPacket.java → authentication/NativePasswordPlugin.java}
  15. +160 −0 src/main/java/org/mariadb/jdbc/internal/com/send/authentication/OldPasswordPlugin.java
  16. +113 −0 src/main/java/org/mariadb/jdbc/internal/com/send/authentication/SendGssApiAuthPacket.java
  17. +232 −0 src/main/java/org/mariadb/jdbc/internal/com/send/authentication/SendPamAuthPacket.java
  18. 0 src/main/java/org/mariadb/jdbc/internal/com/send/{ → authentication}/ed25519/README
  19. +1 −1 src/main/java/org/mariadb/jdbc/internal/com/send/{ → authentication}/ed25519/Utils.java
  20. +2 −2 src/main/java/org/mariadb/jdbc/internal/com/send/{ → authentication}/ed25519/math/Constants.java
  21. +101 −0 src/main/java/org/mariadb/jdbc/internal/com/send/authentication/ed25519/math/Curve.java
  22. +1 −1 src/main/java/org/mariadb/jdbc/internal/com/send/{ → authentication}/ed25519/math/Encoding.java
  23. +99 −0 src/main/java/org/mariadb/jdbc/internal/com/send/authentication/ed25519/math/Field.java
  24. +1 −1 src/main/java/org/mariadb/jdbc/internal/com/send/{ → authentication}/ed25519/math/FieldElement.java
  25. +1,075 −0 src/main/java/org/mariadb/jdbc/internal/com/send/authentication/ed25519/math/GroupElement.java
  26. +1,060 −0 ...a/org/mariadb/jdbc/internal/com/send/authentication/ed25519/math/ed25519/Ed25519FieldElement.java
  27. +3 −3 .../jdbc/internal/com/send/{ → authentication}/ed25519/math/ed25519/Ed25519LittleEndianEncoding.java
  28. +3 −3 ...n/java/org/mariadb/jdbc/internal/com/send/{ → authentication}/ed25519/math/ed25519/ScalarOps.java
  29. +4 −4 ...java/org/mariadb/jdbc/internal/com/send/{ → authentication}/ed25519/spec/EdDSANamedCurveSpec.java
  30. +70 −0 ...ain/java/org/mariadb/jdbc/internal/com/send/authentication/ed25519/spec/EdDSANamedCurveTable.java
  31. +97 −0 src/main/java/org/mariadb/jdbc/internal/com/send/authentication/ed25519/spec/EdDSAParameterSpec.java
  32. +30 −0 src/main/java/org/mariadb/jdbc/internal/com/send/authentication/gssapi/GssUtility.java
  33. +9 −5 ...mariadb/jdbc/internal/com/send/{InterfaceSendPacket.java → authentication/gssapi/GssapiAuth.java}
  34. +173 −0 ...n/java/org/mariadb/jdbc/internal/com/send/authentication/gssapi/StandardGssapiAuthentication.java
  35. +39 −30 ...rg/mariadb/jdbc/internal/com/send/{ → authentication}/gssapi/WindowsNativeSspiAuthentication.java
  36. +0 −99 src/main/java/org/mariadb/jdbc/internal/com/send/ed25519/math/Curve.java
  37. +0 −98 src/main/java/org/mariadb/jdbc/internal/com/send/ed25519/math/Field.java
  38. +0 −1,025 src/main/java/org/mariadb/jdbc/internal/com/send/ed25519/math/GroupElement.java
  39. +0 −1,059 src/main/java/org/mariadb/jdbc/internal/com/send/ed25519/math/ed25519/Ed25519FieldElement.java
  40. +0 −70 src/main/java/org/mariadb/jdbc/internal/com/send/ed25519/spec/EdDSANamedCurveTable.java
  41. +0 −95 src/main/java/org/mariadb/jdbc/internal/com/send/ed25519/spec/EdDSAParameterSpec.java
  42. +0 −163 src/main/java/org/mariadb/jdbc/internal/com/send/gssapi/StandardGssapiAuthentication.java
  43. +75 −51 src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java
  44. +3 −5 src/main/java/org/mariadb/jdbc/internal/protocol/AbstractQueryProtocol.java
  45. +43 −48 src/main/java/org/mariadb/jdbc/internal/protocol/authentication/AuthenticationProviderHolder.java
  46. +45 −39 src/main/java/org/mariadb/jdbc/internal/protocol/authentication/DefaultAuthenticationProvider.java
  47. +39 −0 src/test/java/org/mariadb/jdbc/ConnectionTest.java
  48. +7 −7 src/test/java/org/mariadb/jdbc/DriverTest.java
  49. +1 −1 src/test/java/org/mariadb/jdbc/PreparedStatementTest.java
@@ -181,7 +181,7 @@
**/SharedMemorySocket.java,
**/UnixDomainSocket.java,
**/MySQLDataSource.java,
**/org/mariadb/jdbc/internal/com/send/ed25519/**
**/org/mariadb/jdbc/internal/com/send/authentication/ed25519/**
</excludes>
<configLocation>src/test/resources/style.xml</configLocation>
<encoding>UTF-8</encoding>
@@ -52,120 +52,104 @@

package org.mariadb.jdbc.internal.com.send;

import java.io.IOException;
import org.mariadb.jdbc.internal.ColumnType;
import org.mariadb.jdbc.internal.com.Packet;
import org.mariadb.jdbc.internal.com.send.parameters.ParameterHolder;
import org.mariadb.jdbc.internal.io.output.PacketOutputStream;

import java.io.IOException;

public class ComStmtExecute implements InterfaceSendPacket {
private final int parameterCount;
private final ParameterHolder[] parameters;
private final int statementId;
private final byte cursorFlag;
private final ColumnType[] parameterTypeHeader;

/**
* Initialize parameters.
*
* @param statementId prepareResult object received after preparation.
* @param parameters parameters
* @param parameterCount parameters number
* @param parameterTypeHeader parameters header
* @param cursorFlag cursor flag. Possible values : <ol>
* <li>CURSOR_TYPE_NO_CURSOR = fetch all</li>
* <li>CURSOR_TYPE_READ_ONLY = fetch by bunch</li>
* <li>CURSOR_TYPE_FOR_UPDATE = fetch by bunch with lock ?</li>
* <li>CURSOR_TYPE_SCROLLABLE = //reserved, but not working</li>
* </ol>
*/
public ComStmtExecute(final int statementId, final ParameterHolder[] parameters, final int parameterCount,
ColumnType[] parameterTypeHeader, byte cursorFlag) {
this.parameterCount = parameterCount;
this.parameters = parameters;
this.statementId = statementId;
this.parameterTypeHeader = parameterTypeHeader;
this.cursorFlag = cursorFlag;
}

/**
* Write COM_STMT_EXECUTE sub-command to output buffer.
*
* @param statementId prepareResult object received after preparation.
* @param parameters parameters
* @param parameterCount parameters number
* @param parameterTypeHeader parameters header1
* @param pos outputStream
* @param cursorFlag cursor flag. Possible values : <ol>
* <li>CURSOR_TYPE_NO_CURSOR = fetch all</li>
* <li>CURSOR_TYPE_READ_ONLY = fetch by bunch</li>
* <li>CURSOR_TYPE_FOR_UPDATE = fetch by bunch with lock ?</li>
* <li>CURSOR_TYPE_SCROLLABLE = //reserved, but not working</li>
* </ol>
* @throws IOException if a connection error occur
*/
public static void writeCmd(final int statementId, final ParameterHolder[] parameters, final int parameterCount,
ColumnType[] parameterTypeHeader, final PacketOutputStream pos,
final byte cursorFlag) throws IOException {
pos.write(Packet.COM_STMT_EXECUTE);
pos.writeInt(statementId);
pos.write(cursorFlag);
pos.writeInt(1); //Iteration pos

public class ComStmtExecute {

//create null bitmap
if (parameterCount > 0) {
int nullCount = (parameterCount + 7) / 8;
/**
* Write COM_STMT_EXECUTE sub-command to output buffer.
*
* @param statementId prepareResult object received after preparation.
* @param parameters parameters
* @param parameterCount parameters number
* @param parameterTypeHeader parameters header1
* @param pos outputStream
* @param cursorFlag cursor flag. Possible values : <ol>
* <li>CURSOR_TYPE_NO_CURSOR = fetch all</li>
* <li>CURSOR_TYPE_READ_ONLY = fetch by bunch</li>
* <li>CURSOR_TYPE_FOR_UPDATE = fetch by bunch with lock ?</li>
* <li>CURSOR_TYPE_SCROLLABLE = //reserved, but not working</li>
* </ol>
* @throws IOException if a connection error occur
*/
public static void writeCmd(final int statementId, final ParameterHolder[] parameters,
final int parameterCount,
ColumnType[] parameterTypeHeader, final PacketOutputStream pos,
final byte cursorFlag) throws IOException {
pos.write(Packet.COM_STMT_EXECUTE);
pos.writeInt(statementId);
pos.write(cursorFlag);
pos.writeInt(1); //Iteration pos

byte[] nullBitsBuffer = new byte[nullCount];
for (int i = 0; i < parameterCount; i++) {
if (parameters[i].isNullData()) {
nullBitsBuffer[i / 8] |= (1 << (i % 8));
}
}
pos.write(nullBitsBuffer, 0, nullCount);
//create null bitmap
if (parameterCount > 0) {
int nullCount = (parameterCount + 7) / 8;

//check if parameters type (using setXXX) have change since previous request, and resend new header type if so
boolean mustSendHeaderType = false;
if (parameterTypeHeader[0] == null) {
mustSendHeaderType = true;
} else {
for (int i = 0; i < parameterCount; i++) {
if (!parameterTypeHeader[i].equals(parameters[i].getColumnType())) {
mustSendHeaderType = true;
break;
}
}
}
byte[] nullBitsBuffer = new byte[nullCount];
for (int i = 0; i < parameterCount; i++) {
if (parameters[i].isNullData()) {
nullBitsBuffer[i / 8] |= (1 << (i % 8));
}
}
pos.write(nullBitsBuffer, 0, nullCount);

if (mustSendHeaderType) {
pos.write((byte) 0x01);
//Store types of parameters in first in first package that is sent to the server.
for (int i = 0; i < parameterCount; i++) {
parameterTypeHeader[i] = parameters[i].getColumnType();
pos.writeShort(parameterTypeHeader[i].getType());
}
} else {
pos.write((byte) 0x00);
}
//check if parameters type (using setXXX) have change since previous request, and resend new header type if so
boolean mustSendHeaderType = false;
if (parameterTypeHeader[0] == null) {
mustSendHeaderType = true;
} else {
for (int i = 0; i < parameterCount; i++) {
if (!parameterTypeHeader[i].equals(parameters[i].getColumnType())) {
mustSendHeaderType = true;
break;
}
}
}

if (mustSendHeaderType) {
pos.write((byte) 0x01);
//Store types of parameters in first in first package that is sent to the server.
for (int i = 0; i < parameterCount; i++) {
ParameterHolder holder = parameters[i];
if (!holder.isNullData() && !holder.isLongData()) holder.writeBinary(pos);
parameterTypeHeader[i] = parameters[i].getColumnType();
pos.writeShort(parameterTypeHeader[i].getType());
}
} else {
pos.write((byte) 0x00);
}
}

/**
* Send a prepare statement binary stream.
*
* @param pos database socket
* @throws IOException if a connection error occur
*/
public void send(final PacketOutputStream pos) throws IOException {
pos.startPacket(0);
writeCmd(statementId, parameters, parameterCount, parameterTypeHeader, pos, cursorFlag);
pos.flush();
for (int i = 0; i < parameterCount; i++) {
ParameterHolder holder = parameters[i];
if (!holder.isNullData() && !holder.isLongData()) {
holder.writeBinary(pos);
}
}
}

/**
* Send a prepare statement binary stream.
*
* @param pos database socket
* @param statementId prepareResult object received after preparation.
* @param parameters parameters
* @param parameterCount parameters number
* @param parameterTypeHeader parameters header
* @param cursorFlag cursor flag. Possible values : <ol>
* <li>CURSOR_TYPE_NO_CURSOR = fetch all</li>
* <li>CURSOR_TYPE_READ_ONLY = fetch by bunch</li>
* <li>CURSOR_TYPE_FOR_UPDATE = fetch by bunch with lock ?</li>
* <li>CURSOR_TYPE_SCROLLABLE = //reserved, but not working</li>
* </ol>
* @throws IOException if a connection error occur
*/
public static void send(final PacketOutputStream pos, final int statementId, final ParameterHolder[] parameters,
final int parameterCount, ColumnType[] parameterTypeHeader, byte cursorFlag) throws IOException {
pos.startPacket(0);
writeCmd(statementId, parameters, parameterCount, parameterTypeHeader, pos, cursorFlag);
pos.flush();
}
}

This file was deleted.

@@ -52,30 +52,24 @@

package org.mariadb.jdbc.internal.com.send;

import java.io.IOException;
import org.mariadb.jdbc.internal.com.Packet;
import org.mariadb.jdbc.internal.io.output.PacketOutputStream;

import java.io.IOException;


public class SendChangeDbPacket implements InterfaceSendPacket {

private final String database;

public SendChangeDbPacket(final String database) {
this.database = database;
}
public class SendChangeDbPacket {

/**
* Change Database.
*
* @param pos Write outputStream
* @throws IOException if connection problem occur
*/
public void send(final PacketOutputStream pos) throws IOException {
pos.startPacket(0);
pos.write(Packet.COM_INIT_DB);
pos.write(database.getBytes("UTF-8"));
pos.flush();
}
/**
* Send a COM_INIT_DB request to specify the default schema for the connection.
*
* @param pos Write outputStream
* @param database database name
* @throws IOException if connection problem occur
*/
public static void send(final PacketOutputStream pos, final String database) throws IOException {
pos.startPacket(0);
pos.write(Packet.COM_INIT_DB);
pos.write(database.getBytes("UTF-8"));
pos.flush();
}
}

0 comments on commit add2498

Please sign in to comment.
You can’t perform that action at this time.