Skip to content

Commit

Permalink
Adapted providers to new version of the driver (#148)
Browse files Browse the repository at this point in the history
* Adapted providers to new version of the driver

* For parser type to be JSON

* Updated test

* Undo test update

* Updated service providers

* Update name of PasswordProvider

* Renaming service providers

* Undo rename

* implement OracleConfigurationSecretProvider instead of OracleConfigurationJsonSecretProvider

* Implement both

* Add both service providers

* Trying with two different providers

* Update test

* Changes to secret providers

* Updated javadoc

* Removed old implementation.

* Fixed test and provider

* Test using secret properties

* Added type parameter

* OCI tests

* Updated javadoc

* Updated version to 1.0.3

* Removed unused method that was commented out + updated requiredments on README file

* Removed unused class
  • Loading branch information
fmeheust authored Feb 8, 2025
1 parent dd3b171 commit 182024c
Show file tree
Hide file tree
Showing 28 changed files with 96 additions and 222 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ consume the JDBC driver.
The requirements for using a provider are:
<ul>
<li>The class path includes the provider's jar.</li>
<li>The class path includes Oracle JDBC 23.3 or newer.</li>
<li>The class path includes Oracle JDBC 23.7 or newer.</li>
<li>Oracle JDBC is configured to use the provider.</li>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion ojdbc-provider-azure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ JDK versions. The coordinates for the latest release are:
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-azure</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion ojdbc-provider-azure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-extensions</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</parent>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
* {@link TokenCredential} created by {@link TokenCredentialFactory} is passed
* to the {@link #request(TokenCredential, ParameterSet)} method of a subclass.
* </p>
* @param <T> the type
*/
public abstract class AzureResourceFactory<T> implements ResourceFactory<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import oracle.jdbc.spi.OracleConfigurationCachableProvider;
import oracle.jdbc.util.OracleConfigurationCache;
import oracle.jdbc.util.OracleConfigurationProviderNetworkError;
import oracle.jdbc.spi.OracleConfigurationProvider;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.provider.azure.authentication.TokenCredentialFactory;
import oracle.sql.json.OracleJsonFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

package oracle.jdbc.provider.azure.configuration;

import oracle.jdbc.driver.OracleConfigurationJsonProvider;
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;
Expand All @@ -52,9 +52,9 @@

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

/**
* Parser that recognizes the "key" and "value" field,
Expand Down Expand Up @@ -85,7 +85,7 @@ public class AzureVaultJsonProvider extends OracleConfigurationJsonProvider {
* @return JSON payload
**/
@Override
public InputStream getJson(String secretIdentifier) {
public InputStream getInputStream(String secretIdentifier) {
final String valueFieldName = "value";
Map<String, String> optionsWithSecret = new HashMap<>(options);
optionsWithSecret.put(valueFieldName, secretIdentifier);
Expand Down Expand Up @@ -116,6 +116,11 @@ public String getType() {
return "azurevault";
}

@Override
public String getParserType(String arg0) {
return "json";
}

/**
* {@inheritDoc}
* @return cache of this provider which is used to store configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@
package oracle.jdbc.provider.azure.configuration;

import oracle.jdbc.provider.azure.keyvault.KeyVaultSecretFactory;
import oracle.jdbc.spi.OracleConfigurationJsonSecretProvider;
import oracle.jdbc.provider.configuration.JsonSecretUtil;
import oracle.jdbc.spi.OracleConfigurationSecretProvider;
import oracle.jdbc.provider.parameter.Parameter;
import oracle.jdbc.provider.parameter.ParameterSet;
import oracle.jdbc.provider.parameter.ParameterSetParser;
import oracle.sql.json.OracleJsonObject;

import java.util.Base64;
import java.util.Map;

/**
* A provider of Secret values from Azure Key Vault.
*/
public final class AzureVaultSecretProvider
implements OracleConfigurationJsonSecretProvider {
implements OracleConfigurationSecretProvider {
/**
* Parser that recognizes the "value" field and parses it as a Key Vault
* secret URL.
Expand All @@ -62,15 +62,16 @@ public final class AzureVaultSecretProvider
public static final ParameterSetParser PARAMETER_SET_PARSER =
AzureConfigurationParameters.configureBuilder(
ParameterSetParser.builder()
.addParameter("type", Parameter.create())
.addParameter("value", AzureVaultURLParser::parseVaultSecretUri))
.build();

/**
* {@inheritDoc}
* <p>
* Returns the password of the Secret that is retrieved from Azure Key Vault.
* Returns the password of the Secret that is retrieved from Azure Key Vault.
* </p><p>
* The {@code secretJsonObject} has the following form:
* The JSON object has the following form:
* </p><pre>{@code
* "password": {
* "type": "azurevault",
Expand All @@ -81,16 +82,15 @@ public final class AzureVaultSecretProvider
* }
* }</pre>
*
* @param secretJsonObject json object to be parsed
* @param secretProperties a map containing the flattened JSON object.
* @return encoded char array in base64 format that represents the retrieved
* Secret.
*/
@Override
public char[] getSecret(OracleJsonObject secretJsonObject) {
public char[] getSecret(Map<String, String> secretProperties) {

ParameterSet parameterSet =
PARAMETER_SET_PARSER.parseNamedValues(
JsonSecretUtil.toNamedValues(secretJsonObject));
PARAMETER_SET_PARSER.parseNamedValues(secretProperties);

String secretString = KeyVaultSecretFactory.getInstance()
.request(parameterSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@
import oracle.jdbc.provider.azure.authentication.AzureAuthenticationMethod;
import oracle.jdbc.provider.azure.AzureTestProperty;
import oracle.jdbc.spi.OracleConfigurationJsonSecretProvider;
import oracle.sql.json.OracleJsonFactory;
import oracle.sql.json.OracleJsonObject;
import oracle.jdbc.spi.OracleConfigurationSecretProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static oracle.jdbc.provider.TestProperties.getOrAbort;
import java.util.HashMap;
import java.util.Map;

public class AzureVaultSecretProviderTest {
private static final OracleConfigurationJsonSecretProvider PROVIDER =
OracleConfigurationJsonSecretProvider.find("azurevault");
private static final OracleConfigurationSecretProvider PROVIDER =
OracleConfigurationSecretProvider.find("azurevault");

/**
* Verifies {@link OracleConfigurationJsonSecretProvider} as implementing
Expand All @@ -61,7 +61,7 @@ public class AzureVaultSecretProviderTest {
@Test
public void test() {
Assertions.assertNotNull(PROVIDER.getSecret(
constructJsonObject(
constructSecretProperties(
TestProperties.getOrAbort(AzureTestProperty.AZURE_KEY_VAULT_URL),
TestProperties.getOrAbort(AzureTestProperty.AZURE_KEY_VAULT_SECRET_NAME),
TestProperties.getOrAbort(AzureTestProperty.AZURE_CLIENT_ID),
Expand All @@ -70,38 +70,16 @@ public void test() {
)));
}

/**
* Returns a JSON object in following format:
* <pre>
* {
* "type": "azurevault",
* "value": "{"uri":"https://ojdbc-plugin-test-vault.vault.azure.net/secrets/test-db-password"}",
* "authentication": {
* "method": "AZURE_SERVICE_PRINCIPAL",
* "AZURE_CLIENT_ID": "<client-id>",
* "AZURE_CLIENT_SECRET": "<client-secret>",
* "AZURE_TENANT_ID": "<tenant-id>",
* }
* }
* </pre>
*/
private OracleJsonObject constructJsonObject(
private Map<String,String> constructSecretProperties(
String vaultUrl, String secretName, String clientId, String clientSecret, String tenantId) {

OracleJsonFactory factory = new OracleJsonFactory();

OracleJsonObject auth = factory.createObject();
auth.put("method", "AZURE_SERVICE_PRINCIPAL");
auth.put("AZURE_CLIENT_ID", clientId);
auth.put("AZURE_CLIENT_SECRET", clientSecret);
auth.put("AZURE_TENANT_ID", tenantId);

OracleJsonObject password = factory.createObject();
password.put("type", "azurevault");
password.put("value", constructSecretUri(vaultUrl, secretName));
password.put("authentication", auth);

return password;
Map<String,String> secretProperties = new HashMap<>();
secretProperties.put("AUTHENTICATION", "AZURE_SERVICE_PRINCIPAL");
secretProperties.put("AZURE_CLIENT_ID", clientId);
secretProperties.put("AZURE_CLIENT_SECRET", clientSecret);
secretProperties.put("AZURE_TENANT_ID", tenantId);
secretProperties.put("type", "azurevault");
secretProperties.put("value", constructSecretUri(vaultUrl, secretName));
return secretProperties;
}

private String constructSecretUri(String vaultUrl, String secretName) {
Expand Down
2 changes: 1 addition & 1 deletion ojdbc-provider-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-extensions</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</parent>

<dependencies>
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions ojdbc-provider-jackson-oson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ JDK versions. The coordinates for the latest release are:
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-jackson-oson</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</dependency>
```
### Note
Expand All @@ -56,7 +56,7 @@ It can be done in maven as:
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-jackson-oson</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<exclusions>
<exclusion>
<groupId>com.oracle.database.jdbc</groupId>
Expand Down
4 changes: 2 additions & 2 deletions ojdbc-provider-jackson-oson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-extensions</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</parent>

<artifactId>ojdbc-provider-jackson-oson</artifactId>
Expand All @@ -21,7 +21,7 @@
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc-provider-common</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
Expand Down
Loading

0 comments on commit 182024c

Please sign in to comment.