Skip to content

Commit

Permalink
Update the code using the latest driver. Use JDK 17 in the root proje…
Browse files Browse the repository at this point in the history
…ct. Fix incorrect version numbers in pom.xml. Merge the changes from origin/main.
  • Loading branch information
ting-lan-wang committed Dec 7, 2024
1 parent f50a184 commit ea95905
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 357 deletions.
1 change: 0 additions & 1 deletion ojdbc-provider-azure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@

package oracle.jdbc.provider.azure.configuration;

import com.azure.security.keyvault.secrets.models.KeyVaultSecret;
import oracle.jdbc.driver.configuration.OracleConfigurationParsableProvider;
import oracle.jdbc.provider.azure.keyvault.KeyVaultSecretFactory;
import oracle.jdbc.provider.parameter.Parameter;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.util.OracleConfigurationCache;
import oracle.jdbc.provider.parameter.ParameterSetParser;
import oracle.jdbc.util.OracleConfigurationCache;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand All @@ -56,6 +55,7 @@
* See {@link #getInputStream(String)} for the spec of the JSON payload.
*/
public class AzureVaultJsonProvider extends OracleConfigurationParsableProvider {

private static final OracleConfigurationCache CACHE = OracleConfigurationCache.create(100);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.oracle.bmc.databasetools.model.DatabaseToolsConnection;
import com.oracle.bmc.databasetools.model.DatabaseToolsConnectionOracleDatabase;
import com.oracle.bmc.databasetools.model.DatabaseToolsConnectionOracleDatabaseProxyClient;
import com.oracle.bmc.databasetools.model.DatabaseToolsConnectionOracleDatabaseProxyClientUserName;
import com.oracle.bmc.databasetools.model.DatabaseToolsKeyStore;
import com.oracle.bmc.databasetools.model.DatabaseToolsKeyStoreContent;
import com.oracle.bmc.databasetools.model.DatabaseToolsKeyStoreContentSecretId;
Expand All @@ -10,14 +12,11 @@
import com.oracle.bmc.databasetools.model.DatabaseToolsUserPassword;
import com.oracle.bmc.databasetools.model.DatabaseToolsUserPasswordSecretId;
import com.oracle.bmc.databasetools.model.LifecycleState;
import com.oracle.bmc.databasetools.model.DatabaseToolsConnectionOracleDatabaseProxyClient;
import com.oracle.bmc.databasetools.model.DatabaseToolsConnectionOracleDatabaseProxyClientUserName;
import com.oracle.bmc.model.BmcException;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.provider.oci.OciResourceParameter;
import oracle.jdbc.provider.oci.databasetools.DatabaseToolsConnectionFactory;
import oracle.jdbc.provider.oci.vault.SecretBundle;
import oracle.jdbc.provider.oci.vault.SecretBundleFactory;
import oracle.jdbc.provider.oci.vault.Secret;
import oracle.jdbc.provider.oci.vault.SecretFactory;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.spi.OracleConfigurationCachableProvider;
import oracle.jdbc.spi.OracleConfigurationProvider;
Expand All @@ -29,7 +28,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;

/**
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package oracle.jdbc.provider.oci.configuration;

import oracle.jdbc.driver.configuration.OracleConfigurationParsableProvider;
import oracle.jdbc.provider.oci.vault.SecretBundleFactory;
import oracle.jdbc.provider.oci.vault.SecretFactory;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.util.OracleConfigurationCache;
Expand All @@ -12,15 +11,12 @@
import java.util.HashMap;
import java.util.Map;

import static java.util.Objects.requireNonNull;

/**
* A provider for JSON payload which contains configuration from OCI Vault.
* See {@link #getInputStream(String)} for the spec of the JSON payload.
**/
public class OciVaultJsonProvider extends OracleConfigurationParsableProvider {

private String secretName;
private static final OracleConfigurationCache CACHE = OracleConfigurationCache.create(100);

/**
Expand All @@ -45,14 +41,8 @@ public InputStream getInputStream(String secretOcid) {
OciConfigurationParameters.getParser()
.parseNamedValues(optionsWithOcid);

// Get secret name
secretName = SecretFactory.getInstance()
.request(parameters)
.getContent()
.getName();

// Get secret contents
String secretContent = SecretBundleFactory.getInstance()
String secretContent = SecretFactory.getInstance()
.request(parameters)
.getContent()
.getBase64Secret();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

package oracle.jdbc.provider.oci.configuration;

import oracle.jdbc.provider.oci.vault.SecretBundle;
import oracle.jdbc.provider.oci.vault.SecretBundleFactory;
import oracle.jdbc.provider.oci.vault.Secret;
import oracle.jdbc.provider.oci.vault.SecretFactory;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.spi.OracleConfigurationSecretProvider;

Expand Down Expand Up @@ -67,7 +67,7 @@ public final class OciVaultSecretProvider
* }
* }</pre>
*
* @param secretJsonObject json object to be parsed
* @param secretMap A map object to be parsed
* @return encoded char array in base64 format that represents the retrieved
* Secret.
*/
Expand All @@ -77,7 +77,7 @@ public char[] getSecret(Map<String, String> secretMap) {
OciConfigurationParameters.getParser()
.parseNamedValues(secretMap);

SecretBundle secretBundle = SecretBundleFactory.getInstance()
Secret secretBundle = SecretFactory.getInstance()
.request(parameters)
.getContent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@

package oracle.jdbc.provider.oci.resource;

import oracle.jdbc.provider.oci.OciResourceParameter;
import oracle.jdbc.provider.oci.vault.SecretBundleFactory;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.provider.resource.ResourceParameter;
import oracle.jdbc.spi.PasswordProvider;

import java.util.Map;

import static oracle.jdbc.provider.oci.vault.SecretFactory.OCID;

/**
* <p>
* A provider of passwords from the OCI Vault service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
package oracle.jdbc.provider.oci.resource;

import oracle.jdbc.provider.oci.vault.Secret;
import oracle.jdbc.provider.oci.OciResourceParameter;
import oracle.jdbc.provider.oci.vault.SecretBundleFactory;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.provider.resource.ResourceParameter;
import oracle.jdbc.spi.UsernameProvider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,77 @@

package oracle.jdbc.provider.oci.vault;

import com.oracle.bmc.secrets.model.Base64SecretBundleContentDetails;
import com.oracle.bmc.secrets.model.SecretBundle;
import com.oracle.bmc.secrets.model.SecretBundleContentDetails;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.util.Arrays;
import java.util.Base64;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* A secret managed by the OCI Vault service.
*/
public final class Secret {

private final String name;
private final String base64Secret;

private Secret(String name) {
this.name = name;
private Secret(String base64Secret) {
this.base64Secret = base64Secret;
}

static Secret fromSecret(com.oracle.bmc.vault.model.Secret secret) {
return new Secret(secret.getSecretName());
static Secret fromSecretBundle(SecretBundle secretBundle) {

SecretBundleContentDetails secretBundleContentDetails =
secretBundle.getSecretBundleContent();

if (secretBundleContentDetails instanceof
Base64SecretBundleContentDetails) {

String base64Secret =
((Base64SecretBundleContentDetails)secretBundleContentDetails)
.getContent();

return new Secret(base64Secret);
}
else {
throw new IllegalStateException(
"Unsupported content type: " + secretBundleContentDetails.getClass());
}
}

/**
* Returns the secret decoded as UTF-8 characters. The {@code char[]} returned
* by this method is not retained: It's contents may be wiped from memory
* after it has been consumed.
* @return Characters representing the UTF-8 decoding of the secret. Not null.
*/
public char[] toCharArray() {
byte[] contentBytes = Base64.getDecoder().decode(base64Secret);
try {
CharBuffer contentBuffer = UTF_8.decode(ByteBuffer.wrap(contentBytes));
char[] contentChars = new char[contentBuffer.remaining()];
try {
contentBuffer.get(contentChars);
return contentChars;
}
finally {
contentBuffer.clear();
contentBuffer.put(new char[contentBuffer.capacity()]);
}
}
finally {
Arrays.fill(contentBytes, (byte)0);
}
}

/**
* @return String that represents name of the Secret
* @return String that represents the Secret in base64 format
*/
public String getName() {
return name;
public String getBase64Secret() {
return base64Secret;
}
}

This file was deleted.

Loading

0 comments on commit ea95905

Please sign in to comment.