Skip to content

Commit

Permalink
Enable SSL Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipinofficial11 committed Oct 8, 2024
1 parent a83eaac commit 822e9f3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static class OracleActionConfig extends DBSpecificQueryConfig {

@Override
public String getConnectionString() {
return OracleConstants.getConnectionString(this.connectionType, host, port, database);
return OracleConstants.getConnectionString(this.connectionType, host, port, database, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected String getConnectionString(@Nullable String database) {
return config.getConnectionString();
}
return OracleConstants.getConnectionString(config.getConnectionType(),
config.getHost(), config.getPort(), database);
config.getHost(), config.getPort(), database, config.getSSlMode());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public OracleConnectorConfig(String host, int port, String user, String password

public OracleConnectorConfig(String host, int port, String user, String password, String jdbcPluginName,
String connectionArguments, String connectionType, String database) {
this(host, port, user, password, jdbcPluginName, connectionArguments, connectionType, database, null);
this(host, port, user, password, jdbcPluginName, connectionArguments, connectionType, database, null, null);
}

public OracleConnectorConfig(String host, int port, String user, String password, String jdbcPluginName,
String connectionArguments, String connectionType, String database,
String role) {
String role, String useSSL) {

this.host = host;
this.port = port;
Expand All @@ -59,11 +59,12 @@ public OracleConnectorConfig(String host, int port, String user, String password
this.connectionType = connectionType;
this.database = database;
this.role = role;
this.useSSL = useSSL;
}

@Override
public String getConnectionString() {
return OracleConstants.getConnectionString(connectionType, host, getPort(), database);
return OracleConstants.getConnectionString(connectionType, host, getPort(), database, useSSL);
}

@Name(OracleConstants.CONNECTION_TYPE)
Expand All @@ -86,6 +87,12 @@ public String getConnectionString() {
@Nullable
private String transactionIsolationLevel;

@Name(OracleConstants.USE_SSL)
@Description("Turns on SSL encryption. Connection will fail if SSL is not available")
@Nullable
public String useSSL;


@Override
protected int getDefaultPort() {
return 1521;
Expand All @@ -103,6 +110,11 @@ public String getDatabase() {
return database;
}

public String getSSlMode() {
return useSSL;
}


@Override
public Properties getConnectionArgumentsProperties() {
Properties prop = super.getConnectionArgumentsProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ private OracleConstants() {
}

public static final String PLUGIN_NAME = "Oracle";
public static final String ORACLE_CONNECTION_STRING_SID_FORMAT = "jdbc:oracle:thin:@%s:%s:%s";
public static final String ORACLE_CONNECTION_STRING_SERVICE_NAME_FORMAT = "jdbc:oracle:thin:@//%s:%s/%s";
// Updating connection strings to accept protocol (e.g., jdbc:oracle:thin:@<protocol>://<host>:<port>:<SID>)
public static final String ORACLE_CONNECTION_STRING_SID_FORMAT = "jdbc:oracle:thin:@%s://%s:%d:%s";
public static final String ORACLE_CONNECTION_STRING_SERVICE_NAME_FORMAT = "jdbc:oracle:thin:@%s://%s:%d/%s";
public static final String ORACLE_CONNECTION_STRING_TNS_FORMAT = "jdbc:oracle:thin:@%s";
public static final String DEFAULT_BATCH_VALUE = "defaultBatchValue";
public static final String DEFAULT_ROW_PREFETCH = "defaultRowPrefetch";
Expand All @@ -38,28 +39,41 @@ private OracleConstants() {
public static final String NAME_DATABASE = "database";
public static final String TNS_CONNECTION_TYPE = "TNS";
public static final String TRANSACTION_ISOLATION_LEVEL = "transactionIsolationLevel";
public static final String USE_SSL = "useSSL";

/**
* Returns the Connection String for the given ConnectionType.
* Constructs the Oracle connection string based on the provided connection type, host, port, and database.
* If SSL is enabled, the connection protocol will be "tcps" instead of "tcp".
*
* @param connectionType TNS/Service/SID
* @param host Host name of the oracle server
* @param port Port of the oracle server
* @param database Database to connect to
* @return Connection String based on the given ConnectionType
* @param useSSL Whether SSL/TLS is required(YES/NO)
* @return Connection String based on the given parameters and connection type.
*/
public static String getConnectionString(String connectionType,
@Nullable String host,
@Nullable int port,
String database) {
String database,
@Nullable String useSSL) {
// Use protocol as "tcps" when SSL is requested or else use "tcp".
String connectionProtocol;
if (useSSL != null && useSSL.equalsIgnoreCase("yes")) {
connectionProtocol = "tcps";
} else {
connectionProtocol = "tcp";
}

// For TNS Descriptor we can't specify the protocol in connection string.
if (OracleConstants.TNS_CONNECTION_TYPE.equalsIgnoreCase(connectionType)) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_TNS_FORMAT, database);
}
if (OracleConstants.SERVICE_CONNECTION_TYPE.equalsIgnoreCase(connectionType)) {
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SERVICE_NAME_FORMAT,
host, port, database);
connectionProtocol, host, port, database);
}
return String.format(OracleConstants.ORACLE_CONNECTION_STRING_SID_FORMAT,
host, port, database);
connectionProtocol, host, port, database);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static class OracleQueryActionConfig extends DBSpecificQueryActionConfig

@Override
public String getConnectionString() {
return OracleConstants.getConnectionString(this.connectionType, host, port, database);
return OracleConstants.getConnectionString(this.connectionType, host, port, database, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public OracleSourceConfig(String host, int port, String user, String password, S
String connectionArguments, String connectionType, String database, String role,
int defaultBatchValue, int defaultRowPrefetch,
String importQuery, Integer numSplits, int fetchSize,
String boundingQuery, String splitBy) {
String boundingQuery, String splitBy, String useSSL) {
this.connection = new OracleConnectorConfig(host, port, user, password, jdbcPluginName, connectionArguments,
connectionType, database, role);
connectionType, database, role, useSSL);
this.defaultBatchValue = defaultBatchValue;
this.defaultRowPrefetch = defaultRowPrefetch;
this.fetchSize = fetchSize;
Expand All @@ -132,7 +132,7 @@ public OracleSourceConfig(String host, int port, String user, String password, S
@Override
public String getConnectionString() {
return OracleConstants.getConnectionString(connection.getConnectionType(), connection.getHost(),
connection.getPort(), connection.getDatabase());
connection.getPort(), connection.getDatabase(), connection.getSSlMode());
}

@Override
Expand Down

0 comments on commit 822e9f3

Please sign in to comment.