diff --git a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml index 5c60589f49efe..fe8185509e069 100755 --- a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml +++ b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml @@ -2306,6 +2306,12 @@ + + + + + + diff --git a/sdk/spring/azure-spring-boot-core/pom.xml b/sdk/spring/azure-spring-boot-core/pom.xml index e67cc75b6a86b..a36df473a4f02 100644 --- a/sdk/spring/azure-spring-boot-core/pom.xml +++ b/sdk/spring/azure-spring-boot-core/pom.xml @@ -19,6 +19,11 @@ Azure Spring Boot Core Library https://github.com/Azure/azure-sdk-for-java + + 0.10 + 0.10 + + org.springframework diff --git a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/ApplicationId.java b/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/ApplicationId.java index b594c0fba1613..9f220ab05db03 100644 --- a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/ApplicationId.java +++ b/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/ApplicationId.java @@ -41,7 +41,8 @@ public class ApplicationId { public static final String AZURE_SPRING_STORAGE_FILES = "az-sp-sf/"; public static final String AZURE_SPRING_STORAGE_QUEUE = "az-si-sq/"; - public static final String VERSION = Optional.of(SpringPropertyPrefix.class) + //TODO: version should contains each starter library's version + public static final String VERSION = Optional.of(ApplicationId.class) .map(Class::getPackage) .map(Package::getImplementationVersion) .orElse("unknown"); diff --git a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/SpringPropertyPrefix.java b/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/SpringPropertyPrefix.java deleted file mode 100644 index 9289476475ec6..0000000000000 --- a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/SpringPropertyPrefix.java +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.spring.core; - -/** - * Used internally. Constants in the Azure Spring Boot Core library. - */ -public class SpringPropertyPrefix { - - public static final String PREFIX = "spring.cloud.azure"; -} diff --git a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/Utils.java b/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/Utils.java deleted file mode 100644 index 86c2a8ba6c5b3..0000000000000 --- a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/Utils.java +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.spring.core; - -import com.azure.identity.AzureAuthorityHosts; - -/** - * Used internally. Constants in the Azure Spring Boot Core library. - */ -public class Utils { - - public static String toAuthorityHost(String azureEnvironment) { - switch (azureEnvironment) { - case "AzureChina": - return AzureAuthorityHosts.AZURE_CHINA; - case "AzureGermany": - return AzureAuthorityHosts.AZURE_GERMANY; - case "AzureUSGovernment": - return AzureAuthorityHosts.AZURE_GOVERNMENT; - default: - return AzureAuthorityHosts.AZURE_PUBLIC_CLOUD; - } - } -} diff --git a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/env/AzureEnvironment.java b/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/env/AzureEnvironment.java index 7f8a76ffd65c3..585060e7a1ecb 100644 --- a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/env/AzureEnvironment.java +++ b/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/env/AzureEnvironment.java @@ -1,3 +1,5 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.spring.core.env; import java.util.Arrays; diff --git a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/util/AzureCloudUrls.java b/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/util/AzureCloudUrls.java index 129cfafca8998..6ce11149849e3 100644 --- a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/util/AzureCloudUrls.java +++ b/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/util/AzureCloudUrls.java @@ -3,6 +3,8 @@ package com.azure.spring.core.util; +import com.azure.identity.AzureAuthorityHosts; + /** * Util class for Azure urls */ @@ -21,4 +23,17 @@ public static String getServiceManagementBaseUrl(String cloudType) { return cloudType.equals("Global") ? "https://management.azure.com/" : "https://management.chinacloudapi.cn/"; } + + public static String toAuthorityHost(String azureEnvironment) { + switch (azureEnvironment) { + case "AzureChina": + return AzureAuthorityHosts.AZURE_CHINA; + case "AzureGermany": + return AzureAuthorityHosts.AZURE_GERMANY; + case "AzureUSGovernment": + return AzureAuthorityHosts.AZURE_GOVERNMENT; + default: + return AzureAuthorityHosts.AZURE_PUBLIC_CLOUD; + } + } } diff --git a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/identity/SpringCredentialBuilderBase.java b/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/identity/SpringCredentialBuilderBase.java index 5ac9890da9430..503dacf70acec 100644 --- a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/identity/SpringCredentialBuilderBase.java +++ b/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/identity/SpringCredentialBuilderBase.java @@ -12,7 +12,7 @@ import java.util.Optional; -import static com.azure.spring.core.Utils.toAuthorityHost; +import static com.azure.spring.core.util.AzureCloudUrls.toAuthorityHost; /** * @@ -54,7 +54,7 @@ private TokenCredential populateTokenCredential(String prefix, boolean createDef .build(); } - String certPath = getPropertyValue(prefix + "client-certificate-path", null); + String certPath = getPropertyValue(prefix + "client-certificate-path"); if (tenantId != null && clientId != null && certPath != null) { return new ClientCertificateCredentialBuilder() @@ -77,11 +77,11 @@ protected ManagedIdentityCredential defaultManagedIdentityCredential() { } protected String getPropertyValue(String propertyName) { - return getPropertyValue(propertyName, null); + return environment.getProperty(propertyName); } protected String getPropertyValue(String propertyName, String defaultValue) { - return environment.getProperty(propertyName, defaultValue); + return environment.getProperty(propertyName, defaultValue); } protected String getAuthorityHost(String prefix) { diff --git a/sdk/spring/azure-spring-boot-starter-keyvault-secrets/CHANGELOG.md b/sdk/spring/azure-spring-boot-starter-keyvault-secrets/CHANGELOG.md index 8abb34dea50a2..8d0b36a8217a2 100644 --- a/sdk/spring/azure-spring-boot-starter-keyvault-secrets/CHANGELOG.md +++ b/sdk/spring/azure-spring-boot-starter-keyvault-secrets/CHANGELOG.md @@ -1,24 +1,6 @@ # Release History ## 3.7.0-beta.1 (Unreleased) -### New Features -- Support unified properties as below when the associated `azure.keyvault.*` properties are not configured.([#22396](https://github.com/Azure/azure-sdk-for-java/issues/22396)) - ``` - spring: - cloud: - azure: - client-id: - client-secret: - certificate-path: - certificate-password: - tenant-id: - authority-host: - environment: - ``` -### Breaking Changes -- Deprecate property of `azure.keyvault.client-key`, and provide `azure.keyvault.client-secret` instead. -- Property type of `spring.cloud.azure.environment` are changed from Enum to String. Supported values are "Azure", "AzureChina", "AzureGermany" and "AzureUSGovernment". -- Support alternative configuration of `azure.keyvault.authority-host` from `spring.cloud.azure.authority-host` or `spring.cloud.azure.environment`. ## 3.6.0 (2021-06-23) ### Breaking Changes diff --git a/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosActuatorIT.java b/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosActuatorIT.java index e17f80f515327..d1ce4a0fbeb90 100644 --- a/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosActuatorIT.java +++ b/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosActuatorIT.java @@ -19,10 +19,10 @@ public class CosmosActuatorIT { public void testCosmosSpringBootActuatorHealth() { try (AppRunner app = new AppRunner(DummyApp.class)) { //set properties - app.property("azure.cosmos.uri", AZURE_COSMOS_ENDPOINT); - app.property("azure.cosmos.key", AZURE_COSMOS_ACCOUNT_KEY); - app.property("azure.cosmos.database", AZURE_COSMOS_DATABASE_NAME); - app.property("azure.cosmos.populateQueryMetrics", String.valueOf(true)); + app.property("spring.cloud.azure.cosmos.uri", AZURE_COSMOS_ENDPOINT); + app.property("spring.cloud.azure.cosmos.key", AZURE_COSMOS_ACCOUNT_KEY); + app.property("spring.cloud.azure.cosmos.database", AZURE_COSMOS_DATABASE_NAME); + app.property("spring.cloud.azure.cosmos.populateQueryMetrics", String.valueOf(true)); app.property("management.endpoint.health.show-details", "always"); app.property("management.health.azure-cosmos.enabled", "true"); diff --git a/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosIT.java b/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosIT.java index 1f1eada24a57f..2705f41aa3b03 100644 --- a/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosIT.java +++ b/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosIT.java @@ -30,10 +30,10 @@ public class CosmosIT { public void testCosmosStarterIsolating() { try (AppRunner app = new AppRunner(DummyApp.class)) { //set properties - app.property("azure.cosmos.uri", AZURE_COSMOS_ENDPOINT); - app.property("azure.cosmos.key", AZURE_COSMOS_ACCOUNT_KEY); - app.property("azure.cosmos.database", AZURE_COSMOS_DATABASE_NAME); - app.property("azure.cosmos.populateQueryMetrics", String.valueOf(true)); + app.property("spring.cloud.azure.cosmos.uri", AZURE_COSMOS_ENDPOINT); + app.property("spring.cloud.azure.cosmos.key", AZURE_COSMOS_ACCOUNT_KEY); + app.property("spring.cloud.azure.cosmos.database", AZURE_COSMOS_DATABASE_NAME); + app.property("spring.cloud.azure.cosmos.populateQueryMetrics", String.valueOf(true)); //start app app.start(); @@ -46,10 +46,10 @@ public void testCosmosStarterIsolating() { public void testCosmosOperation() { try (AppRunner app = new AppRunner(DummyApp.class)) { //set properties - app.property("azure.cosmos.uri", AZURE_COSMOS_ENDPOINT); - app.property("azure.cosmos.key", AZURE_COSMOS_ACCOUNT_KEY); - app.property("azure.cosmos.database", AZURE_COSMOS_DATABASE_NAME); - app.property("azure.cosmos.populateQueryMetrics", String.valueOf(true)); + app.property("spring.cloud.azure.cosmos.uri", AZURE_COSMOS_ENDPOINT); + app.property("spring.cloud.azure.cosmos.key", AZURE_COSMOS_ACCOUNT_KEY); + app.property("spring.cloud.azure.cosmos.database", AZURE_COSMOS_DATABASE_NAME); + app.property("spring.cloud.azure.cosmos.populateQueryMetrics", String.valueOf(true)); //start app app.start(); diff --git a/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/spring/test/keyvault/KeyVaultActuatorIT.java b/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/spring/test/keyvault/KeyVaultActuatorIT.java index 7c92abfb6f984..c56e84d4c13e2 100644 --- a/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/spring/test/keyvault/KeyVaultActuatorIT.java +++ b/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/spring/test/keyvault/KeyVaultActuatorIT.java @@ -28,11 +28,11 @@ public class KeyVaultActuatorIT { public void testSpringBootActuatorHealth() { LOGGER.info("testSpringBootActuatorHealth begin."); try (AppRunner app = new AppRunner(DummyApp.class)) { - app.property("azure.keyvault.enabled", "true"); - app.property("azure.keyvault.uri", AZURE_KEYVAULT_URI); - app.property("azure.keyvault.client-id", SPRING_CLIENT_ID); - app.property("azure.keyvault.client-key", SPRING_CLIENT_SECRET); - app.property("azure.keyvault.tenant-id", SPRING_TENANT_ID); + app.property("spring.cloud.azure.keyvault.enabled", "true"); + app.property("spring.cloud.azure.keyvault.uri", AZURE_KEYVAULT_URI); + app.property("spring.cloud.azure.keyvault.credential.client-id", SPRING_CLIENT_ID); + app.property("spring.cloud.azure.keyvault.credential.client-secret", SPRING_CLIENT_SECRET); + app.property("spring.cloud.azure.keyvault.credential.tenant-id", SPRING_TENANT_ID); app.property("management.endpoint.health.show-details", "always"); app.property("management.endpoints.web.exposure.include", "*"); app.property("management.health.azure-key-vault.enabled", "true"); @@ -53,11 +53,11 @@ public void testSpringBootActuatorHealth() { public void testSpringBootActuatorEnv() { LOGGER.info("testSpringBootActuatorEnv begin."); try (AppRunner app = new AppRunner(DummyApp.class)) { - app.property("azure.keyvault.enabled", "true"); - app.property("azure.keyvault.uri", AZURE_KEYVAULT_URI); - app.property("azure.keyvault.client-id", SPRING_CLIENT_ID); - app.property("azure.keyvault.client-key", SPRING_CLIENT_SECRET); - app.property("azure.keyvault.tenant-id", SPRING_TENANT_ID); + app.property("spring.cloud.azure.keyvault.enabled", "true"); + app.property("spring.cloud.azure.keyvault.uri", AZURE_KEYVAULT_URI); + app.property("spring.cloud.azure.keyvault.credential.client-id", SPRING_CLIENT_ID); + app.property("spring.cloud.azure.keyvault.credential.client-secret", SPRING_CLIENT_SECRET); + app.property("spring.cloud.azure.keyvault.credential.tenant-id", SPRING_TENANT_ID); app.property("management.endpoint.health.show-details", "always"); app.property("management.endpoints.web.exposure.include", "*"); app.property("management.health.azure-key-vault.enabled", "true"); diff --git a/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/spring/test/keyvault/KeyVaultSecretValueIT.java b/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/spring/test/keyvault/KeyVaultSecretValueIT.java index bcaa3ba2da078..23b3a88e33847 100644 --- a/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/spring/test/keyvault/KeyVaultSecretValueIT.java +++ b/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/spring/test/keyvault/KeyVaultSecretValueIT.java @@ -75,11 +75,11 @@ private static TokenCredential credentials() { public void keyVaultAsPropertySource() { LOGGER.info("keyVaultAsPropertySource begin."); try (AppRunner app = new AppRunner(DummyApp.class)) { - app.property("azure.keyvault.enabled", "true"); - app.property("azure.keyvault.uri", AZURE_KEYVAULT_URI); - app.property("azure.keyvault.client-id", SPRING_CLIENT_ID); - app.property("azure.keyvault.client-key", SPRING_CLIENT_SECRET); - app.property("azure.keyvault.tenant-id", SPRING_TENANT_ID); + app.property("spring.cloud.azure.keyvault.enabled", "true"); + app.property("spring.cloud.azure.keyvault.uri", AZURE_KEYVAULT_URI); + app.property("spring.cloud.azure.keyvault.credential.client-id", SPRING_CLIENT_ID); + app.property("spring.cloud.azure.keyvault.credential.client-secret", SPRING_CLIENT_SECRET); + app.property("spring.cloud.azure.keyvault.credential.tenant-id", SPRING_TENANT_ID); LOGGER.info("app begin to start."); final ConfigurableApplicationContext dummy = app.start(); @@ -98,12 +98,12 @@ public void keyVaultAsPropertySource() { public void keyVaultAsPropertySourceWithSpecificKeys() { LOGGER.info("keyVaultAsPropertySourceWithSpecificKeys begin."); try (AppRunner app = new AppRunner(DummyApp.class)) { - app.property("azure.keyvault.enabled", "true"); - app.property("azure.keyvault.uri", AZURE_KEYVAULT_URI); - app.property("azure.keyvault.client-id", SPRING_CLIENT_ID); - app.property("azure.keyvault.client-key", SPRING_CLIENT_SECRET); - app.property("azure.keyvault.tenant-id", SPRING_TENANT_ID); - app.property("azure.keyvault.secret-keys", KEY_VAULT_SECRET_NAME); + app.property("spring.cloud.azure.keyvault.enabled", "true"); + app.property("spring.cloud.azure.keyvault.uri", AZURE_KEYVAULT_URI); + app.property("spring.cloud.azure.keyvault.credential.client-id", SPRING_CLIENT_ID); + app.property("spring.cloud.azure.keyvault.credential.client-secret", SPRING_CLIENT_SECRET); + app.property("spring.cloud.azure.keyvault.credential.tenant-id", SPRING_TENANT_ID); + app.property("spring.cloud.azure.keyvault.secret-keys", KEY_VAULT_SECRET_NAME); LOGGER.info("====" + KEY_VAULT_SECRET_NAME); app.start(); assertEquals(KEY_VAULT_SECRET_VALUE, app.getProperty(KEY_VAULT_SECRET_NAME)); diff --git a/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/spring/test/keyvault/MultipleKeyVaultsIT.java b/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/spring/test/keyvault/MultipleKeyVaultsIT.java index 215d4060e5e5f..d79d5e21179b9 100644 --- a/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/spring/test/keyvault/MultipleKeyVaultsIT.java +++ b/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/spring/test/keyvault/MultipleKeyVaultsIT.java @@ -37,12 +37,12 @@ private static String getKeyVaultName(String keyVaultUri) { @Test public void testGetValueFromKeyVault1() { try (AppRunner app = new AppRunner(TestApp.class)) { - app.property("azure.keyvault.order", KEY_VAULT_NAME_1); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".enabled", "true"); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".uri", AZURE_KEYVAULT_URI); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".client-id", SPRING_CLIENT_ID); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".client-key", SPRING_CLIENT_SECRET); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".tenant-id", SPRING_TENANT_ID); + app.property("spring.cloud.azure.keyvault.order", KEY_VAULT_NAME_1); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".enabled", "true"); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".uri", AZURE_KEYVAULT_URI); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".credential.client-id", SPRING_CLIENT_ID); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".credential.client-secret", SPRING_CLIENT_SECRET); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".credential.tenant-id", SPRING_TENANT_ID); app.start(); assertEquals(KEY_VAULT1_SECRET_VALUE, app.getProperty(KEY_VAULT1_SECRET_NAME)); } @@ -54,12 +54,12 @@ public void testGetValueFromKeyVault1() { @Test public void testGetValueFromKeyVault2() { try (AppRunner app = new AppRunner(TestApp.class)) { - app.property("azure.keyvault.order", KEY_VAULT_NAME_2); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".enabled", "true"); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".uri", AZURE_KEYVAULT2_URI); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".client-id", SPRING_CLIENT_ID); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".client-key", SPRING_CLIENT_SECRET); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".tenant-id", SPRING_TENANT_ID); + app.property("spring.cloud.azure.keyvault.order", KEY_VAULT_NAME_2); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".enabled", "true"); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".uri", AZURE_KEYVAULT2_URI); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".credential.client-id", SPRING_CLIENT_ID); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".credential.client-secret", SPRING_CLIENT_SECRET); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".credential.tenant-id", SPRING_TENANT_ID); app.start(); assertEquals(KEY_VAULT2_SECRET_VALUE, app.getProperty(KEY_VAULT2_SECRET_NAME)); } @@ -72,17 +72,17 @@ public void testGetValueFromKeyVault2() { @Test public void testGetValueForDuplicateKey() { try (AppRunner app = new AppRunner(TestApp.class)) { - app.property("azure.keyvault.order", String.join(",", KEY_VAULT_NAME_1, KEY_VAULT_NAME_2)); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".enabled", "true"); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".uri", AZURE_KEYVAULT_URI); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".client-id", SPRING_CLIENT_ID); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".client-key", SPRING_CLIENT_SECRET); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".tenant-id", SPRING_TENANT_ID); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".enabled", "true"); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".uri", AZURE_KEYVAULT2_URI); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".client-id", SPRING_CLIENT_ID); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".client-key", SPRING_CLIENT_SECRET); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".tenant-id", SPRING_TENANT_ID); + app.property("spring.cloud.azure.keyvault.order", String.join(",", KEY_VAULT_NAME_1, KEY_VAULT_NAME_2)); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".enabled", "true"); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".uri", AZURE_KEYVAULT_URI); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".credential.client-id", SPRING_CLIENT_ID); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".credential.client-secret", SPRING_CLIENT_SECRET); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".credential.tenant-id", SPRING_TENANT_ID); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".enabled", "true"); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".uri", AZURE_KEYVAULT2_URI); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".credential.client-id", SPRING_CLIENT_ID); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".credential.client-secret", SPRING_CLIENT_SECRET); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".credential.tenant-id", SPRING_TENANT_ID); app.start(); assertEquals(KEY_VAULT1_COMMON_SECRET_VALUE, app.getProperty(KEY_VAULT_COMMON_SECRET_NAME)); } @@ -94,17 +94,17 @@ public void testGetValueForDuplicateKey() { @Test public void testGetValueFromSingleVault() { try (AppRunner app = new AppRunner(TestApp.class)) { - app.property("azure.keyvault.order", String.join(",", KEY_VAULT_NAME_1, KEY_VAULT_NAME_2)); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".enabled", "true"); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".uri", AZURE_KEYVAULT_URI); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".client-id", SPRING_CLIENT_ID); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".client-key", SPRING_CLIENT_SECRET); - app.property("azure.keyvault." + KEY_VAULT_NAME_1 + ".tenant-id", SPRING_TENANT_ID); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".enabled", "true"); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".uri", AZURE_KEYVAULT2_URI); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".client-id", SPRING_CLIENT_ID); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".client-key", SPRING_CLIENT_SECRET); - app.property("azure.keyvault." + KEY_VAULT_NAME_2 + ".tenant-id", SPRING_TENANT_ID); + app.property("spring.cloud.azure.keyvault.order", String.join(",", KEY_VAULT_NAME_1, KEY_VAULT_NAME_2)); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".enabled", "true"); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".uri", AZURE_KEYVAULT_URI); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".credential.client-id", SPRING_CLIENT_ID); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".credential.client-secret", SPRING_CLIENT_SECRET); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_1 + ".credential.tenant-id", SPRING_TENANT_ID); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".enabled", "true"); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".uri", AZURE_KEYVAULT2_URI); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".credential.client-id", SPRING_CLIENT_ID); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".credential.client-secret", SPRING_CLIENT_SECRET); + app.property("spring.cloud.azure.keyvault." + KEY_VAULT_NAME_2 + ".credential.tenant-id", SPRING_TENANT_ID); app.start(); assertEquals(KEY_VAULT1_SECRET_VALUE, app.getProperty(KEY_VAULT1_SECRET_NAME)); assertEquals(KEY_VAULT2_SECRET_VALUE, app.getProperty(KEY_VAULT2_SECRET_NAME)); diff --git a/sdk/spring/azure-spring-boot-test-storage/src/test/java/com/microsoft/azure/test/storage/StorageActuatorIT.java b/sdk/spring/azure-spring-boot-test-storage/src/test/java/com/microsoft/azure/test/storage/StorageActuatorIT.java index 9fcc304c1aff3..7e566aac9f47b 100644 --- a/sdk/spring/azure-spring-boot-test-storage/src/test/java/com/microsoft/azure/test/storage/StorageActuatorIT.java +++ b/sdk/spring/azure-spring-boot-test-storage/src/test/java/com/microsoft/azure/test/storage/StorageActuatorIT.java @@ -22,9 +22,9 @@ public class StorageActuatorIT { public void testBlobStorageActuatorHealth() { try (AppRunner app = new AppRunner(DummyApp.class)) { //set properties - app.property("azure.storage.account-name", AZURE_STORAGE_ACCOUNT_NAME); - app.property("azure.storage.account-key", AZURE_STORAGE_ACCOUNT_KEY); - app.property("azure.storage.blob-endpoint", AZURE_STORAGE_BLOB_ENDPOINT); + app.property("spring.cloud.azure.storage.account-name", AZURE_STORAGE_ACCOUNT_NAME); + app.property("spring.cloud.azure.storage.account-key", AZURE_STORAGE_ACCOUNT_KEY); + app.property("spring.cloud.azure.storage.blob-endpoint", AZURE_STORAGE_BLOB_ENDPOINT); app.property("blob", AZURE_STORAGE_BLOB); app.property("management.endpoint.health.show-details", "always"); app.property("management.endpoints.web.exposure.include", "*"); @@ -49,9 +49,9 @@ public void testBlobStorageActuatorHealth() { public void testFileStorageActuatorHealth() { try (AppRunner app = new AppRunner(DummyApp.class)) { //set properties - app.property("azure.storage.account-name", AZURE_STORAGE_ACCOUNT_NAME); - app.property("azure.storage.account-key", AZURE_STORAGE_ACCOUNT_KEY); - app.property("azure.storage.file-endpoint", AZURE_STORAGE_FILE_ENDPOINT); + app.property("spring.cloud.azure.storage.account-name", AZURE_STORAGE_ACCOUNT_NAME); + app.property("spring.cloud.azure.storage.account-key", AZURE_STORAGE_ACCOUNT_KEY); + app.property("spring.cloud.azure.storage.file-endpoint", AZURE_STORAGE_FILE_ENDPOINT); app.property("file", AZURE_STORAGE_FILE); app.property("management.endpoint.health.show-details", "always"); //start app diff --git a/sdk/spring/azure-spring-boot-test-storage/src/test/resources/application.properties b/sdk/spring/azure-spring-boot-test-storage/src/test/resources/application.properties index 70a9c8b979054..5e29083279fab 100644 --- a/sdk/spring/azure-spring-boot-test-storage/src/test/resources/application.properties +++ b/sdk/spring/azure-spring-boot-test-storage/src/test/resources/application.properties @@ -1,6 +1,6 @@ -azure.storage.account-name=${AZURE_STORAGE_ACCOUNT_NAME} -azure.storage.account-key=${AZURE_STORAGE_ACCOUNT_KEY} -azure.storage.blob-endpoint=${AZURE_STORAGE_BLOB_ENDPOINT} -azure.storage.file-endpoint=${AZURE_STORAGE_FILE_ENDPOINT} +spring.cloud.azure.storage.account-name=${AZURE_STORAGE_ACCOUNT_NAME} +spring.cloud.azure.storage.account-key=${AZURE_STORAGE_ACCOUNT_KEY} +spring.cloud.azure.storage.blob-endpoint=${AZURE_STORAGE_BLOB_ENDPOINT} +spring.cloud.azure.storage.file-endpoint=${AZURE_STORAGE_FILE_ENDPOINT} blob=${AZURE_STORAGE_BLOB} file=${AZURE_STORAGE_FILE} diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterAutoConfiguration.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterAutoConfiguration.java index 8198c0677669c..179b8878665f9 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterAutoConfiguration.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterAutoConfiguration.java @@ -35,8 +35,8 @@ @ConditionalOnWebApplication @ConditionalOnResource(resources = "classpath:aad.enable.config") @ConditionalOnMissingClass({ "org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken" }) -@ConditionalOnExpression(value = "!'${azure.activedirectory.client-id:}'.empty || !'${spring.cloud.azure.client-id:}'.empty") -@EnableConfigurationProperties(AADAuthenticationProperties.class) +@ConditionalOnProperty(prefix = AADAuthenticationFilterAutoConfiguration.PROPERTY_PREFIX, value = { "client-id" }) +@EnableConfigurationProperties({ AADAuthenticationProperties.class }) public class AADAuthenticationFilterAutoConfiguration { public static final String PROPERTY_PREFIX = "azure.activedirectory"; private static final Logger LOG = LoggerFactory.getLogger(AADAuthenticationProperties.class); diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationProperties.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationProperties.java index 0bc24d43c74f0..1aa02a9d94c62 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationProperties.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationProperties.java @@ -42,14 +42,12 @@ public class AADAuthenticationProperties implements InitializingBean { private UserGroupProperties userGroup = new UserGroupProperties(); /** - * Registered application ID in Azure AD. - * A property of client-id must be configured when OAuth2 authentication is done in front end. + * Registered application ID in Azure AD. Must be configured when OAuth2 authentication is done in front end */ private String clientId; /** - * API Access Key of the registered application. - * A property of client-secret must be configured when OAuth2 authentication is done in front end. + * API Access Key of the registered application. Must be configured when OAuth2 authentication is done in front end */ private String clientSecret; diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/b2c/AADB2COAuth2AuthorizationCodeGrantRequestEntityConverter.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/b2c/AADB2COAuth2AuthorizationCodeGrantRequestEntityConverter.java index b343e0b46004e..27089dde1d41d 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/b2c/AADB2COAuth2AuthorizationCodeGrantRequestEntityConverter.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/b2c/AADB2COAuth2AuthorizationCodeGrantRequestEntityConverter.java @@ -3,8 +3,8 @@ package com.azure.spring.autoconfigure.b2c; -import com.azure.spring.core.ApplicationId; import com.azure.spring.aad.AbstractOAuth2AuthorizationCodeGrantRequestEntityConverter; +import com.azure.spring.core.ApplicationId; import org.springframework.http.RequestEntity; import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest; diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/cosmos/CosmosAutoConfiguration.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/cosmos/CosmosAutoConfiguration.java index e7bed2dde8f9a..4797b1dce4980 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/cosmos/CosmosAutoConfiguration.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/cosmos/CosmosAutoConfiguration.java @@ -7,11 +7,10 @@ import com.azure.cosmos.ConnectionMode; import com.azure.cosmos.CosmosAsyncClient; import com.azure.cosmos.CosmosClientBuilder; -import com.azure.spring.core.AzureProperties; +import com.azure.spring.autoconfigure.unity.AzureProperties; import com.azure.spring.data.cosmos.config.AbstractCosmosConfiguration; import com.azure.spring.data.cosmos.config.CosmosConfig; import com.azure.spring.data.cosmos.core.CosmosTemplate; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnResource; @@ -19,7 +18,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import static com.azure.spring.autoconfigure.unity.AzurePropertyAutoConfiguration.AZURE_PROPERTY_BEAN_NAME; +import static com.azure.spring.autoconfigure.unity.AzureProperties.AZURE_PROPERTY_BEAN_NAME; /** * Auto Configure Cosmos properties and connection policy. diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/cosmos/CosmosProperties.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/cosmos/CosmosProperties.java index 7d53acc181918..b1d916e29e0f2 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/cosmos/CosmosProperties.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/cosmos/CosmosProperties.java @@ -5,7 +5,7 @@ import com.azure.cosmos.ConnectionMode; import com.azure.cosmos.ConsistencyLevel; -import com.azure.spring.core.AzureProperties; +import com.azure.spring.autoconfigure.unity.AzureProperties; import com.azure.spring.data.cosmos.core.ResponseDiagnosticsProcessor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/AzureServiceBusJMSProperties.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/AzureServiceBusJMSProperties.java index 7bbee746f2612..581ad23e42fb7 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/AzureServiceBusJMSProperties.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/AzureServiceBusJMSProperties.java @@ -3,7 +3,7 @@ package com.azure.spring.autoconfigure.jms; -import com.azure.spring.core.AzureProperties; +import com.azure.spring.autoconfigure.unity.AzureProperties; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.util.StringUtils; @@ -18,7 +18,7 @@ @ConfigurationProperties(AzureServiceBusJMSProperties.PREFIX) public class AzureServiceBusJMSProperties extends AzureProperties { - public static final String PREFIX = "spring.cloud.azure.jms.servicebus"; + public static final String PREFIX = "spring.jms.servicebus"; private String connectionString; diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/NonPremiumServiceBusJMSAutoConfiguration.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/NonPremiumServiceBusJMSAutoConfiguration.java index ddcf7f8afc7b5..149963c7a614e 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/NonPremiumServiceBusJMSAutoConfiguration.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/NonPremiumServiceBusJMSAutoConfiguration.java @@ -3,7 +3,7 @@ package com.azure.spring.autoconfigure.jms; -import com.azure.spring.core.AzureProperties; +import com.azure.spring.autoconfigure.unity.AzureProperties; import org.apache.qpid.jms.JmsConnectionFactory; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -19,7 +19,7 @@ import javax.jms.ConnectionFactory; -import static com.azure.spring.autoconfigure.unity.AzurePropertyAutoConfiguration.AZURE_PROPERTY_BEAN_NAME; +import static com.azure.spring.autoconfigure.unity.AzureProperties.AZURE_PROPERTY_BEAN_NAME; /** * Automatic configuration class of ServiceBusJMS for Standard and Basic Service Bus @@ -27,8 +27,8 @@ @Configuration @ConditionalOnClass(JmsConnectionFactory.class) @ConditionalOnResource(resources = "classpath:servicebusjms.enable.config") -@ConditionalOnProperty(value = "spring.cloud.azure.jms.servicebus.enabled", matchIfMissing = true) -@ConditionalOnExpression(value = "not '${spring.cloud.azure.jms.servicebus.pricing-tier}'.equalsIgnoreCase('premium')") +@ConditionalOnProperty(value = "spring.jms.servicebus.enabled", matchIfMissing = true) +@ConditionalOnExpression(value = "not '${spring.jms.servicebus.pricing-tier}'.equalsIgnoreCase('premium')") @EnableConfigurationProperties(AzureServiceBusJMSProperties.class) public class NonPremiumServiceBusJMSAutoConfiguration { diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/PremiumServiceBusJMSAutoConfiguration.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/PremiumServiceBusJMSAutoConfiguration.java index 0dafc709d9f13..8f83e3de8f3f1 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/PremiumServiceBusJMSAutoConfiguration.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/PremiumServiceBusJMSAutoConfiguration.java @@ -3,7 +3,7 @@ package com.azure.spring.autoconfigure.jms; -import com.azure.spring.core.AzureProperties; +import com.azure.spring.autoconfigure.unity.AzureProperties; import com.microsoft.azure.servicebus.jms.ServiceBusJmsConnectionFactory; import com.microsoft.azure.servicebus.jms.ServiceBusJmsConnectionFactorySettings; import org.springframework.beans.factory.annotation.Qualifier; @@ -20,7 +20,7 @@ import javax.jms.ConnectionFactory; -import static com.azure.spring.autoconfigure.unity.AzurePropertyAutoConfiguration.AZURE_PROPERTY_BEAN_NAME; +import static com.azure.spring.autoconfigure.unity.AzureProperties.AZURE_PROPERTY_BEAN_NAME; import static com.azure.spring.core.ApplicationId.AZURE_SPRING_SERVICE_BUS; import static com.azure.spring.core.ApplicationId.VERSION; @@ -30,8 +30,8 @@ @Configuration @ConditionalOnClass(ServiceBusJmsConnectionFactory.class) @ConditionalOnResource(resources = "classpath:servicebusjms.enable.config") -@ConditionalOnProperty(value = "spring.cloud.azure.jms.servicebus.enabled", matchIfMissing = true) -@ConditionalOnExpression(value = "'${spring.cloud.azure.jms.servicebus.pricing-tier}'.equalsIgnoreCase('premium')") +@ConditionalOnProperty(value = "spring.jms.servicebus.enabled", matchIfMissing = true) +@ConditionalOnExpression(value = "'${spring.jms.servicebus.pricing-tier}'.equalsIgnoreCase('premium')") @EnableConfigurationProperties(AzureServiceBusJMSProperties.class) public class PremiumServiceBusJMSAutoConfiguration { diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/storage/StorageAutoConfiguration.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/storage/StorageAutoConfiguration.java index 041a3385d7663..e2f2b7e115fe7 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/storage/StorageAutoConfiguration.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/storage/StorageAutoConfiguration.java @@ -5,7 +5,7 @@ import com.azure.core.http.policy.HttpLogOptions; import com.azure.spring.autoconfigure.storage.resource.AzureStorageProtocolResolver; -import com.azure.spring.core.AzureProperties; +import com.azure.spring.autoconfigure.unity.AzureProperties; import com.azure.storage.blob.BlobServiceClientBuilder; import com.azure.storage.common.StorageSharedKeyCredential; import com.azure.storage.file.share.ShareServiceClientBuilder; @@ -19,7 +19,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import static com.azure.spring.autoconfigure.unity.AzurePropertyAutoConfiguration.AZURE_PROPERTY_BEAN_NAME; +import static com.azure.spring.autoconfigure.unity.AzureProperties.AZURE_PROPERTY_BEAN_NAME; import static com.azure.spring.core.ApplicationId.AZURE_SPRING_STORAGE_BLOB; import static com.azure.spring.core.ApplicationId.AZURE_SPRING_STORAGE_FILES; import static com.azure.spring.core.ApplicationId.VERSION; diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/storage/StorageProperties.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/storage/StorageProperties.java index ffd5db6b48788..76b95cc9ea9f0 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/storage/StorageProperties.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/storage/StorageProperties.java @@ -3,7 +3,7 @@ package com.azure.spring.autoconfigure.storage; -import com.azure.spring.core.AzureProperties; +import com.azure.spring.autoconfigure.unity.AzureProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.annotation.Validated; diff --git a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/AzureProperties.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/AzureProperties.java similarity index 52% rename from sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/AzureProperties.java rename to sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/AzureProperties.java index b2bdb90ab061b..65731c0a33f73 100644 --- a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/AzureProperties.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/AzureProperties.java @@ -1,24 +1,27 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.spring.core; +package com.azure.spring.autoconfigure.unity; /** * Unified properties for Azure SDK clients. */ public class AzureProperties { + public static final String AZURE_PROPERTY_BEAN_NAME = "azureProperties"; - private CredentialProperties credentialProperties; + public static final String PREFIX = "spring.cloud.azure"; + + private CredentialProperties credential; private EnvironmentProperties environment; - public CredentialProperties getCredentialProperties() { - return credentialProperties; + public CredentialProperties getCredential() { + return credential; } - public void setCredentialProperties(CredentialProperties credentialProperties) { - this.credentialProperties = credentialProperties; + public void setCredential(CredentialProperties credential) { + this.credential = credential; } public EnvironmentProperties getEnvironment() { diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/AzurePropertyAutoConfiguration.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/AzurePropertyAutoConfiguration.java index 04e84ba7a7759..321639a3078be 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/AzurePropertyAutoConfiguration.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/AzurePropertyAutoConfiguration.java @@ -3,13 +3,10 @@ package com.azure.spring.autoconfigure.unity; -import com.azure.spring.core.AzureProperties; -import com.azure.spring.core.SpringPropertyPrefix; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.boot.context.properties.bind.Binder; import org.springframework.context.EnvironmentAware; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.env.Environment; @@ -18,7 +15,6 @@ /** * Automatic configuration class of {@link AzureProperties} for unified configuration of Azure Spring libraries. */ -@Configuration @Import(AzurePropertyAutoConfiguration.Registrar.class) public class AzurePropertyAutoConfiguration { @@ -35,13 +31,13 @@ public void setEnvironment(Environment environment) { @Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { - Binder.get(this.environment).bind(SpringPropertyPrefix.PREFIX, AzureProperties.class); if (!registry.containsBeanDefinition(AZURE_PROPERTY_BEAN_NAME)) { registry.registerBeanDefinition(AZURE_PROPERTY_BEAN_NAME, - BeanDefinitionBuilder.genericBeanDefinition(AzureProperties.class).getBeanDefinition()); + BeanDefinitionBuilder.genericBeanDefinition(AzureProperties.class, + () -> Binder.get(this.environment).bindOrCreate(AzureProperties.PREFIX, + AzureProperties.class)).getBeanDefinition()); } } } - } diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/AzurePropertyEnvironmentPostProcessor.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/AzurePropertyEnvironmentPostProcessor.java index d6a30160259f8..451d09a553a3b 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/AzurePropertyEnvironmentPostProcessor.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/AzurePropertyEnvironmentPostProcessor.java @@ -37,9 +37,9 @@ public class AzurePropertyEnvironmentPostProcessor { private static final String LEGACY_STORAGE_PREFIX = "azure.storage"; private static final String LEGACY_KEYVAULT_PREFIX = "azure.keyvault"; - private final Logger LOGGER = LoggerFactory.getLogger(AzurePropertyEnvironmentPostProcessor.class); + private static final Logger LOGGER = LoggerFactory.getLogger(AzurePropertyEnvironmentPostProcessor.class); - private static final Map LEGACY_TO_CURRENT = new HashMap<>() { + private static final Map LEGACY_TO_CURRENT = new HashMap() { { put(LEGACY_AAD_PREFIX + ".clientId", AADAuthenticationProperties.PREFIX + ".credential.clientId"); put(LEGACY_AAD_PREFIX + ".clientSecret", AADAuthenticationProperties.PREFIX + ".credential.clientSecret"); @@ -52,27 +52,27 @@ public class AzurePropertyEnvironmentPostProcessor { + ".allowedGroupIds"); put(LEGACY_AAD_PREFIX + ".userGroup.enableFullList", AADAuthenticationProperties.PREFIX + ".userGroup" + ".enableFullList"); - put(LEGACY_AAD_PREFIX + ".userNameAttribute", AADAuthenticationProperties.PREFIX + - ".userNameAttribute"); - put(LEGACY_AAD_PREFIX + ".redirectUriTemplate", AADAuthenticationProperties.PREFIX + - ".redirectUriTemplate"); + put(LEGACY_AAD_PREFIX + ".userNameAttribute", AADAuthenticationProperties.PREFIX + + ".userNameAttribute"); + put(LEGACY_AAD_PREFIX + ".redirectUriTemplate", AADAuthenticationProperties.PREFIX + + ".redirectUriTemplate"); put(LEGACY_AAD_PREFIX + ".appIdUri", AADAuthenticationProperties.PREFIX + ".appIdUri"); put(LEGACY_AAD_PREFIX + ".authenticateAdditionalParameters", AADAuthenticationProperties.PREFIX + ".authenticateAdditionalParameters"); put(LEGACY_AAD_PREFIX + ".jwtConnectTimeout", AADAuthenticationProperties.PREFIX + ".jwtConnectTimeout"); put(LEGACY_AAD_PREFIX + ".jwtReadTimeout", AADAuthenticationProperties.PREFIX + ".jwtReadTimeout"); put(LEGACY_AAD_PREFIX + ".jwtSizeLimit", AADAuthenticationProperties.PREFIX + ".jwtSizeLimit"); - put(LEGACY_AAD_PREFIX + ".jwkSetCacheLifespan", AADAuthenticationProperties.PREFIX + - ".jwkSetCacheLifespan"); - put(LEGACY_AAD_PREFIX + ".jwkSetCacheRefreshTime", AADAuthenticationProperties.PREFIX + - ".jwkSetCacheRefreshTime"); - put(LEGACY_AAD_PREFIX + ".postLogoutRedirectUri", AADAuthenticationProperties.PREFIX + - ".postLogoutRedirectUri"); + put(LEGACY_AAD_PREFIX + ".jwkSetCacheLifespan", AADAuthenticationProperties.PREFIX + + ".jwkSetCacheLifespan"); + put(LEGACY_AAD_PREFIX + ".jwkSetCacheRefreshTime", AADAuthenticationProperties.PREFIX + + ".jwkSetCacheRefreshTime"); + put(LEGACY_AAD_PREFIX + ".postLogoutRedirectUri", AADAuthenticationProperties.PREFIX + + ".postLogoutRedirectUri"); put(LEGACY_AAD_PREFIX + ".allowTelemetry", AADAuthenticationProperties.PREFIX + ".allowTelemetry"); put(LEGACY_AAD_PREFIX + ".sessionStateless", AADAuthenticationProperties.PREFIX + ".sessionStateless"); put(LEGACY_AAD_PREFIX + ".graphMembershipUri", AADAuthenticationProperties.PREFIX + ".graphMembershipUri"); - put(LEGACY_AAD_PREFIX + ".authorizationClients", AADAuthenticationProperties.PREFIX + - ".authorizationClients"); + put(LEGACY_AAD_PREFIX + ".authorizationClients", AADAuthenticationProperties.PREFIX + + ".authorizationClients"); put(LEGACY_AAD_B2C_PREFIX + ".clientId", AADB2CProperties.PREFIX + ".credential.clientId"); put(LEGACY_AAD_B2C_PREFIX + ".clientSecret", AADB2CProperties.PREFIX + ".credential.clientSecret"); @@ -84,8 +84,8 @@ public class AzurePropertyEnvironmentPostProcessor { put(LEGACY_AAD_B2C_PREFIX + ".jwtReadTimeout", AADB2CProperties.PREFIX + ".jwtReadTimeout"); put(LEGACY_AAD_B2C_PREFIX + ".jwtSizeLimit", AADB2CProperties.PREFIX + ".jwtSizeLimit"); put(LEGACY_AAD_B2C_PREFIX + ".logoutSuccessUrl", AADB2CProperties.PREFIX + ".logoutSuccessUrl"); - put(LEGACY_AAD_B2C_PREFIX + ".authenticateAdditionalParameters", AADB2CProperties.PREFIX + - ".authenticateAdditionalParameters"); + put(LEGACY_AAD_B2C_PREFIX + ".authenticateAdditionalParameters", AADB2CProperties.PREFIX + + ".authenticateAdditionalParameters"); put(LEGACY_AAD_B2C_PREFIX + ".userNameAttributeName", AADB2CProperties.PREFIX + ".userNameAttributeName"); put(LEGACY_AAD_B2C_PREFIX + ".allowTelemetry", AADB2CProperties.PREFIX + ".allowTelemetry"); put(LEGACY_AAD_B2C_PREFIX + ".replyUrl", AADB2CProperties.PREFIX + ".replyUrl"); @@ -101,8 +101,8 @@ public class AzurePropertyEnvironmentPostProcessor { put(LEGACY_COSMOS_PREFIX + ".populateQueryMetrics", CosmosProperties.PREFIX + ".populateQueryMetrics"); put(LEGACY_COSMOS_PREFIX + ".allowTelemetry", CosmosProperties.PREFIX + ".allowTelemetry"); put(LEGACY_COSMOS_PREFIX + ".connectionMode", CosmosProperties.PREFIX + ".connectionMode"); - put(LEGACY_COSMOS_PREFIX + ".responseDiagnosticsProcessor", CosmosProperties.PREFIX + - ".responseDiagnosticsProcessor"); + put(LEGACY_COSMOS_PREFIX + ".responseDiagnosticsProcessor", CosmosProperties.PREFIX + + ".responseDiagnosticsProcessor"); put(LEGACY_JMS_PREFIX + ".connectionString", AzureServiceBusJMSProperties.PREFIX + ".connectionString"); put(LEGACY_JMS_PREFIX + ".topicClientId", AzureServiceBusJMSProperties.PREFIX + ".topicClientId"); @@ -152,7 +152,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp .orElse(null); if (null != value) { properties.put(e.getValue(), value); - LOGGER.info( e.getKey() + " property detected! Use the {} instead!", e.getValue()); + LOGGER.info(e.getKey() + " property detected! Use the {} instead!", e.getValue()); } } diff --git a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/CredentialProperties.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/CredentialProperties.java similarity index 85% rename from sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/CredentialProperties.java rename to sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/CredentialProperties.java index 4f8d33cb3124d..8f56208c3120e 100644 --- a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/CredentialProperties.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/CredentialProperties.java @@ -1,17 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.spring.core; +package com.azure.spring.autoconfigure.unity; /** * Azure properties used for getting token credential. */ public class CredentialProperties { - /** - * The Azure Active Directory endpoint to connect to. - */ - private String authorityHost; /** * Client id to use when performing service principal authentication with Azure. @@ -43,14 +39,6 @@ public class CredentialProperties { */ private String tenantId; - public String getAuthorityHost() { - return authorityHost; - } - - public void setAuthorityHost(String authorityHost) { - this.authorityHost = authorityHost; - } - public String getClientId() { return clientId; } diff --git a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/EnvironmentProperties.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/EnvironmentProperties.java similarity index 94% rename from sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/EnvironmentProperties.java rename to sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/EnvironmentProperties.java index adb49f40db000..606b51f2d38bd 100644 --- a/sdk/spring/azure-spring-boot-core/src/main/java/com/azure/spring/core/EnvironmentProperties.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/EnvironmentProperties.java @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.spring.core; +package com.azure.spring.autoconfigure.unity; /** * Environment properties for endpoints in different Azure Clouds. diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/package-info.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/package-info.java new file mode 100644 index 0000000000000..9e0fcef114317 --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/unity/package-info.java @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +/** + * Package com.azure.spring.autoconfigure.unity; + */ +package com.azure.spring.autoconfigure.unity; diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessorHelper.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessorHelper.java index 082b3500b7fd4..da92c89d2be76 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessorHelper.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessorHelper.java @@ -5,17 +5,16 @@ 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.identity.implementation.IdentityClientOptions; 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.core.SpringPropertyPrefix; +import com.azure.spring.autoconfigure.unity.AzureProperties; import com.azure.spring.keyvault.KeyVaultProperties.Property; -import java.util.HashSet; -import java.util.Set; +import com.google.common.annotations.VisibleForTesting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.context.properties.bind.Bindable; @@ -32,6 +31,7 @@ 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; /** @@ -43,7 +43,6 @@ 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 static final String DEFAULT_AUTHORITY_HOST = new IdentityClientOptions().getAuthorityHost(); private final ConfigurableEnvironment environment; KeyVaultEnvironmentPostProcessorHelper(final ConfigurableEnvironment environment) { @@ -142,9 +141,7 @@ public TokenCredential getCredentials(String normalizedName) { 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(Optional.of(SpringPropertyPrefix.PREFIX + "environment") - .map(environment::getProperty) - .orElse(DEFAULT_AUTHORITY_HOST)); + .orElse(AzureAuthorityHosts.AZURE_PUBLIC_CLOUD); if (clientId != null && tenantId != null && clientSecret != null) { LOGGER.debug("Will use custom credentials"); return new ClientSecretCredentialBuilder() @@ -182,12 +179,13 @@ public TokenCredential getCredentials(String normalizedName) { return new ManagedIdentityCredentialBuilder().build(); } - private String getPropertyValue(final String normalizedName, final Property property) { + @VisibleForTesting + String getPropertyValue(final String normalizedName, final Property property) { List propertyNames = Arrays.asList(KeyVaultProperties.getPropertyName(normalizedName, property), - SpringPropertyPrefix.PREFIX + property.getName()); + AzureProperties.PREFIX + DELIMITER + property.getName()); String propertyValue = null; - for(String key : propertyNames) { + for (String key : propertyNames) { propertyValue = environment.getProperty(key); if (null != propertyValue) { break; diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/keyvault/KeyVaultProperties.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/keyvault/KeyVaultProperties.java index d10027adb92e3..944e730fa8ba5 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/keyvault/KeyVaultProperties.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/keyvault/KeyVaultProperties.java @@ -3,7 +3,7 @@ package com.azure.spring.keyvault; -import com.azure.spring.core.AzureProperties; +import com.azure.spring.autoconfigure.unity.AzureProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterPropertiesTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterPropertiesTest.java index 263547db2a55a..7b89407b2f230 100644 --- a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterPropertiesTest.java +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterPropertiesTest.java @@ -4,7 +4,7 @@ package com.azure.spring.autoconfigure.aad; import com.azure.identity.AzureAuthorityHosts; -import com.azure.spring.core.SpringPropertyPrefix; +import com.azure.spring.autoconfigure.unity.AzureProperties; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -39,7 +39,6 @@ public void canSetProperties() { assertThat(properties.getClientId()).isEqualTo(TestConstants.CLIENT_ID); assertThat(properties.getClientSecret()).isEqualTo(TestConstants.CLIENT_SECRET); - assertThat(properties.getBaseUri()).isEqualTo(AzureAuthorityHosts.AZURE_PUBLIC_CLOUD); assertThat(properties.getActiveDirectoryGroups() .toString()).isEqualTo(TestConstants.TARGETED_GROUPS.toString()); } @@ -52,10 +51,10 @@ public void loadPropertiesFromCredentialProperties() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); addInlinedPropertiesToEnvironment( context, - SpringPropertyPrefix.PREFIX + ".tenant-id=azure-tenant-id", - SpringPropertyPrefix.PREFIX + ".client-id=azure-client-id", - SpringPropertyPrefix.PREFIX + ".authority-host=azure-authority-host", - SpringPropertyPrefix.PREFIX + ".environment=AzureGermany", + AzureProperties.PREFIX + ".tenant-id=azure-tenant-id", + AzureProperties.PREFIX + ".client-id=azure-client-id", + AzureProperties.PREFIX + ".authority-host=azure-authority-host", + AzureProperties.PREFIX + ".environment=AzureGermany", AAD_PROPERTY_PREFIX + "client-id=" + TestConstants.CLIENT_ID, AAD_PROPERTY_PREFIX + "client-secret=" + TestConstants.CLIENT_SECRET ); @@ -77,7 +76,7 @@ public void testGetBaseUriFromEnvironment() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); addInlinedPropertiesToEnvironment( context, - SpringPropertyPrefix.PREFIX + ".environment=AzureGermany", + AzureProperties.PREFIX + ".environment=AzureGermany", AAD_PROPERTY_PREFIX + "tenant-id=azure-tenant-id", AAD_PROPERTY_PREFIX + "client-id=" + TestConstants.CLIENT_ID, AAD_PROPERTY_PREFIX + "client-secret=" + TestConstants.CLIENT_SECRET diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterTest.java index e747652907d4c..bac88ff2d76e2 100644 --- a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterTest.java +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterTest.java @@ -8,7 +8,6 @@ import com.nimbusds.jose.proc.BadJOSEException; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; @@ -34,7 +33,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class AADAuthenticationFilterTest { private static final String TOKEN = "dummy-token"; private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() @@ -136,6 +134,7 @@ public void testAlreadyAuthenticated() throws ServletException, IOException, Par } @Test + @Disabled public void testAADAuthenticationFilterAutoConfiguration() { this.contextRunner.withPropertyValues( diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/b2c/AADB2CAutoConfigurationTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/b2c/AADB2CAutoConfigurationTest.java index 102223a2c7c2a..97d46694e750f 100644 --- a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/b2c/AADB2CAutoConfigurationTest.java +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/b2c/AADB2CAutoConfigurationTest.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. package com.azure.spring.autoconfigure.b2c; -import com.azure.spring.core.CredentialProperties; +import com.azure.spring.autoconfigure.unity.CredentialProperties; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/cosmos/CosmosAutoConfigurationTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/cosmos/CosmosAutoConfigurationTest.java index 876e4eea683af..3c4857145b69b 100644 --- a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/cosmos/CosmosAutoConfigurationTest.java +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/cosmos/CosmosAutoConfigurationTest.java @@ -6,7 +6,7 @@ import com.azure.cosmos.CosmosAsyncClient; import com.azure.cosmos.CosmosClientBuilder; import com.azure.spring.autoconfigure.unity.AzurePropertyAutoConfiguration; -import com.azure.spring.core.AzureProperties; +import com.azure.spring.autoconfigure.unity.AzureProperties; import com.azure.spring.data.cosmos.config.CosmosConfig; import com.azure.spring.data.cosmos.core.CosmosTemplate; import org.junit.jupiter.api.Test; @@ -17,11 +17,14 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; +import static com.azure.spring.autoconfigure.cosmos.PropertySettingUtil.CLOUD; import static com.azure.spring.autoconfigure.cosmos.PropertySettingUtil.DATABASE_NAME; import static com.azure.spring.autoconfigure.cosmos.PropertySettingUtil.KEY; +import static com.azure.spring.autoconfigure.cosmos.PropertySettingUtil.MSI_ENABLED; import static com.azure.spring.autoconfigure.cosmos.PropertySettingUtil.URI; -import static com.azure.spring.autoconfigure.cosmos.PropertySettingUtil.getCommonPropertyValues; -import static com.azure.spring.autoconfigure.unity.AzurePropertyAutoConfiguration.AZURE_PROPERTY_BEAN_NAME; +import static com.azure.spring.autoconfigure.cosmos.PropertySettingUtil.getCosmosPropertyValues; +import static com.azure.spring.autoconfigure.cosmos.PropertySettingUtil.getUnifiedPropertyValues; +import static com.azure.spring.autoconfigure.unity.AzureProperties.AZURE_PROPERTY_BEAN_NAME; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -52,7 +55,8 @@ public void testCosmosAutoConfigurationWithoutConditionalOnClass() { @Test public void testCosmosAutoConfigurationBean() { this.contextRunner - .withPropertyValues(getCommonPropertyValues()) + .withPropertyValues(getCosmosPropertyValues()) + .withPropertyValues(getUnifiedPropertyValues()) .withConfiguration(AutoConfigurations.of(ConfigurationWithMockCosmosAsyncClient.class, AzurePropertyAutoConfiguration.class)) .run((context) -> { assertThat(context).hasSingleBean(CosmosAsyncClient.class); @@ -60,11 +64,16 @@ public void testCosmosAutoConfigurationBean() { assertThat(context).hasSingleBean(AzureKeyCredential.class); assertThat(context).hasSingleBean(CosmosClientBuilder.class); assertThat(context).hasSingleBean(CosmosConfig.class); + assertThat(context).hasBean(AZURE_PROPERTY_BEAN_NAME); CosmosProperties cosmosProperties = context.getBean(CosmosProperties.class); assertThat(cosmosProperties.getUri()).isEqualTo(URI); assertThat(cosmosProperties.getKey()).isEqualTo(KEY); assertThat(cosmosProperties.getDatabase()).isEqualTo(DATABASE_NAME); + + AzureProperties azureProperties = (AzureProperties) context.getBean(AZURE_PROPERTY_BEAN_NAME); + assertThat(azureProperties.getCredential().isMsiEnabled()).isEqualTo(MSI_ENABLED); + assertThat(azureProperties.getEnvironment().getCloud()).isEqualTo(CLOUD); }); } diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/cosmos/CosmosPropertiesTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/cosmos/CosmosPropertiesTest.java index d875d7357a474..bb63824fdc2d1 100644 --- a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/cosmos/CosmosPropertiesTest.java +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/cosmos/CosmosPropertiesTest.java @@ -24,7 +24,7 @@ public class CosmosPropertiesTest { @Test - public void canSetAllProperties() { + public void canSetProperties() { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { configureCosmosProperties(context); context.register(Config.class); @@ -36,6 +36,8 @@ public void canSetAllProperties() { assertThat(properties.getConsistencyLevel()).isEqualTo(PropertySettingUtil.CONSISTENCY_LEVEL); assertThat(properties.isPopulateQueryMetrics()).isEqualTo(PropertySettingUtil.POPULATE_QUERY_METRICS); assertThat(properties.getConnectionMode()).isEqualTo(PropertySettingUtil.CONNECTION_MODE); + assertThat(properties.getCredential().isMsiEnabled()).isEqualTo(PropertySettingUtil.MSI_ENABLED); + assertThat(properties.getEnvironment().getCloud()).isEqualTo(PropertySettingUtil.CLOUD); } } diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/cosmos/PropertySettingUtil.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/cosmos/PropertySettingUtil.java index 9cfd4a635d566..9cc6f68368cb1 100644 --- a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/cosmos/PropertySettingUtil.java +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/cosmos/PropertySettingUtil.java @@ -15,12 +15,18 @@ public class PropertySettingUtil { public static final boolean POPULATE_QUERY_METRICS = true; public static final ConsistencyLevel CONSISTENCY_LEVEL = ConsistencyLevel.STRONG; public static final ConnectionMode CONNECTION_MODE = ConnectionMode.DIRECT; + public static final boolean MSI_ENABLED = true; + public static final String CLOUD = "AzureChina"; public static final String PROPERTY_URI = "spring.cloud.azure.cosmos.uri"; public static final String PROPERTY_KEY = "spring.cloud.azure.cosmos.key"; public static final String PROPERTY_DBNAME = "spring.cloud.azure.cosmos.database"; public static final String PROPERTY_CONSISTENCY_LEVEL = "spring.cloud.azure.cosmos.consistency-level"; public static final String PROPERTY_POPULATE_QUERY_METRICS = "spring.cloud.azure.cosmos.populateQueryMetrics"; public static final String PROPERTY_CONNECTION_MODE = "spring.cloud.azure.cosmos.connection-mode"; + public static final String PROPERTY_MSI_ENABLED = "spring.cloud.azure.cosmos.credential.msi-enabled"; + public static final String PROPERTY_CLOUD = "spring.cloud.azure.cosmos.environment.cloud"; + public static final String PROPERTY_UNIFIED_MSI_ENABLED = "spring.cloud.azure.credential.msi-enabled"; + public static final String PROPERTY_UNIFIED_CLOUD = "spring.cloud.azure.environment.cloud"; public static void configureCosmosProperties(AnnotationConfigApplicationContext context) { addInlinedPropertiesToEnvironment( @@ -30,11 +36,13 @@ public static void configureCosmosProperties(AnnotationConfigApplicationContext PROPERTY_DBNAME + "=" + DATABASE_NAME, PROPERTY_CONSISTENCY_LEVEL + "=" + CONSISTENCY_LEVEL.name(), PROPERTY_POPULATE_QUERY_METRICS + "=" + POPULATE_QUERY_METRICS, - PROPERTY_CONNECTION_MODE + "=" + CONNECTION_MODE.name() + PROPERTY_CONNECTION_MODE + "=" + CONNECTION_MODE.name(), + PROPERTY_MSI_ENABLED + "=" + MSI_ENABLED, + PROPERTY_CLOUD + "=" + CLOUD ); } - public static String[] getCommonPropertyValues() { + public static String[] getCosmosPropertyValues() { return new String[] { PROPERTY_URI + "=" + URI, PROPERTY_KEY + "=" + KEY, PROPERTY_DBNAME + "=" + DATABASE_NAME, @@ -43,4 +51,10 @@ public static String[] getCommonPropertyValues() { PROPERTY_CONNECTION_MODE + "=" + CONNECTION_MODE.name() }; } + + public static String[] getUnifiedPropertyValues() { + return new String[] { PROPERTY_UNIFIED_MSI_ENABLED + "=" + MSI_ENABLED, + PROPERTY_UNIFIED_CLOUD + "=" + CLOUD + }; + } } diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/jms/NonPremiumServiceBusJMSAutoConfigurationTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/jms/NonPremiumServiceBusJMSAutoConfigurationTest.java index 325b96cd974c0..2261959558efe 100644 --- a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/jms/NonPremiumServiceBusJMSAutoConfigurationTest.java +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/jms/NonPremiumServiceBusJMSAutoConfigurationTest.java @@ -4,6 +4,7 @@ package com.azure.spring.autoconfigure.jms; import com.azure.spring.autoconfigure.unity.AzurePropertyAutoConfiguration; +import com.azure.spring.autoconfigure.unity.AzureProperties; import org.apache.qpid.jms.JmsConnectionFactory; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -15,6 +16,7 @@ import javax.jms.ConnectionFactory; +import static com.azure.spring.autoconfigure.unity.AzureProperties.AZURE_PROPERTY_BEAN_NAME; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -26,13 +28,13 @@ public class NonPremiumServiceBusJMSAutoConfigurationTest { @Test public void testAzureServiceBusNonPremiumAutoConfiguration() { ApplicationContextRunner contextRunner = getEmptyContextRunner(); - contextRunner.withPropertyValues("spring.cloud.azure.jms.servicebus.pricing-tier=premium") + contextRunner.withPropertyValues("spring.jms.servicebus.pricing-tier=premium") .run(context -> assertThat(context).doesNotHaveBean(AzureServiceBusJMSProperties.class)); - contextRunner.withPropertyValues("spring.cloud.azure.jms.servicebus.enabled=false") + contextRunner.withPropertyValues("spring.jms.servicebus.enabled=false") .run(context -> assertThat(context).doesNotHaveBean(AzureServiceBusJMSProperties.class)); - contextRunner.withPropertyValues("spring.cloud.azure.jms.servicebus.connection-string=" + CONNECTION_STRING) + contextRunner.withPropertyValues("spring.jms.servicebus.connection-string=" + CONNECTION_STRING) .run(context -> assertThat(context).hasSingleBean(AzureServiceBusJMSProperties.class)); } @@ -48,8 +50,8 @@ public void testAzureServiceBusJMSPropertiesConnectionStringValidation() { public void testAzureServiceBusJMSPropertiesPricingTireValidation() { ApplicationContextRunner contextRunner = getEmptyContextRunner(); contextRunner.withPropertyValues( - "spring.cloud.azure.jms.servicebus.pricing-tier=fake", - "spring.cloud.azure.jms.servicebus.connection-string=" + CONNECTION_STRING) + "spring.jms.servicebus.pricing-tier=fake", + "spring.jms.servicebus.connection-string=" + CONNECTION_STRING) .run(context -> Assertions.assertThrows(IllegalStateException.class, () -> context.getBean(AzureServiceBusJMSProperties.class))); } @@ -88,6 +90,24 @@ public void testAzureServiceBusJMSPropertiesConfigured() { CONNECTION_STRING); assertThat(context.getBean(AzureServiceBusJMSProperties.class).getTopicClientId()).isEqualTo("cid"); assertThat(context.getBean(AzureServiceBusJMSProperties.class).getIdleTimeout()).isEqualTo(123); + assertThat(context.getBean(AzureServiceBusJMSProperties.class).getCredential().isMsiEnabled()).isEqualTo(true); + assertThat(context.getBean(AzureServiceBusJMSProperties.class).getEnvironment().getCloud()).isEqualTo("AzureGermany"); + } + ); + } + + @Test + public void testAzurePropertiesConfigured() { + ApplicationContextRunner contextRunner = getContextRunnerWithProperties(); + + contextRunner.run( + context -> { + assertThat(context).hasBean(AZURE_PROPERTY_BEAN_NAME); + + assertThat(((AzureProperties) context.getBean(AZURE_PROPERTY_BEAN_NAME)).getCredential().getCertificatePassword()) + .isEqualTo("for-test-purpose"); + assertThat(((AzureProperties) context.getBean(AZURE_PROPERTY_BEAN_NAME)).getEnvironment().getAuthorityHost()) + .isEqualTo("for-test-purpose"); } ); } @@ -98,7 +118,7 @@ private ApplicationContextRunner getEmptyContextRunner() { .withConfiguration(AutoConfigurations.of(NonPremiumServiceBusJMSAutoConfiguration.class, JmsAutoConfiguration.class, AzurePropertyAutoConfiguration.class)) .withPropertyValues( - "spring.cloud.azure.jms.servicebus.pricing-tier=basic" + "spring.jms.servicebus.pricing-tier=basic" ); } @@ -108,10 +128,14 @@ private ApplicationContextRunner getContextRunnerWithProperties() { .withConfiguration(AutoConfigurations.of(NonPremiumServiceBusJMSAutoConfiguration.class, JmsAutoConfiguration.class, AzurePropertyAutoConfiguration.class)) .withPropertyValues( - "spring.cloud.azure.jms.servicebus.connection-string=" + CONNECTION_STRING, - "spring.cloud.azure.jms.servicebus.topic-client-id=cid", - "spring.cloud.azure.jms.servicebus.idle-timeout=123", - "spring.cloud.azure.jms.servicebus.pricing-tier=basic" + "spring.jms.servicebus.connection-string=" + CONNECTION_STRING, + "spring.jms.servicebus.topic-client-id=cid", + "spring.jms.servicebus.idle-timeout=123", + "spring.jms.servicebus.pricing-tier=basic", + "spring.jms.servicebus.credential.msi-enabled=true", + "spring.jms.servicebus.environment.cloud=AzureGermany", + "spring.cloud.azure.credential.certificate-password=for-test-purpose", + "spring.cloud.azure.environment.authority-host=for-test-purpose" ); } } diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/jms/PremiumServiceBusJMSAutoConfigurationTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/jms/PremiumServiceBusJMSAutoConfigurationTest.java index c458515967761..9e0c8c9141657 100644 --- a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/jms/PremiumServiceBusJMSAutoConfigurationTest.java +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/jms/PremiumServiceBusJMSAutoConfigurationTest.java @@ -4,6 +4,7 @@ package com.azure.spring.autoconfigure.jms; import com.azure.spring.autoconfigure.unity.AzurePropertyAutoConfiguration; +import com.azure.spring.autoconfigure.unity.AzureProperties; import com.microsoft.azure.servicebus.jms.ServiceBusJmsConnectionFactory; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -15,6 +16,7 @@ import javax.jms.ConnectionFactory; +import static com.azure.spring.autoconfigure.unity.AzureProperties.AZURE_PROPERTY_BEAN_NAME; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -26,13 +28,13 @@ public class PremiumServiceBusJMSAutoConfigurationTest { @Test public void testAzureServiceBusPremiumAutoConfiguration() { ApplicationContextRunner contextRunner = getEmptyContextRunner(); - contextRunner.withPropertyValues("spring.cloud.azure.jms.servicebus.pricing-tier=basic") - .run(context -> assertThat(context).doesNotHaveBean(AzureServiceBusJMSProperties.class)); + contextRunner.withPropertyValues("spring.jms.servicebus.pricing-tier=basic") + .run(context -> assertThat(context).doesNotHaveBean(AzureServiceBusJMSProperties.class)); - contextRunner.withPropertyValues("spring.cloud.azure.jms.servicebus.enabled=false") - .run(context -> assertThat(context).doesNotHaveBean(AzureServiceBusJMSProperties.class)); + contextRunner.withPropertyValues("spring.jms.servicebus.enabled=false") + .run(context -> assertThat(context).doesNotHaveBean(AzureServiceBusJMSProperties.class)); - contextRunner.withPropertyValues("spring.cloud.azure.jms.servicebus.connection-string=" + CONNECTION_STRING) + contextRunner.withPropertyValues("spring.jms.servicebus.connection-string=" + CONNECTION_STRING) .run(context -> assertThat(context).hasSingleBean(AzureServiceBusJMSProperties.class)); } @@ -48,7 +50,7 @@ public void testAzureServiceBusJMSPropertiesConnectionStringValidation() { public void testWithoutServiceBusJMSNamespace() { ApplicationContextRunner contextRunner = getEmptyContextRunner(); contextRunner.withClassLoader(new FilteredClassLoader(ServiceBusJmsConnectionFactory.class)) - .run(context -> assertThat(context).doesNotHaveBean(AzureServiceBusJMSProperties.class)); + .run(context -> assertThat(context).doesNotHaveBean(AzureServiceBusJMSProperties.class)); } @Test @@ -74,10 +76,30 @@ public void testAzureServiceBusJMSPropertiesConfigured() { contextRunner.run( context -> { assertThat(context).hasSingleBean(AzureServiceBusJMSProperties.class); + assertThat(context).hasBean(AZURE_PROPERTY_BEAN_NAME); + assertThat(context.getBean(AzureServiceBusJMSProperties.class).getConnectionString()).isEqualTo( CONNECTION_STRING); assertThat(context.getBean(AzureServiceBusJMSProperties.class).getTopicClientId()).isEqualTo("cid"); assertThat(context.getBean(AzureServiceBusJMSProperties.class).getIdleTimeout()).isEqualTo(123); + assertThat(context.getBean(AzureServiceBusJMSProperties.class).getCredential().isMsiEnabled()).isEqualTo(true); + assertThat(context.getBean(AzureServiceBusJMSProperties.class).getEnvironment().getCloud()).isEqualTo("AzureGermany"); + } + ); + } + + @Test + public void testAzurePropertiesConfigured() { + ApplicationContextRunner contextRunner = getContextRunnerWithProperties(); + + contextRunner.run( + context -> { + assertThat(context).hasBean(AZURE_PROPERTY_BEAN_NAME); + + assertThat(((AzureProperties) context.getBean(AZURE_PROPERTY_BEAN_NAME)).getCredential().getCertificatePassword()) + .isEqualTo("for-test-purpose"); + assertThat(((AzureProperties) context.getBean(AZURE_PROPERTY_BEAN_NAME)).getEnvironment().getAuthorityHost()) + .isEqualTo("for-test-purpose"); } ); } @@ -88,7 +110,7 @@ private ApplicationContextRunner getEmptyContextRunner() { .withConfiguration(AutoConfigurations.of(PremiumServiceBusJMSAutoConfiguration.class, JmsAutoConfiguration.class, AzurePropertyAutoConfiguration.class)) .withPropertyValues( - "spring.cloud.azure.jms.servicebus.pricing-tier=premium" + "spring.jms.servicebus.pricing-tier=premium" ); } @@ -98,10 +120,14 @@ private ApplicationContextRunner getContextRunnerWithProperties() { .withConfiguration(AutoConfigurations.of(PremiumServiceBusJMSAutoConfiguration.class, JmsAutoConfiguration.class, AzurePropertyAutoConfiguration.class)) .withPropertyValues( - "spring.cloud.azure.jms.servicebus.connection-string=" + CONNECTION_STRING, - "spring.cloud.azure.jms.servicebus.topic-client-id=cid", - "spring.cloud.azure.jms.servicebus.idle-timeout=123", - "spring.cloud.azure.jms.servicebus.pricing-tier=premium" + "spring.jms.servicebus.connection-string=" + CONNECTION_STRING, + "spring.jms.servicebus.topic-client-id=cid", + "spring.jms.servicebus.idle-timeout=123", + "spring.jms.servicebus.pricing-tier=premium", + "spring.jms.servicebus.credential.msi-enabled=true", + "spring.jms.servicebus.environment.cloud=AzureGermany", + "spring.cloud.azure.credential.certificate-password=for-test-purpose", + "spring.cloud.azure.environment.authority-host=for-test-purpose" ); } } diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/storage/StorageAutoConfigurationTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/storage/StorageAutoConfigurationTest.java index 98dd7fae8a90c..5e19b187f8d59 100644 --- a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/storage/StorageAutoConfigurationTest.java +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/storage/StorageAutoConfigurationTest.java @@ -4,6 +4,7 @@ package com.azure.spring.autoconfigure.storage; import com.azure.spring.autoconfigure.unity.AzurePropertyAutoConfiguration; +import com.azure.spring.autoconfigure.unity.AzureProperties; import com.azure.storage.blob.BlobServiceClientBuilder; import com.azure.storage.file.share.ShareServiceClientBuilder; import org.junit.jupiter.api.Test; @@ -14,6 +15,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; +import static com.azure.spring.autoconfigure.unity.AzureProperties.AZURE_PROPERTY_BEAN_NAME; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -49,12 +51,31 @@ public void testAzureStoragePropertiesConfigured() { this.contextRunner.withPropertyValues("spring.cloud.azure.storage.account-name=acc1") .withPropertyValues("spring.cloud.azure.storage.account-key=key1") .withPropertyValues("spring.cloud.azure.storage.blob-endpoint=endpoint1") + .withPropertyValues("spring.cloud.azure.storage.credential.client-id=for-test-purpose") + .withPropertyValues("spring.cloud.azure.storage.environment.cloud=AzureUSGovernment") .run(context -> { assertThat(context).hasSingleBean(StorageProperties.class); final StorageProperties storageProperties = context.getBean(StorageProperties.class); assertThat(storageProperties.getAccountName()).isEqualTo("acc1"); assertThat(storageProperties.getAccountKey()).isEqualTo("key1"); assertThat(storageProperties.getBlobEndpoint()).isEqualTo("endpoint1"); + assertThat(storageProperties.getCredential().getClientId()).isEqualTo("for-test-purpose"); + assertThat(storageProperties.getEnvironment().getCloud()).isEqualTo("AzureUSGovernment"); + }); + } + + @Test + public void testAzurePropertiesConfigured() { + this.contextRunner.withPropertyValues("spring.cloud.azure.credential.client-id=for-test-purpose") + .withPropertyValues("spring.cloud.azure.environment.cloud=AzureUSGovernment") + .withPropertyValues("spring.cloud.azure.storage.account-name=acc1") + .run(context -> { + assertThat(context).hasSingleBean(StorageProperties.class); + assertThat(context).hasBean(AZURE_PROPERTY_BEAN_NAME); + + final AzureProperties azureProperties = (AzureProperties) context.getBean(AZURE_PROPERTY_BEAN_NAME); + assertThat(azureProperties.getCredential().getClientId()).isEqualTo("for-test-purpose"); + assertThat(azureProperties.getEnvironment().getCloud()).isEqualTo("AzureUSGovernment"); }); } diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/storage/actuator/BlobStorageHealthIndicatorTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/storage/actuator/BlobStorageHealthIndicatorTest.java index b869f6fab4c5e..8441383cb5b49 100644 --- a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/storage/actuator/BlobStorageHealthIndicatorTest.java +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/storage/actuator/BlobStorageHealthIndicatorTest.java @@ -48,7 +48,7 @@ public void testWithStorageConfigurationWithConnectionUp() { .withAllowBeanDefinitionOverriding(true) .withConfiguration(AutoConfigurations.of(StorageAutoConfiguration.class, StorageHealthConfiguration.class)) .withUserConfiguration(TestConfigurationConnectionUp.class) - .withPropertyValues("azure.storage.account-name=acc1"); + .withPropertyValues("spring.cloud.azure.storage.account-name=acc1"); contextRunner.run(context -> { Health health = context.getBean("blobStorageHealthIndicator", BlobStorageHealthIndicator.class) @@ -64,7 +64,7 @@ public void testWithStorageConfigurationWithConnectionDown() { .withAllowBeanDefinitionOverriding(true) .withConfiguration(AutoConfigurations.of(StorageAutoConfiguration.class, StorageHealthConfiguration.class)) .withUserConfiguration(TestConfigurationConnectionDown.class) - .withPropertyValues("azure.storage.account-name=acc1"); + .withPropertyValues("spring.cloud.azure.storage.account-name=acc1"); contextRunner.run(context -> { Health health = context.getBean("blobStorageHealthIndicator", BlobStorageHealthIndicator.class) diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/storage/actuator/FileStorageHealthIndicatorTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/storage/actuator/FileStorageHealthIndicatorTest.java index 729f4dd396048..9567265769287 100644 --- a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/storage/actuator/FileStorageHealthIndicatorTest.java +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/storage/actuator/FileStorageHealthIndicatorTest.java @@ -45,7 +45,7 @@ public void testWithStorageConfigurationWithConnectionUp() { .withAllowBeanDefinitionOverriding(true) .withConfiguration(AutoConfigurations.of(StorageAutoConfiguration.class, StorageHealthConfiguration.class)) .withUserConfiguration(TestConfigurationConnectionUp.class) - .withPropertyValues("azure.storage.account-name=acc1"); + .withPropertyValues("spring.cloud.azure.storage.account-name=acc1"); contextRunner.run(context -> { Health health = context.getBean(FileStorageHealthIndicator.class).getHealth(true); Assertions.assertEquals(Status.UP, health.getStatus()); @@ -59,7 +59,7 @@ public void testWithStorageConfigurationWithConnectionDown() { .withAllowBeanDefinitionOverriding(true) .withConfiguration(AutoConfigurations.of(StorageAutoConfiguration.class, StorageHealthConfiguration.class)) .withUserConfiguration(TestConfigurationConnectionDown.class) - .withPropertyValues("azure.storage.account-name=acc1"); + .withPropertyValues("spring.cloud.azure.storage.account-name=acc1"); contextRunner.run(context -> { Health health = context.getBean(FileStorageHealthIndicator.class).getHealth(true); Assertions.assertEquals(Status.DOWN, health.getStatus()); diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/unity/AzurePropertyAutoConfigurationTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/unity/AzurePropertyAutoConfigurationTest.java new file mode 100644 index 0000000000000..ad426473d3715 --- /dev/null +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/autoconfigure/unity/AzurePropertyAutoConfigurationTest.java @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +package com.azure.spring.autoconfigure.unity; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +public class AzurePropertyAutoConfigurationTest { + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(AzurePropertyAutoConfiguration.class)); + + @Test + public void testAutoConfiguration() { + this.contextRunner.run(context -> { + assertThat(context).hasSingleBean(AzurePropertyAutoConfiguration.class); + assertThat(context).hasSingleBean(AzureProperties.class); + }); + } + + @Test + public void testAzureProperties() { + this.contextRunner.withPropertyValues( + "spring.cloud.azure.credential.client-id=fake-client-id", + "spring.cloud.azure.credential.client_secret=fake-client-secret", + "spring.cloud.azure.environment.authorityHost=fake-authority-host", + "spring.cloud.azure.environment.GRAPH_BASE_URI=fake-graph-base-uri" + ) + .run(context -> { + final AzureProperties azureProperties = context.getBean(AzureProperties.class); + assertThat(azureProperties.getCredential().getClientId()).isEqualTo("fake-client-id"); + assertThat(azureProperties.getCredential().getClientSecret()).isEqualTo("fake-client-secret"); + assertThat(azureProperties.getEnvironment().getAuthorityHost()).isEqualTo("fake-authority-host"); + assertThat(azureProperties.getEnvironment().getGraphBaseUri()).isEqualTo("fake-graph-base-uri"); + }); + } +} diff --git a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessorTest.java b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessorTest.java index 772cf45873ce0..7da7750299404 100644 --- a/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessorTest.java +++ b/sdk/spring/azure-spring-boot/src/test/java/com/azure/spring/keyvault/KeyVaultEnvironmentPostProcessorTest.java @@ -22,12 +22,18 @@ import java.util.HashMap; import java.util.Map; +import static com.azure.spring.keyvault.KeyVaultProperties.Property.AUTHORITY_HOST; import static com.azure.spring.keyvault.KeyVaultProperties.Property.CERTIFICATE_PATH; import static com.azure.spring.keyvault.KeyVaultProperties.Property.CLIENT_ID; import static com.azure.spring.keyvault.KeyVaultProperties.Property.CLIENT_KEY; +import static com.azure.spring.keyvault.KeyVaultProperties.Property.CLIENT_SECRET; +import static com.azure.spring.keyvault.KeyVaultProperties.Property.ORDER; import static com.azure.spring.keyvault.KeyVaultProperties.Property.TENANT_ID; +import static com.azure.spring.keyvault.KeyVaultProperties.Property.URI; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class KeyVaultEnvironmentPostProcessorTest { private KeyVaultEnvironmentPostProcessorHelper keyVaultEnvironmentPostProcessorHelper; @@ -149,16 +155,70 @@ public void testMultipleKeyVaults() { } @Test - public void testGetPropertyFromCommonProperties() { - testProperties.put("spring.cloud.azure.client-id", "fake-client-id"); + public void testGetCredentialFromKeyVaultProperties() { + testProperties.put("spring.cloud.azure.keyvault.credential.client-id", "aaaa-bbbb-cccc-dddd"); + testProperties.put("spring.cloud.azure.keyvault.credential.client-secret", "mySecret"); + testProperties.put("spring.cloud.azure.keyvault.credential.tenant-id", "myid"); + propertySources.addLast(new MapPropertySource("Test_Properties", testProperties)); + keyVaultEnvironmentPostProcessorHelper = new KeyVaultEnvironmentPostProcessorHelper(environment); + + final TokenCredential credentials = keyVaultEnvironmentPostProcessorHelper.getCredentials(); + + assertThat(credentials, IsInstanceOf.instanceOf(ClientSecretCredential.class)); + } + + @Test + public void testGetCredentialFromCommonProperties() { + testProperties.put("spring.cloud.azure.credential.client-id", "fake-client-id"); + testProperties.put("spring.cloud.azure.credential.client-secret", "fake-client-secret"); + testProperties.put("spring.cloud.azure.credential.tenant-id", "fake-tenant-id"); propertySources.addLast(new MapPropertySource("Test_Properties", testProperties)); keyVaultEnvironmentPostProcessorHelper = new KeyVaultEnvironmentPostProcessorHelper(environment); final TokenCredential credentials = keyVaultEnvironmentPostProcessorHelper.getCredentials(); - assertThat(credentials, IsInstanceOf.instanceOf(ManagedIdentityCredential.class)); + assertThat(credentials, IsInstanceOf.instanceOf(ClientSecretCredential.class)); } + + @Test + public void testGetPropertyValue() { + testProperties.put("spring.cloud.azure.credential.client-id", "client1"); + + testProperties.put("spring.cloud.azure.keyvault.credential.client-secret", "secret2"); + + testProperties.put("spring.cloud.azure.credential.tenant-id", "tenant1"); + testProperties.put("spring.cloud.azure.keyvault.credential.tenant-id", "tenant2"); + + testProperties.put("spring.cloud.azure.environment.authority-host", "host1"); + testProperties.put("spring.cloud.azure.keyvault.environment.authority-host", "host2"); + + testProperties.put("spring.cloud.azure.credential.certificate-path", "cert1"); + testProperties.put("spring.cloud.azure.keyvault.mykeyvault.credential.certificate-path", "cert2"); + + testProperties.put("spring.cloud.azure.keyvault.uri", "uri1"); + + propertySources.addLast(new MapPropertySource("Test_Properties", testProperties)); + + keyVaultEnvironmentPostProcessorHelper = new KeyVaultEnvironmentPostProcessorHelper(environment); + + String clientId = keyVaultEnvironmentPostProcessorHelper.getPropertyValue("", CLIENT_ID); + String clientSecert = keyVaultEnvironmentPostProcessorHelper.getPropertyValue("", CLIENT_SECRET); + String tenantId = keyVaultEnvironmentPostProcessorHelper.getPropertyValue("", TENANT_ID); + String authorityHost = keyVaultEnvironmentPostProcessorHelper.getPropertyValue("", AUTHORITY_HOST); + String certificatePath = keyVaultEnvironmentPostProcessorHelper.getPropertyValue("mykeyvault", CERTIFICATE_PATH); + String uri = keyVaultEnvironmentPostProcessorHelper.getPropertyValue("", URI); + String order = keyVaultEnvironmentPostProcessorHelper.getPropertyValue("", ORDER); + + assertEquals("client1", clientId); + assertEquals("secret2", clientSecert); + assertEquals("tenant2", tenantId); + assertNotEquals("host1", authorityHost); + assertEquals("cert2", certificatePath); + assertEquals("uri1", uri); + assertNull(order); + } + } @Configuration diff --git a/sdk/spring/azure-spring-cloud-context/CHANGELOG.md b/sdk/spring/azure-spring-cloud-context/CHANGELOG.md index d4da686d10cd0..df67010233e17 100644 --- a/sdk/spring/azure-spring-cloud-context/CHANGELOG.md +++ b/sdk/spring/azure-spring-cloud-context/CHANGELOG.md @@ -1,23 +1,6 @@ # Release History ## 2.7.0-beta.1 (Unreleased) -### New Features -- Support unified properties as below when the service specific properties are not configured.([#22396](https://github.com/Azure/azure-sdk-for-java/issues/22396)) - ``` - spring: - cloud: - azure: - authority-host: - client-id: - client-secret: - certificate-path: - msi-enabled: - tenant-id: - environment: - ``` - -### Breaking Changes -- Property type of `spring.cloud.azure.environment` are changed from Enum to String. Supported values are "Azure", "AzureChina", "AzureGermany" and "AzureUSGovernment". ## 2.6.0 (2021-06-23) ### Breaking Changes diff --git a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.java b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.java index 24fbb6fd5183d..1174153bf0895 100644 --- a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.java +++ b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.java @@ -8,8 +8,6 @@ import com.azure.resourcemanager.AzureResourceManager; import com.azure.spring.cloud.context.core.api.CredentialsProvider; import com.azure.spring.cloud.context.core.api.EnvironmentProvider; -import com.azure.spring.core.SpringPropertyPrefix; -import com.azure.spring.core.CredentialProperties; import com.azure.spring.cloud.context.core.impl.ResourceGroupManager; import com.azure.spring.identity.DefaultSpringCredentialBuilder; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -19,8 +17,8 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; import org.springframework.context.annotation.Import; +import org.springframework.core.env.Environment; /** * Auto-config to provide default {@link CredentialsProvider} for all Azure services * @@ -61,7 +59,7 @@ public AzureProfile azureProfile(AzureContextProperties azureContextProperties, @ConditionalOnMissingBean public TokenCredential credential(Environment environment) { return new DefaultSpringCredentialBuilder().environment(environment) - .alternativePrefix(SpringPropertyPrefix.PREFIX) + .alternativePrefix(AzureContextProperties.PREFIX) .build(); } diff --git a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureContextProperties.java b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureContextProperties.java index e604148418163..6b9ca36d9f9a1 100644 --- a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureContextProperties.java +++ b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureContextProperties.java @@ -4,7 +4,6 @@ package com.azure.spring.cloud.autoconfigure.context; import com.azure.spring.cloud.context.core.enums.AzureEnvironments; -import com.azure.spring.core.SpringPropertyPrefix; import com.google.common.base.Strings; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.util.Assert; @@ -16,9 +15,11 @@ * Azure Context related properties for resource management. */ @Validated -@ConfigurationProperties(SpringPropertyPrefix.PREFIX) +@ConfigurationProperties(AzureContextProperties.PREFIX) public class AzureContextProperties { + public static final String PREFIX = "spring.cloud.azure"; + private String clientId; private String clientSecret; diff --git a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/impl/DefaultEnvironmentProvider.java b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/impl/DefaultEnvironmentProvider.java index 3f628c02ceaa8..0958d5556f62a 100644 --- a/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/impl/DefaultEnvironmentProvider.java +++ b/sdk/spring/azure-spring-cloud-context/src/main/java/com/azure/spring/cloud/context/core/impl/DefaultEnvironmentProvider.java @@ -5,11 +5,11 @@ import com.azure.core.management.AzureEnvironment; import com.azure.spring.cloud.context.core.api.EnvironmentProvider; -import com.azure.spring.core.AzureProperties; +import com.azure.spring.cloud.autoconfigure.context.AzureContextProperties; /** * A {@link EnvironmentProvider} implementation that based on {@link - * AzureProperties}. + * AzureContextProperties}. * * @author Warren Zhu */ diff --git a/sdk/spring/spring-test-template.yml b/sdk/spring/spring-test-template.yml index 2a2889a226e12..d751bb505931c 100644 --- a/sdk/spring/spring-test-template.yml +++ b/sdk/spring/spring-test-template.yml @@ -10,8 +10,6 @@ parameters: - spring/azure-spring-boot-test-storage - spring/azure-spring-cloud-test-eventhubs - spring/azure-spring-cloud-test-servicebus-binder - - spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-binder - - spring/azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-kafka Artifacts: - name: azure-spring-boot-test-application groupId: com.azure.spring @@ -58,12 +56,6 @@ parameters: - name: azure-spring-boot-test-storage groupId: com.azure.spring safeName: azurespringbootteststorage - - name: azure-spring-cloud-sample-eventhubs-binder - groupId: com.azure.spring - safeName: azurespringcloudsampleeventhubsbinder - - name: azure-spring-cloud-sample-eventhubs-kafka - groupId: com.azure.spring - safeName: azurespringcloudsampleeventhubskafka - name: azure-spring-cloud-test-servicebus-binder groupId: com.azure.spring safeName: azurespringcloudtestservicebusbinder