Skip to content

Commit 669e1c0

Browse files
Jithendar12Trianz-Akshayfal-bharadwajchngpe
authored
Replace connector-specific JDBC factory with GenericJdbcConnectionFactory in athena-oracle (#3219)
Co-authored-by: akshay.kachore <akshay.kachore@trianz.com> Co-authored-by: Fal Bharadwaj <falgunb@amazon.com> Co-authored-by: chngpe <102991671+chngpe@users.noreply.github.com>
1 parent c68c065 commit 669e1c0

File tree

8 files changed

+628
-381
lines changed

8 files changed

+628
-381
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*-
2+
* #%L
3+
* athena-oracle
4+
* %%
5+
* Copyright (C) 2019 - 2026 Amazon Web Services
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.amazonaws.athena.connectors.oracle;
21+
22+
import com.amazonaws.athena.connector.credentials.CredentialsConstants;
23+
import com.amazonaws.athena.connector.credentials.DefaultCredentials;
24+
import com.amazonaws.athena.connector.credentials.DefaultCredentialsProvider;
25+
import com.google.common.annotations.VisibleForTesting;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
28+
29+
import java.util.HashMap;
30+
import java.util.Map;
31+
32+
public class OracleCredentialsProvider extends DefaultCredentialsProvider
33+
{
34+
public static final String IS_FIPS_ENABLED = "is_fips_enabled";
35+
public static final String IS_FIPS_ENABLED_LEGACY = "is_FIPS_Enabled";
36+
private static final Logger LOGGER = LoggerFactory.getLogger(OracleCredentialsProvider.class);
37+
38+
private final String jdbcConnectionString;
39+
40+
public OracleCredentialsProvider(final String secretString, final String jdbcConnectionString)
41+
{
42+
super(secretString);
43+
this.jdbcConnectionString = jdbcConnectionString;
44+
}
45+
46+
@Override
47+
public Map<String, String> getCredentialMap()
48+
{
49+
DefaultCredentials creds = getCredential();
50+
String password = creds.getPassword();
51+
if (!password.contains("\"")) {
52+
password = String.format("\"%s\"", password);
53+
}
54+
55+
Map<String, String> credMap = new HashMap<>();
56+
credMap.put(CredentialsConstants.USER, creds.getUser());
57+
credMap.put(CredentialsConstants.PASSWORD, password);
58+
59+
//checking for tcps (Secure Communication) protocol as part of the connection string.
60+
if (jdbcConnectionString != null && jdbcConnectionString.toLowerCase().contains("@tcps://")) {
61+
LOGGER.info("Adding SSL properties...");
62+
credMap.put("javax.net.ssl.trustStoreType", "JKS");
63+
credMap.put("javax.net.ssl.trustStorePassword", "changeit");
64+
credMap.put("oracle.net.ssl_server_dn_match", "true");
65+
66+
// By default; Oracle RDS uses SSL_RSA_WITH_AES_256_CBC_SHA
67+
// Adding the following cipher suits to support others listed in Doc
68+
// https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.Oracle.Options.SSL.html#Appendix.Oracle.Options.SSL.CipherSuites
69+
if (isFipsEnabled()) {
70+
credMap.put("oracle.net.ssl_cipher_suites",
71+
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384," +
72+
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256," +
73+
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384," +
74+
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256," +
75+
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA," +
76+
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA");
77+
}
78+
}
79+
80+
return credMap;
81+
}
82+
83+
// Returns true if either current or legacy FIPS environment variable is set to "true"
84+
private boolean isFipsEnabled()
85+
{
86+
return Boolean.parseBoolean(getFipsEnabledEnv()) ||
87+
Boolean.parseBoolean(getFipsEnabledLegacyEnv());
88+
}
89+
90+
@VisibleForTesting
91+
protected String getFipsEnabledEnv()
92+
{
93+
return System.getenv(IS_FIPS_ENABLED);
94+
}
95+
96+
@VisibleForTesting
97+
protected String getFipsEnabledLegacyEnv()
98+
{
99+
return System.getenv(IS_FIPS_ENABLED_LEGACY);
100+
}
101+
}

athena-oracle/src/main/java/com/amazonaws/athena/connectors/oracle/OracleJdbcConnectionFactory.java

Lines changed: 0 additions & 115 deletions
This file was deleted.

athena-oracle/src/main/java/com/amazonaws/athena/connectors/oracle/OracleMetadataHandler.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
package com.amazonaws.athena.connectors.oracle;
2222

23+
import com.amazonaws.athena.connector.credentials.CredentialsProvider;
2324
import com.amazonaws.athena.connector.lambda.QueryStatusChecker;
2425
import com.amazonaws.athena.connector.lambda.data.Block;
2526
import com.amazonaws.athena.connector.lambda.data.BlockAllocator;
@@ -45,6 +46,7 @@
4546
import com.amazonaws.athena.connector.lambda.metadata.optimizations.pushdown.TopNPushdownSubType;
4647
import com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig;
4748
import com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionInfo;
49+
import com.amazonaws.athena.connectors.jdbc.connection.GenericJdbcConnectionFactory;
4850
import com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory;
4951
import com.amazonaws.athena.connectors.jdbc.manager.JDBCUtil;
5052
import com.amazonaws.athena.connectors.jdbc.manager.JdbcArrowTypeConverter;
@@ -112,7 +114,7 @@ public OracleMetadataHandler(java.util.Map<String, String> configOptions)
112114
*/
113115
public OracleMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, java.util.Map<String, String> configOptions)
114116
{
115-
this(databaseConnectionConfig, new OracleJdbcConnectionFactory(databaseConnectionConfig, new DatabaseConnectionInfo(OracleConstants.ORACLE_DRIVER_CLASS, OracleConstants.ORACLE_DEFAULT_PORT)), configOptions);
117+
this(databaseConnectionConfig, new GenericJdbcConnectionFactory(databaseConnectionConfig, null, new DatabaseConnectionInfo(OracleConstants.ORACLE_DRIVER_CLASS, OracleConstants.ORACLE_DEFAULT_PORT)), configOptions);
116118
}
117119

118120
public OracleMetadataHandler(DatabaseConnectionConfig databaseConnectionConfig, JdbcConnectionFactory jdbcConnectionFactory, java.util.Map<String, String> configOptions)
@@ -384,4 +386,12 @@ protected Schema getSchema(Connection jdbcConnection, TableName tableName, Schem
384386
return schemaBuilder.build();
385387
}
386388
}
389+
390+
@Override
391+
public CredentialsProvider createCredentialsProvider(String secretName, AwsRequestOverrideConfiguration requestOverrideConfiguration)
392+
{
393+
return new OracleCredentialsProvider(
394+
getSecret(secretName, requestOverrideConfiguration),
395+
getDatabaseConnectionConfig().getJdbcConnectionString());
396+
}
387397
}

