consumeConnectionString() {
+ return QueueServiceClientBuilder::connectionString;
+ }
+
+ @Override
+ protected String getApplicationId() {
+ return AZURE_SPRING_STORAGE_QUEUE + VERSION;
+ }
+
+ private QueueMessageEncoding convertToMessageEncoding(String messageEncoding) {
+ return QueueMessageEncoding.BASE64
+ .name()
+ .equalsIgnoreCase(messageEncoding) ? QueueMessageEncoding.BASE64 : QueueMessageEncoding.NONE;
+ }
+}
diff --git a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/queue/package-info.java b/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/queue/package-info.java
new file mode 100644
index 000000000000..16ba9ba2d268
--- /dev/null
+++ b/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/queue/package-info.java
@@ -0,0 +1,8 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+/**
+ * Package com.azure.spring.cloud.autoconfigure.storage.queue;
+ */
+package com.azure.spring.cloud.autoconfigure.storage.queue;
+
diff --git a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessor.java b/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessor.java
index 3ff99b1b1ce8..1a0fd8013231 100644
--- a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessor.java
+++ b/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessor.java
@@ -3,27 +3,50 @@
package com.azure.spring.keyvault;
-import com.azure.spring.autoconfigure.unity.PreLegacyPropertyEnvironmentPostProcessor;
+import com.azure.security.keyvault.secrets.SecretClient;
+import com.azure.spring.cloud.autoconfigure.keyvault.secrets.AzureKeyVaultPropertySourceProperties;
+import com.azure.spring.cloud.autoconfigure.keyvault.secrets.AzureKeyVaultSecretProperties;
+import com.azure.spring.cloud.autoconfigure.keyvault.secrets.SecretClientBuilderFactory;
+import com.azure.spring.cloud.autoconfigure.properties.AzureGlobalProperties;
+import com.azure.spring.core.properties.AzurePropertiesUtils;
+import org.apache.commons.logging.Log;
import org.springframework.boot.SpringApplication;
+import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
+import org.springframework.boot.context.properties.PropertyMapper;
+import org.springframework.boot.context.properties.bind.Bindable;
+import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.MutablePropertySources;
+import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
+import java.util.Collections;
+import java.util.List;
+
+import static org.springframework.core.env.StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME;
+
/**
* Leverage {@link EnvironmentPostProcessor} to add Key Vault secrets as a property source.
*/
public class KeyVaultEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
- public static final int DEFAULT_ORDER = PreLegacyPropertyEnvironmentPostProcessor.DEFAULT_ORDER + 1;
- private int order = DEFAULT_ORDER;
+
+ public static final int ORDER = ConfigDataEnvironmentPostProcessor.ORDER + 1;
+
+ private final Log logger;
+
+ public KeyVaultEnvironmentPostProcessor(Log logger) {
+ this.logger = logger;
+ }
+
/**
- * Post process the environment.
+ * Post-process the environment.
*
*
- * Here we are going to process any key vault(s) and make them as available
- * PropertySource(s). Note this supports both the singular key vault setup,
- * as well as the multiple key vault setup.
+ * Here we are going to process any key vault(s) and make them as available PropertySource(s). Note this supports
+ * both the singular key vault setup, as well as the multiple key vault setup.
*
*
* @param environment the environment.
@@ -31,61 +54,135 @@ public class KeyVaultEnvironmentPostProcessor implements EnvironmentPostProcesso
*/
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
- final KeyVaultEnvironmentPostProcessorHelper helper
- = new KeyVaultEnvironmentPostProcessorHelper(environment);
- if (hasMultipleKeyVaultsEnabled(environment)) {
- final String property = environment.
- getProperty(KeyVaultProperties.getPropertyName(KeyVaultProperties.Property.ORDER), "");
- final String[] keyVaultNames = property.split(",");
- for (int i = keyVaultNames.length - 1; i >= 0; i--) {
- final String normalizedName = keyVaultNames[i].trim();
- if (isKeyVaultEnabled(environment, normalizedName)) {
- helper.addKeyVaultPropertySource(normalizedName);
- }
+ if (!isKeyVaultClientAvailable()) {
+ logger.info("Key Vault client is not present, skip the Key Vault property source");
+ return;
+ }
+
+ final AzureKeyVaultSecretProperties keyVaultSecretProperties = loadProperties(Binder.get(environment));
+
+ if (isKeyVaultPropertySourceEnabled(keyVaultSecretProperties)) {
+
+ // TODO (xiada): confirm the order
+ final List propertySources = keyVaultSecretProperties.getPropertySources();
+ Collections.reverse(propertySources);
+
+ if (propertySources.isEmpty()) {
+ propertySources.add(new AzureKeyVaultPropertySourceProperties());
+ }
+
+ for (AzureKeyVaultPropertySourceProperties propertySource : propertySources) {
+ final AzureKeyVaultPropertySourceProperties properties = getMergeProperties(keyVaultSecretProperties,
+ propertySource);
+ addKeyVaultPropertySource(environment, properties);
}
- } else if (isKeyVaultEnabled(environment, "")) {
- helper.addKeyVaultPropertySource("");
+ } else {
+ logger.debug("Key Vault property source is not enabled");
}
}
+ // TODO (xiada) better way to implement this
+ private AzureKeyVaultPropertySourceProperties getMergeProperties(AzureKeyVaultSecretProperties secretProperties,
+ AzureKeyVaultPropertySourceProperties propertySource) {
+ AzureKeyVaultPropertySourceProperties mergedResult = new AzureKeyVaultPropertySourceProperties();
+ AzurePropertiesUtils.copyAzureProperties(secretProperties, mergedResult);
+ AzurePropertiesUtils.copyAzurePropertiesIgnoreNull(propertySource, mergedResult);
+
+ mergedResult.setVaultUrl(secretProperties.getVaultUrl());
+ mergedResult.setServiceVersion(secretProperties.getServiceVersion());
+ mergedResult.setName(propertySource.getName());
+ mergedResult.setCaseSensitive(propertySource.getCaseSensitive());
+ mergedResult.setSecretKeys(propertySource.getSecretKeys());
+ mergedResult.setRefreshInterval(propertySource.getRefreshInterval());
+
+ PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
+ propertyMapper.from(propertySource.getVaultUrl()).to(mergedResult::setVaultUrl);
+ propertyMapper.from(propertySource.getServiceVersion()).to(mergedResult::setServiceVersion);
+
+ return mergedResult;
+ }
+
+
/**
- * Is the key vault enabled.
- * @param environment the environment.
- * @param normalizedName the normalized name used to differentiate between
- * multiple key vaults.
- * @return true if the key vault is enabled, false otherwise.
+ * Add a key vault property source.
+ *
+ *
+ * The normalizedName is used to target a specific key vault (note if the name is the empty string it works as
+ * before with only one key vault present). The normalized name is the name of the specific key vault plus a
+ * trailing "." at the end.
+ *
+ *
+ * @param environment The Spring environment.
+ * @param propertySource The property source properties.
+ * @throws IllegalStateException If KeyVaultOperations fails to initialize.
*/
- private boolean isKeyVaultEnabled(ConfigurableEnvironment environment, String normalizedName) {
- return environment.getProperty(
- KeyVaultProperties.getPropertyName(normalizedName, KeyVaultProperties.Property.ENABLED),
- Boolean.class,
- true)
- && environment.getProperty(KeyVaultProperties
- .getPropertyName(normalizedName, KeyVaultProperties.Property.URI)) != null
- && isKeyVaultClientAvailable();
+ public void addKeyVaultPropertySource(ConfigurableEnvironment environment,
+ AzureKeyVaultPropertySourceProperties propertySource) {
+ Assert.notNull(propertySource.getVaultUrl(), "vaultUri must not be null!");
+
+ AzureKeyVaultSecretProperties secretProperties = new AzureKeyVaultSecretProperties();
+ AzurePropertiesUtils.copyAzureProperties(propertySource, secretProperties);
+ secretProperties.setServiceVersion(propertySource.getServiceVersion());
+ secretProperties.setVaultUrl(propertySource.getVaultUrl());
+
+ final SecretClient secretClient = new SecretClientBuilderFactory(secretProperties).build().buildClient();
+ try {
+ final MutablePropertySources sources = environment.getPropertySources();
+ final boolean caseSensitive = Boolean.TRUE.equals(propertySource.getCaseSensitive());
+ final KeyVaultOperation keyVaultOperation = new KeyVaultOperation(secretClient,
+ propertySource.getRefreshInterval(),
+ propertySource.getSecretKeys(),
+ caseSensitive);
+
+ KeyVaultPropertySource keyVaultPropertySource = new KeyVaultPropertySource(propertySource.getName(),
+ keyVaultOperation);
+
+ if (sources.contains(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)) {
+ sources.addAfter(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, keyVaultPropertySource);
+ } else {
+ // TODO (xiada): confirm the order
+ sources.addFirst(keyVaultPropertySource);
+ }
+
+ } catch (final Exception ex) {
+ throw new IllegalStateException("Failed to configure KeyVault property source", ex);
+ }
+ }
+
+ private AzureKeyVaultSecretProperties loadProperties(Binder binder) {
+ AzureGlobalProperties azureProperties = binder
+ .bind(AzureGlobalProperties.PREFIX, Bindable.of(AzureGlobalProperties.class))
+ .orElseGet(AzureGlobalProperties::new);
+
+ AzureKeyVaultSecretProperties existingValue = new AzureKeyVaultSecretProperties();
+ AzurePropertiesUtils.copyAzureProperties(azureProperties, existingValue);
+
+
+ return binder
+ .bind(AzureKeyVaultSecretProperties.PREFIX,
+ Bindable.of(AzureKeyVaultSecretProperties.class).withExistingValue(existingValue))
+ .orElseGet(AzureKeyVaultSecretProperties::new);
}
/**
- * Determine whether or not multiple key vaults are enabled.
- * @param environment the environment.
- * @return true if enabled, false otherwise.
+ * Is the Key Vault property source enabled.
+ *
+ * @param properties The Azure Key Vault Secret properties.
+ * @return true if the key vault is enabled, false otherwise.
*/
- private boolean hasMultipleKeyVaultsEnabled(ConfigurableEnvironment environment) {
- return environment.getProperty(KeyVaultProperties.getPropertyName(KeyVaultProperties.Property.ORDER)) != null;
+ private boolean isKeyVaultPropertySourceEnabled(AzureKeyVaultSecretProperties properties) {
+ return Boolean.TRUE.equals(properties.getPropertySourceEnabled())
+ || !properties.getPropertySources().isEmpty();
}
private boolean isKeyVaultClientAvailable() {
return ClassUtils.isPresent("com.azure.security.keyvault.secrets.SecretClient",
- KeyVaultEnvironmentPostProcessor.class.getClassLoader());
+ KeyVaultEnvironmentPostProcessor.class.getClassLoader());
}
@Override
public int getOrder() {
- return order;
+ return ORDER;
}
-
- public void setOrder(int order) {
- this.order = order;
- }
}
diff --git a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessorHelper.java b/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessorHelper.java
deleted file mode 100644
index 6e545b783b6f..000000000000
--- a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessorHelper.java
+++ /dev/null
@@ -1,194 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package com.azure.spring.keyvault;
-
-import com.azure.core.credential.TokenCredential;
-import com.azure.core.http.policy.HttpLogOptions;
-import com.azure.identity.AzureAuthorityHosts;
-import com.azure.identity.ClientCertificateCredentialBuilder;
-import com.azure.identity.ClientSecretCredentialBuilder;
-import com.azure.identity.ManagedIdentityCredentialBuilder;
-import com.azure.security.keyvault.secrets.SecretClient;
-import com.azure.security.keyvault.secrets.SecretClientBuilder;
-import com.azure.security.keyvault.secrets.SecretServiceVersion;
-import com.azure.spring.autoconfigure.unity.AzureProperties;
-import com.azure.spring.keyvault.KeyVaultProperties.Property;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.boot.context.properties.bind.Bindable;
-import org.springframework.boot.context.properties.bind.Binder;
-import org.springframework.core.env.ConfigurableEnvironment;
-import org.springframework.core.env.MutablePropertySources;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-
-import static com.azure.spring.core.ApplicationId.AZURE_SPRING_KEY_VAULT;
-import static com.azure.spring.core.ApplicationId.VERSION;
-import static com.azure.spring.keyvault.KeyVaultProperties.DELIMITER;
-import static org.springframework.core.env.StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME;
-
-/**
- * A helper class to initialize the key vault secret client depending on which authentication method users choose. Then
- * add key vault as a property source to the environment.
- */
-class KeyVaultEnvironmentPostProcessorHelper {
-
- public static final String AZURE_KEYVAULT_PROPERTYSOURCE_NAME = "azurekv";
- public static final long DEFAULT_REFRESH_INTERVAL_MS = 1800000L;
- private static final Logger LOGGER = LoggerFactory.getLogger(KeyVaultEnvironmentPostProcessorHelper.class);
- private final ConfigurableEnvironment environment;
-
- KeyVaultEnvironmentPostProcessorHelper(final ConfigurableEnvironment environment) {
- this.environment = environment;
- Assert.notNull(environment, "environment must not be null!");
- }
-
- /**
- * Add a key vault property source.
- *
- *
- * The normalizedName is used to target a specific key vault (note if the name is the empty string it works as
- * before with only one key vault present). The normalized name is the name of the specific key vault plus a
- * trailing "." at the end.
- *
- *
- * @param normalizedName The normalized name.
- * @throws IllegalStateException If KeyVaultOperations fails to initialize.
- */
- public void addKeyVaultPropertySource(String normalizedName) {
- final String vaultUri = getPropertyValue(normalizedName, Property.URI);
- final String version = getPropertyValue(normalizedName, Property.SECRET_SERVICE_VERSION);
- SecretServiceVersion secretServiceVersion = Arrays.stream(SecretServiceVersion.values())
- .filter(val -> val.getVersion().equals(version))
- .findFirst()
- .orElse(null);
- Assert.notNull(vaultUri, "vaultUri must not be null!");
- final Long refreshInterval = Optional.ofNullable(getPropertyValue(normalizedName, Property.REFRESH_INTERVAL))
- .map(Long::valueOf)
- .orElse(DEFAULT_REFRESH_INTERVAL_MS);
- final List secretKeys = Binder.get(this.environment)
- .bind(
- KeyVaultProperties.getPropertyName(normalizedName, Property.SECRET_KEYS),
- Bindable.listOf(String.class)
- )
- .orElse(Collections.emptyList());
-
- final TokenCredential tokenCredential = getCredentials(normalizedName);
- final SecretClient secretClient = new SecretClientBuilder()
- .vaultUrl(vaultUri)
- .credential(tokenCredential)
- .serviceVersion(secretServiceVersion)
- .httpLogOptions(new HttpLogOptions().setApplicationId(AZURE_SPRING_KEY_VAULT + VERSION))
- .buildClient();
- try {
- final MutablePropertySources sources = this.environment.getPropertySources();
- final boolean caseSensitive = Boolean
- .parseBoolean(getPropertyValue(normalizedName, Property.CASE_SENSITIVE_KEYS));
- final KeyVaultOperation keyVaultOperation = new KeyVaultOperation(
- secretClient,
- refreshInterval,
- secretKeys,
- caseSensitive);
-
- String propertySourceName = Optional.of(normalizedName)
- .map(String::trim)
- .filter(s -> !s.isEmpty())
- .orElse(AZURE_KEYVAULT_PROPERTYSOURCE_NAME);
- KeyVaultPropertySource keyVaultPropertySource =
- new KeyVaultPropertySource(propertySourceName, keyVaultOperation);
- if (sources.contains(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)) {
- sources.addAfter(
- SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
- keyVaultPropertySource
- );
- } else {
- sources.addFirst(keyVaultPropertySource);
- }
-
- } catch (final Exception ex) {
- throw new IllegalStateException("Failed to configure KeyVault property source", ex);
- }
- }
-
- /**
- * Get the token credentials.
- *
- * @return the token credentials.
- */
- public TokenCredential getCredentials() {
- return getCredentials("");
- }
-
- /**
- * Get the token credentials.
- *
- * @param normalizedName the normalized name of the key vault.
- * @return the token credentials.
- */
- public TokenCredential getCredentials(String normalizedName) {
- //use service principle to authenticate
- final String clientId = getPropertyValue(normalizedName, Property.CLIENT_ID);
- final String clientSecret = Optional.ofNullable(getPropertyValue(normalizedName, Property.CLIENT_SECRET))
- .orElse(getPropertyValue(normalizedName, Property.CLIENT_KEY));
- final String tenantId = getPropertyValue(normalizedName, Property.TENANT_ID);
- final String certificatePath = getPropertyValue(normalizedName, Property.CERTIFICATE_PATH);
- final String certificatePassword = getPropertyValue(normalizedName, Property.CERTIFICATE_PASSWORD);
- final String authorityHost = Optional.ofNullable(getPropertyValue(normalizedName, Property.AUTHORITY_HOST))
- .orElse(AzureAuthorityHosts.AZURE_PUBLIC_CLOUD);
- if (clientId != null && tenantId != null && clientSecret != null) {
- LOGGER.debug("Will use custom credentials");
- return new ClientSecretCredentialBuilder()
- .clientId(clientId)
- .clientSecret(clientSecret)
- .tenantId(tenantId)
- .authorityHost(authorityHost)
- .build();
- }
- // Use certificate to authenticate
- // Password can be empty
- if (clientId != null && tenantId != null && certificatePath != null) {
- if (!StringUtils.hasText(certificatePassword)) {
- return new ClientCertificateCredentialBuilder()
- .tenantId(tenantId)
- .clientId(clientId)
- .pemCertificate(certificatePath)
- .authorityHost(authorityHost)
- .build();
- } else {
- return new ClientCertificateCredentialBuilder()
- .tenantId(tenantId)
- .clientId(clientId)
- .authorityHost(authorityHost)
- .pfxCertificate(certificatePath, certificatePassword)
- .build();
- }
- }
- //use MSI to authenticate
- if (clientId != null) {
- LOGGER.debug("Will use MSI credentials with specified clientId");
- return new ManagedIdentityCredentialBuilder().clientId(clientId).build();
- }
- LOGGER.debug("Will use MSI credentials");
- return new ManagedIdentityCredentialBuilder().build();
- }
-
- String getPropertyValue(final String normalizedName, final Property property) {
- List propertyNames = Arrays.asList(KeyVaultProperties.getPropertyName(normalizedName, property),
- AzureProperties.PREFIX + DELIMITER + property.getName());
-
- String propertyValue = null;
- for (String key : propertyNames) {
- propertyValue = environment.getProperty(key);
- if (null != propertyValue) {
- break;
- }
- }
- return propertyValue;
- }
-}
diff --git a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultOperation.java b/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultOperation.java
index 71fbf93b5771..33893b83a1a5 100644
--- a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultOperation.java
+++ b/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultOperation.java
@@ -14,6 +14,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.lang.NonNull;
+import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -31,10 +32,10 @@
*/
public class KeyVaultOperation {
- private static final Logger LOG = LoggerFactory.getLogger(KeyVaultOperation.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(KeyVaultOperation.class);
/**
- * Stores the case sensitive flag.
+ * Stores the case-sensitive flag.
*/
private final boolean caseSensitive;
@@ -60,16 +61,14 @@ public class KeyVaultOperation {
/**
* Constructor.
* @param secretClient the Key Vault secret client.
- * @param refreshInMillis the refresh in milliseconds (0 or less disables refresh).
+ * @param refreshDuration the refresh in milliseconds (0 or less disables refresh).
* @param secretKeys the secret keys to look for.
- * @param caseSensitive the case sensitive flag.
+ * @param caseSensitive the case-sensitive flag.
*/
- public KeyVaultOperation(
- final SecretClient secretClient,
- final long refreshInMillis,
- List secretKeys,
- boolean caseSensitive
- ) {
+ public KeyVaultOperation(final SecretClient secretClient,
+ final Duration refreshDuration,
+ List secretKeys,
+ boolean caseSensitive) {
this.caseSensitive = caseSensitive;
this.secretClient = secretClient;
@@ -77,6 +76,7 @@ public KeyVaultOperation(
refreshProperties();
+ final long refreshInMillis = refreshDuration.toMillis();
if (refreshInMillis > 0) {
synchronized (KeyVaultOperation.class) {
if (timer != null) {
@@ -84,7 +84,7 @@ public KeyVaultOperation(
timer.cancel();
timer.purge();
} catch (RuntimeException runtimeException) {
- LOG.error("Error of terminating Timer", runtimeException);
+ LOGGER.error("Error of terminating Timer", runtimeException);
}
}
timer = new Timer(true);
@@ -212,10 +212,10 @@ boolean isUp() {
} catch (HttpResponseException httpResponseException) {
result = httpResponseException.getResponse().getStatusCode() < 500;
} catch (HttpRequestException httpRequestException) {
- LOG.error("An HTTP error occurred while checking key vault connectivity", httpRequestException);
+ LOGGER.error("An HTTP error occurred while checking key vault connectivity", httpRequestException);
result = false;
} catch (RuntimeException runtimeException) {
- LOG.error("A runtime error occurred while checking key vault connectivity", runtimeException);
+ LOGGER.error("A runtime error occurred while checking key vault connectivity", runtimeException);
result = false;
}
return result;
diff --git a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultProperties.java b/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultProperties.java
deleted file mode 100644
index 133a6511d01f..000000000000
--- a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultProperties.java
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package com.azure.spring.keyvault;
-
-import com.azure.spring.autoconfigure.unity.AzureProperties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
-
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-/**
- * KeyVaultProperties
- */
-@ConfigurationProperties(value = KeyVaultProperties.PREFIX)
-public class KeyVaultProperties extends AzureProperties {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(KeyVaultProperties.class);
-
- public static final String PREFIX = "spring.cloud.azure.keyvault";
- public static final String DELIMITER = ".";
-
- public Boolean getEnabled() {
- return enabled;
- }
-
- public void setEnabled(Boolean enabled) {
- this.enabled = enabled;
- }
-
- public String getUri() {
- return uri;
- }
-
- public void setUri(String uri) {
- this.uri = uri;
- }
-
- public Long getRefreshInterval() {
- return refreshInterval;
- }
-
- public void setRefreshInterval(Long refreshInterval) {
- this.refreshInterval = refreshInterval;
- }
-
- public List getSecretKeys() {
- return secretKeys;
- }
-
- public void setSecretKeys(List secretKeys) {
- this.secretKeys = secretKeys;
- }
-
- public String getOrder() {
- return order;
- }
-
- public void setOrder(String order) {
- this.order = order;
- }
-
- public String getCaseSensitiveKeys() {
- return caseSensitiveKeys;
- }
-
- public void setCaseSensitiveKeys(String caseSensitiveKeys) {
- this.caseSensitiveKeys = caseSensitiveKeys;
- }
-
- @Deprecated
- @DeprecatedConfigurationProperty(
- reason = "Deprecate the telemetry endpoint and use HTTP header User Agent instead.")
- public String getAllowTelemetry() {
- return allowTelemetry;
- }
-
- public void setAllowTelemetry(String allowTelemetry) {
- this.allowTelemetry = allowTelemetry;
- }
-
- private Boolean enabled;
- private List secretKeys;
- private Long refreshInterval = KeyVaultEnvironmentPostProcessorHelper.DEFAULT_REFRESH_INTERVAL_MS;
- private String allowTelemetry;
- /**
- * Defines the constant for the property that enables/disables case sensitive keys.
- */
- private String caseSensitiveKeys;
-
- /**
- * The constant used to define the order of the key vaults you are
- * delivering (comma delimited, e.g 'my-vault, my-vault-2').
- */
- private String order;
-
- private String uri;
-
- /**
- * enum Property
- */
- public enum Property {
- AUTHORITY_HOST("environment.authority-host"),
- CLIENT_ID("credential.client-id"),
- CLIENT_SECRET("credential.client-secret"),
- CERTIFICATE_PATH("credential.client-certificate-path"),
- CERTIFICATE_PASSWORD("credential.client-certificate-password"),
- TENANT_ID("credential.tenant-id"),
- SECRET_SERVICE_VERSION("secret-service-version"),
- CASE_SENSITIVE_KEYS("case-sensitive-keys"),
- CLIENT_KEY("client-key"),
- ENABLED("enabled"),
- ORDER("order"),
- REFRESH_INTERVAL("refresh-interval"),
- SECRET_KEYS("secret-keys"),
- URI("uri");
-
- private final String name;
-
- String getName() {
- return name;
- }
-
- Property(String name) {
- this.name = name;
- }
- }
-
- public static String getPropertyName(Property property) {
- return String.join(DELIMITER, PREFIX, property.getName());
- }
-
- public static String getPropertyName(String normalizedName, Property property) {
- return Stream.of(PREFIX, normalizedName, property.getName())
- .map(String::trim)
- .filter(s -> !s.isEmpty())
- .collect(Collectors.joining(DELIMITER));
- }
-}
diff --git a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultPropertySource.java b/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultPropertySource.java
index a90fd5344d06..f79a3af1b62b 100644
--- a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultPropertySource.java
+++ b/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/KeyVaultPropertySource.java
@@ -5,7 +5,6 @@
import org.springframework.core.env.EnumerablePropertySource;
-import static com.azure.spring.keyvault.KeyVaultEnvironmentPostProcessorHelper.AZURE_KEYVAULT_PROPERTYSOURCE_NAME;
/**
* A key vault implementation of {@link EnumerablePropertySource} to enumerate all property pairs in Key Vault.
@@ -13,6 +12,7 @@
public class KeyVaultPropertySource extends EnumerablePropertySource {
private final KeyVaultOperation operations;
+ public static final String DEFAULT_AZURE_KEYVAULT_PROPERTYSOURCE_NAME = "azurekv";
public KeyVaultPropertySource(String keyVaultName, KeyVaultOperation operation) {
super(keyVaultName, operation);
@@ -20,7 +20,7 @@ public KeyVaultPropertySource(String keyVaultName, KeyVaultOperation operation)
}
public KeyVaultPropertySource(KeyVaultOperation operation) {
- super(AZURE_KEYVAULT_PROPERTYSOURCE_NAME, operation);
+ super(DEFAULT_AZURE_KEYVAULT_PROPERTYSOURCE_NAME, operation);
this.operations = operation;
}
diff --git a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/PostLegacyPropertyEnvironmentPostProcessor.java b/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/PostLegacyPropertyEnvironmentPostProcessor.java
deleted file mode 100644
index 8980d96adb01..000000000000
--- a/sdk/spring/azure-spring-cloud-autoconfigure/src/main/java/com/azure/spring/keyvault/PostLegacyPropertyEnvironmentPostProcessor.java
+++ /dev/null
@@ -1,110 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package com.azure.spring.keyvault;
-
-import com.azure.spring.autoconfigure.unity.AbstractLegacyPropertyEnvironmentPostProcessor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.core.env.ConfigurableEnvironment;
-import org.springframework.core.env.MutablePropertySources;
-import org.springframework.core.env.PropertiesPropertySource;
-import org.springframework.util.CollectionUtils;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.stream.Collectors;
-
-import static org.springframework.core.env.StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME;
-
-/**
- * Convert legacy properties in Key Vault property sources to the current and set into environment after
- * {@link KeyVaultEnvironmentPostProcessor}.
- *
- * Due to that properties in Key Vault has higher precedence than those in local, thus when comparing whether legacy
- * properties in Key Vault should be converted, they only need to be compared those in Key Vault.
- *
- * The converted current properties should have higher precedence than those in local, so the precedence is set
- * to be lower only than system properties, which is refered to the behavior of Key Vault property sources.
- */
-public class PostLegacyPropertyEnvironmentPostProcessor extends AbstractLegacyPropertyEnvironmentPostProcessor {
-
- public static final int DEFAULT_ORDER = KeyVaultEnvironmentPostProcessor.DEFAULT_ORDER + 1;
- private static final Logger LOGGER = LoggerFactory.getLogger(PostLegacyPropertyEnvironmentPostProcessor.class);
-
- @Override
- public int getOrder() {
- return DEFAULT_ORDER;
- }
-
- /**
- * When only legacy properties are detected from each key vault property source, convert legacy properties to
- * the current, and create a new {@link Properties} to store the converted current properties of each key vault
- * property source.
- *
- * @param environment The application environment to load property from.
- * @param legacyToCurrentMap A {@link Properties} contains a map of all legacy properties and associated current properties.
- * @return A {@link Properties} to store mapped current properties
- */
- @Override
- protected Properties convertLegacyToCurrent(ConfigurableEnvironment environment, Properties legacyToCurrentMap) {
- Properties convertedProperties = new Properties();
- List kvSourceList = environment.getPropertySources()
- .stream()
- .filter(KeyVaultPropertySource.class::isInstance)
- .map(KeyVaultPropertySource.class::cast)
- .collect(Collectors.toList());
- // Reverse traversal to keep the Key Vault property source of higher precedence could override the lower ones.
- Collections.reverse(kvSourceList);
- kvSourceList.forEach(source -> convertLegacyToCurrentInKvSource(source, legacyToCurrentMap, convertedProperties));
- return convertedProperties;
- }
-
- private void convertLegacyToCurrentInKvSource(KeyVaultPropertySource kvName, Properties legacyToCurrentMap,
- Properties convertedProperties) {
- for (Map.Entry