Skip to content

Commit c6ad416

Browse files
Dilli-Babu-Godarilukmanulhakkeem
authored andcommitted
Added ssl configs for oracle
SSL enablement of Oracle Connector with Oracle THIN JDBC driver Co-authored-by: lukmanulhakkeem <lukmanul.hakkeem.a@ibm.com>
1 parent 3de246f commit c6ad416

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

presto-oracle/src/main/java/com/facebook/presto/plugin/oracle/OracleClientModule.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Properties;
3131

3232
import static com.facebook.airlift.configuration.ConfigBinder.configBinder;
33+
import static java.util.Objects.requireNonNull;
3334

3435
public class OracleClientModule
3536
implements Module
@@ -49,8 +50,22 @@ public static ConnectionFactory connectionFactory(BaseJdbcConfig config, OracleC
4950
throws SQLException
5051
{
5152
Properties connectionProperties = new Properties();
52-
connectionProperties.setProperty(OracleConnection.CONNECTION_PROPERTY_INCLUDE_SYNONYMS, String.valueOf(oracleConfig.isSynonymsEnabled()));
5353

54+
requireNonNull(oracleConfig, "oracle config is null");
55+
requireNonNull(config, "BaseJdbc config is null");
56+
if (config.getConnectionUser() != null && config.getConnectionPassword() != null) {
57+
connectionProperties.setProperty("user", config.getConnectionUser());
58+
connectionProperties.setProperty("password", config.getConnectionPassword());
59+
}
60+
if (oracleConfig.isTlsEnabled()) {
61+
if (oracleConfig.getTrustStorePath() != null) {
62+
connectionProperties.setProperty("javax.net.ssl.trustStore", oracleConfig.getTrustStorePath());
63+
}
64+
if (oracleConfig.getTruststorePassword() != null) {
65+
connectionProperties.setProperty("javax.net.ssl.trustStorePassword", oracleConfig.getTruststorePassword());
66+
}
67+
}
68+
connectionProperties.setProperty(OracleConnection.CONNECTION_PROPERTY_INCLUDE_SYNONYMS, String.valueOf(oracleConfig.isSynonymsEnabled()));
5469
return new DriverConnectionFactory(
5570
new OracleDriver(),
5671
config.getConnectionUrl(),

presto-oracle/src/main/java/com/facebook/presto/plugin/oracle/OracleConfig.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public class OracleConfig
2727
private int timestampDefaultPrecision = 6;
2828
private int numberDefaultScale = 10;
2929
private RoundingMode numberRoundingMode = RoundingMode.HALF_UP;
30+
private boolean tlsEnabled;
31+
private String trustStorePath;
32+
private String truststorePassword;
3033

3134
@NotNull
3235
public boolean isSynonymsEnabled()
@@ -94,4 +97,40 @@ public OracleConfig setTimestampDefaultPrecision(int timestampDefaultPrecision)
9497
this.timestampDefaultPrecision = timestampDefaultPrecision;
9598
return this;
9699
}
100+
101+
public boolean isTlsEnabled()
102+
{
103+
return tlsEnabled;
104+
}
105+
106+
@Config("oracle.tls.enabled")
107+
public OracleConfig setTlsEnabled(boolean tlsEnabled)
108+
{
109+
this.tlsEnabled = tlsEnabled;
110+
return this;
111+
}
112+
113+
public String getTrustStorePath()
114+
{
115+
return trustStorePath;
116+
}
117+
118+
@Config("oracle.tls.truststore-path")
119+
public OracleConfig setTrustStorePath(String path)
120+
{
121+
this.trustStorePath = path;
122+
return this;
123+
}
124+
125+
public String getTruststorePassword()
126+
{
127+
return truststorePassword;
128+
}
129+
130+
@Config("oracle.tls.truststore-password")
131+
public OracleConfig setTruststorePassword(String password)
132+
{
133+
this.truststorePassword = password;
134+
return this;
135+
}
97136
}

presto-oracle/src/test/java/com/facebook/presto/plugin/oracle/TestOracleConfig.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ public void testDefaults()
3333
.setVarcharMaxSize(4000)
3434
.setTimestampDefaultPrecision(6)
3535
.setNumberDefaultScale(10)
36-
.setNumberRoundingMode(RoundingMode.HALF_UP));
36+
.setNumberRoundingMode(RoundingMode.HALF_UP)
37+
.setTlsEnabled(false)
38+
.setTrustStorePath(null)
39+
.setTruststorePassword(null));
3740
}
3841

3942
@Test
@@ -45,14 +48,20 @@ public void testExplicitPropertyMappings()
4548
.put("oracle.timestamp.precision", "3")
4649
.put("oracle.number.default-scale", "2")
4750
.put("oracle.number.rounding-mode", "CEILING")
51+
.put("oracle.tls.enabled", "true")
52+
.put("oracle.tls.truststore-path", "/my/path/to/truststore.jks")
53+
.put("oracle.tls.truststore-password", "changeit")
4854
.build();
4955

5056
OracleConfig expected = new OracleConfig()
5157
.setSynonymsEnabled(true)
5258
.setVarcharMaxSize(10000)
5359
.setTimestampDefaultPrecision(3)
5460
.setNumberDefaultScale(2)
55-
.setNumberRoundingMode(RoundingMode.CEILING);
61+
.setNumberRoundingMode(RoundingMode.CEILING)
62+
.setTlsEnabled(true)
63+
.setTrustStorePath("/my/path/to/truststore.jks")
64+
.setTruststorePassword("changeit");
5665

5766
assertFullMapping(properties, expected);
5867
}

0 commit comments

Comments
 (0)