athena-oracle/src/main/java/com/amazonaws/athena/connectors/oracle/OracleRecordHandler.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
*/
2020
package com.amazonaws.athena.connectors.oracle;
2121

22+
import com.amazonaws.athena.connector.credentials.CredentialsProvider;
2223
import com.amazonaws.athena.connector.lambda.domain.Split;
2324
import com.amazonaws.athena.connector.lambda.domain.TableName;
2425
import com.amazonaws.athena.connector.lambda.domain.predicate.Constraints;
2526
import com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig;
2627
import com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionInfo;
28+
import com.amazonaws.athena.connectors.jdbc.connection.GenericJdbcConnectionFactory;
2729
import com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory;
2830
import com.amazonaws.athena.connectors.jdbc.manager.JDBCUtil;
2931
import com.amazonaws.athena.connectors.jdbc.manager.JdbcRecordHandler;
@@ -33,6 +35,7 @@
3335
import org.apache.commons.lang3.Validate;
3436
import org.slf4j.Logger;
3537
import org.slf4j.LoggerFactory;
38+
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
3639
import software.amazon.awssdk.services.athena.AthenaClient;
3740
import software.amazon.awssdk.services.s3.S3Client;
3841
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
@@ -69,7 +72,7 @@ public OracleRecordHandler(java.util.Map<String, String> configOptions)
6972

7073
public OracleRecordHandler(DatabaseConnectionConfig databaseConnectionConfig, java.util.Map<String, String> configOptions)
7174
{
72-
this(databaseConnectionConfig, new OracleJdbcConnectionFactory(databaseConnectionConfig, new DatabaseConnectionInfo(ORACLE_DRIVER_CLASS, ORACLE_DEFAULT_PORT)), configOptions);
75+
this(databaseConnectionConfig, new GenericJdbcConnectionFactory(databaseConnectionConfig, null, new DatabaseConnectionInfo(ORACLE_DRIVER_CLASS, ORACLE_DEFAULT_PORT)), configOptions);
7376
}
7477

7578
public OracleRecordHandler(DatabaseConnectionConfig databaseConnectionConfig, JdbcConnectionFactory jdbcConnectionFactory, java.util.Map<String, String> configOptions)
@@ -103,4 +106,12 @@ public PreparedStatement buildSplitSql(Connection jdbcConnection, String catalog
103106

104107
return preparedStatement;
105108
}
109+
110+
@Override
111+
public CredentialsProvider createCredentialsProvider(String secretName, AwsRequestOverrideConfiguration requestOverrideConfiguration)
112+
{
113+
return new OracleCredentialsProvider(
114+
getSecret(secretName, requestOverrideConfiguration),
115+
getDatabaseConnectionConfig().getJdbcConnectionString());
116+
}
106117
}

0 commit comments

Comments
 (0)