diff --git a/sdk/identity/azure-identity-extensions/CHANGELOG.md b/sdk/identity/azure-identity-extensions/CHANGELOG.md index 63bf441ee75c7..38751608824ba 100644 --- a/sdk/identity/azure-identity-extensions/CHANGELOG.md +++ b/sdk/identity/azure-identity-extensions/CHANGELOG.md @@ -2,11 +2,52 @@ ## 1.2.0-beta.2 (Unreleased) +#### Bugs Fixed +- Fix the issue where the token acquisition timeout is not set via the property `azure.accessTokenTimeoutInSeconds`. [#43512](https://github.com/Azure/azure-sdk-for-java/issues/43512). + ### Other Changes #### Dependency Updates -- Upgraded `mysql-connector-j` from `8.0.33` to version `9.0.0`. +## 1.1.22 (2024-12-04) + +### Other Changes + +#### Dependency Updates + +- Upgraded `azure-identity` from `1.14.0` to version `1.14.2`. + +## 1.1.21 (2024-10-28) + +### Other Changes + +#### Dependency Updates + +- Upgraded `azure-identity` from `1.13.3` to version `1.14.0`. + +## 1.1.20 (2024-09-28) + +### Other Changes + +#### Dependency Updates + +- Upgraded `azure-identity` from `1.13.2` to version `1.13.3`. + +## 1.1.19 (2024-08-25) + +### Other Changes + +#### Dependency Updates + +- Upgraded `azure-identity` from `1.13.1` to version `1.13.2`. + +## 1.1.18 (2024-07-27) + +### Other Changes + +#### Dependency Updates + +- Upgraded `azure-identity` from `1.13.0` to version `1.13.1`. ## 1.1.17 (2024-06-25) @@ -153,6 +194,14 @@ - Improve the performance of DefaultTokenCredentialProvider's `get()` method. +## 1.2.0-beta.1 (2023-02-04) + +### Other Changes + +#### Dependency Updates + +- Upgraded `mysql-connector-j` from `8.0.33` to version `9.0.0`. + ## 1.2.0-beta.1 (2023-02-06) ### Other Changes diff --git a/sdk/identity/azure-identity-extensions/src/main/java/com/azure/identity/extensions/implementation/credential/TokenCredentialProviderOptions.java b/sdk/identity/azure-identity-extensions/src/main/java/com/azure/identity/extensions/implementation/credential/TokenCredentialProviderOptions.java index af785be09d759..68bf84b858400 100644 --- a/sdk/identity/azure-identity-extensions/src/main/java/com/azure/identity/extensions/implementation/credential/TokenCredentialProviderOptions.java +++ b/sdk/identity/azure-identity-extensions/src/main/java/com/azure/identity/extensions/implementation/credential/TokenCredentialProviderOptions.java @@ -25,6 +25,7 @@ public class TokenCredentialProviderOptions { private boolean managedIdentityEnabled; private String tokenCredentialProviderClassName; private String tokenCredentialBeanName; + private String accessTokenTimeoutInSeconds; public TokenCredentialProviderOptions() { @@ -41,6 +42,7 @@ public TokenCredentialProviderOptions(Properties properties) { this.managedIdentityEnabled = Boolean.TRUE.equals(AuthProperty.MANAGED_IDENTITY_ENABLED.getBoolean(properties)); this.tokenCredentialProviderClassName = AuthProperty.TOKEN_CREDENTIAL_PROVIDER_CLASS_NAME.get(properties); this.tokenCredentialBeanName = AuthProperty.TOKEN_CREDENTIAL_BEAN_NAME.get(properties); + this.accessTokenTimeoutInSeconds = AuthProperty.GET_TOKEN_TIMEOUT.get(properties); this.authorityHost = AuthProperty.AUTHORITY_HOST.get(properties); } @@ -132,4 +134,11 @@ public void setAuthorityHost(String authorityHost) { this.authorityHost = authorityHost; } + public String getAccessTokenTimeoutInSeconds() { + return accessTokenTimeoutInSeconds; + } + + public void setAccessTokenTimeoutInSeconds(String accessTokenTimeoutInSeconds) { + this.accessTokenTimeoutInSeconds = accessTokenTimeoutInSeconds; + } } diff --git a/sdk/identity/azure-identity-extensions/src/main/java/com/azure/identity/extensions/implementation/enums/AuthProperty.java b/sdk/identity/azure-identity-extensions/src/main/java/com/azure/identity/extensions/implementation/enums/AuthProperty.java index 1daf1c7383dd2..198524d909e7d 100644 --- a/sdk/identity/azure-identity-extensions/src/main/java/com/azure/identity/extensions/implementation/enums/AuthProperty.java +++ b/sdk/identity/azure-identity-extensions/src/main/java/com/azure/identity/extensions/implementation/enums/AuthProperty.java @@ -67,7 +67,7 @@ public enum AuthProperty { /** * Max time to get an access token. */ - GET_TOKEN_TIMEOUT("azure.accessTokenTimeoutInSeconds", "Max time to get an access token.", false), + GET_TOKEN_TIMEOUT("azure.accessTokenTimeoutInSeconds", "30", "Max time to get an access token.", false), /** * The canonical class name of a class that implements 'TokenCredentialProvider'. */ diff --git a/sdk/identity/azure-identity-extensions/src/main/java/com/azure/identity/extensions/implementation/template/AzureAuthenticationTemplate.java b/sdk/identity/azure-identity-extensions/src/main/java/com/azure/identity/extensions/implementation/template/AzureAuthenticationTemplate.java index 6fbf69c85ceca..4240aa50313ff 100644 --- a/sdk/identity/azure-identity-extensions/src/main/java/com/azure/identity/extensions/implementation/template/AzureAuthenticationTemplate.java +++ b/sdk/identity/azure-identity-extensions/src/main/java/com/azure/identity/extensions/implementation/template/AzureAuthenticationTemplate.java @@ -9,10 +9,11 @@ import com.azure.identity.extensions.implementation.credential.TokenCredentialProviderOptions; import com.azure.identity.extensions.implementation.token.AccessTokenResolver; import com.azure.identity.extensions.implementation.token.AccessTokenResolverOptions; -import reactor.core.publisher.Mono; import java.time.Duration; import java.util.Properties; import java.util.concurrent.atomic.AtomicBoolean; +import reactor.core.publisher.Mono; +import static com.azure.identity.extensions.implementation.enums.AuthProperty.GET_TOKEN_TIMEOUT; /** * Template class can be extended to get password from access token. @@ -27,6 +28,8 @@ public class AzureAuthenticationTemplate { private AccessTokenResolver accessTokenResolver; + private long accessTokenTimeoutInSeconds; + /** * Default constructor for AzureAuthenticationTemplate */ @@ -66,6 +69,12 @@ public void init(Properties properties) { = AccessTokenResolver.createDefault(new AccessTokenResolverOptions(properties)); } + if (properties.containsKey(GET_TOKEN_TIMEOUT.getPropertyKey())) { + accessTokenTimeoutInSeconds = Long.parseLong(GET_TOKEN_TIMEOUT.get(properties)); + } else { + accessTokenTimeoutInSeconds = 30; + LOGGER.verbose("Use default access token timeout: {} seconds.", accessTokenTimeoutInSeconds); + } LOGGER.verbose("Initialized AzureAuthenticationTemplate."); } else { LOGGER.info("AzureAuthenticationTemplate has already initialized."); @@ -110,7 +119,7 @@ TokenCredentialProvider getTokenCredentialProvider() { } Duration getBlockTimeout() { - return Duration.ofSeconds(30); + return Duration.ofSeconds(accessTokenTimeoutInSeconds); } AtomicBoolean getIsInitialized() { diff --git a/sdk/identity/azure-identity-extensions/src/test/java/com/azure/identity/extensions/implementation/template/AzureAuthenticationTemplateTest.java b/sdk/identity/azure-identity-extensions/src/test/java/com/azure/identity/extensions/implementation/template/AzureAuthenticationTemplateTest.java index 05b1d1578e1c0..b7750f5cd4c1c 100644 --- a/sdk/identity/azure-identity-extensions/src/test/java/com/azure/identity/extensions/implementation/template/AzureAuthenticationTemplateTest.java +++ b/sdk/identity/azure-identity-extensions/src/test/java/com/azure/identity/extensions/implementation/template/AzureAuthenticationTemplateTest.java @@ -12,10 +12,12 @@ import org.mockito.MockedConstruction; import reactor.core.publisher.Mono; +import java.lang.reflect.Field; import java.time.OffsetDateTime; import java.util.Properties; import java.util.concurrent.TimeUnit; +import static com.azure.identity.extensions.implementation.enums.AuthProperty.GET_TOKEN_TIMEOUT; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -109,4 +111,25 @@ void testGetTokenAsPassword() throws InterruptedException { } } + @Test + void useDefaultAccessTokenTimeout() throws NoSuchFieldException, IllegalAccessException { + AzureAuthenticationTemplate template = new AzureAuthenticationTemplate(); + Properties properties = new Properties(); + template.init(properties); + assertNotNull(template.getBlockTimeout()); + Field defaultValueField = GET_TOKEN_TIMEOUT.getClass().getDeclaredField("defaultValue"); + defaultValueField.setAccessible(true); + String defaultVault = (String) defaultValueField.get(GET_TOKEN_TIMEOUT); + assertEquals(template.getBlockTimeout().getSeconds() + "", defaultVault); + } + + @Test + void useCustomAccessTokenTimeout() { + AzureAuthenticationTemplate template = new AzureAuthenticationTemplate(); + Properties properties = new Properties(); + properties.setProperty(AuthProperty.GET_TOKEN_TIMEOUT.getPropertyKey(), "35"); + template.init(properties); + assertNotNull(template.getBlockTimeout()); + assertEquals(template.getBlockTimeout().getSeconds(), 35); + } }