Skip to content

Commit 7f619d5

Browse files
committed
Adopt purely name-based user-override contract for EventHubClientBuilder
Remove the custom OnMissingUserDefinedEventHubClientBuilderCondition and rely solely on @ConditionalOnMissingBean(name = EVENT_HUB_CLIENT_BUILDER_BEAN_NAME). The override contract is now uniformly name-based: to replace the auto-configured root builder (and have shared EventHubConsumerClient/EventHubProducerClient pick up the override) the user must register their bean under springCloudAzureEventHubsClientBuilder. A user-supplied bean under any other name no longer suppresses the auto-configured root and is not wired into the shared clients. Update userDefinedEventHubsClientBuilderProvidedShouldNotAutoconfigure to register under the reserved name, add a new userDefinedEventHubsClientBuilderUnderCustomNameShouldNotSuppressAutoconfigure asserting the new coexistence behavior, and tighten the CHANGELOG breaking-change entry.
1 parent 22c894f commit 7f619d5

4 files changed

Lines changed: 18 additions & 56 deletions

File tree

sdk/spring/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This section includes changes in `spring-cloud-azure-autoconfigure` module.
1111
- AAD resource server now requires `spring.cloud.azure.active-directory.profile.tenant-id` to be set to a specific (non-reserved) tenant ID. Empty string, `common`, `organizations`, and `consumers` are no longer accepted and will cause application startup to fail with an `IllegalArgumentException`. ([#49033](https://github.com/Azure/azure-sdk-for-java/pull/49033))
1212
- `AadAuthenticationFilter` now enables explicit audience validation by default. The filter will verify that the JWT's `aud` (audience) claim matches either `spring.cloud.azure.active-directory.credential.client-id` or `spring.cloud.azure.active-directory.app-id-uri`. Tokens issued for other applications will be rejected with `BadJWTException`. This prevents cross-application token reuse and aligns with OAuth2/OIDC security best practices. ([#49033](https://github.com/Azure/azure-sdk-for-java/pull/49033))
1313
- B2C resource server now requires `spring.cloud.azure.active-directory.b2c.profile.tenant-id` to be set to a specific (non-reserved) tenant ID. Empty string, `common`, `organizations`, and `consumers` are no longer accepted. In addition, default token validation is hardened to enforce tenant-bound `tid`, stricter `aud` validation, and B2C-only trusted issuers. ([#49252](https://github.com/Azure/azure-sdk-for-java/pull/49252))
14-
- Event Hubs shared consumer/producer auto-configuration now wires the root `EventHubClientBuilder` by bean name (`springCloudAzureEventHubsClientBuilder`) instead of by type. Users who provide their own `EventHubClientBuilder` bean and want it to be injected into the auto-configured shared `EventHubConsumerClient`/`EventHubProducerClient` must register it under that bean name; a user-supplied builder under a different name will still suppress the auto-configured root builder, but will not be wired into the shared clients. ([#49245](https://github.com/Azure/azure-sdk-for-java/issues/49245))
14+
- Event Hubs auto-configuration now identifies the root `EventHubClientBuilder` by bean name (`springCloudAzureEventHubsClientBuilder`) instead of by type. To override the auto-configured root builder (and have shared `EventHubConsumerClient`/`EventHubProducerClient` use your bean), register the bean under the name `springCloudAzureEventHubsClientBuilder`. A user-supplied `EventHubClientBuilder` bean under a different name will no longer suppress the auto-configured root builder and will not be wired into the shared clients. ([#49245](https://github.com/Azure/azure-sdk-for-java/issues/49245))
1515

1616
#### Bugs Fixed
1717

sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/AzureEventHubsClientBuilderConfiguration.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
2020
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2121
import org.springframework.context.annotation.Bean;
22-
import org.springframework.context.annotation.Conditional;
2322
import org.springframework.context.annotation.Configuration;
2423
import org.springframework.context.annotation.Import;
2524

@@ -43,7 +42,6 @@ class AzureEventHubsClientBuilderConfiguration {
4342

4443
@Bean(EVENT_HUB_CLIENT_BUILDER_BEAN_NAME)
4544
@ConditionalOnMissingBean(name = EVENT_HUB_CLIENT_BUILDER_BEAN_NAME)
46-
@Conditional(OnMissingUserDefinedEventHubClientBuilderCondition.class)
4745
EventHubClientBuilder eventHubClientBuilder(@Qualifier(EVENT_HUB_CLIENT_BUILDER_FACTORY_BEAN_NAME)
4846
EventHubClientBuilderFactory factory) {
4947
return factory.build();

sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/OnMissingUserDefinedEventHubClientBuilderCondition.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/AzureEventHubsClientBuilderConfigurationTests.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.azure.data.appconfiguration.ConfigurationClientBuilder;
77
import com.azure.messaging.eventhubs.EventHubClientBuilder;
88
import com.azure.spring.cloud.autoconfigure.implementation.TestBuilderCustomizer;
9+
import com.azure.spring.cloud.autoconfigure.implementation.context.AzureContextUtils;
910
import com.azure.spring.cloud.autoconfigure.implementation.context.properties.AzureGlobalProperties;
1011
import com.azure.spring.cloud.autoconfigure.implementation.eventhubs.properties.AzureEventHubsConnectionDetails;
1112
import com.azure.spring.cloud.core.provider.connectionstring.StaticConnectionStringProvider;
@@ -93,10 +94,24 @@ void userDefinedEventHubsClientBuilderProvidedShouldNotAutoconfigure() {
9394
"spring.cloud.azure.eventhubs.connection-string=" + String.format(CONNECTION_STRING_FORMAT, "test-namespace")
9495
)
9596
.withBean(AzureGlobalProperties.class, AzureGlobalProperties::new)
96-
.withBean("user-defined-builder", EventHubClientBuilder.class, EventHubClientBuilder::new)
97+
.withBean(AzureContextUtils.EVENT_HUB_CLIENT_BUILDER_BEAN_NAME, EventHubClientBuilder.class, EventHubClientBuilder::new)
9798
.run(context -> {
9899
assertThat(context).hasSingleBean(EventHubClientBuilder.class);
99-
assertThat(context).hasBean("user-defined-builder");
100+
assertThat(context).hasBean(AzureContextUtils.EVENT_HUB_CLIENT_BUILDER_BEAN_NAME);
101+
});
102+
}
103+
104+
@Test
105+
void userDefinedEventHubsClientBuilderUnderCustomNameShouldNotSuppressAutoconfigure() {
106+
this.contextRunner
107+
.withPropertyValues(
108+
"spring.cloud.azure.eventhubs.connection-string=" + String.format(CONNECTION_STRING_FORMAT, "test-namespace")
109+
)
110+
.withBean(AzureGlobalProperties.class, AzureGlobalProperties::new)
111+
.withBean("user-defined-builder", EventHubClientBuilder.class, EventHubClientBuilder::new)
112+
.run(context -> {
113+
assertThat(context).getBeanNames(EventHubClientBuilder.class)
114+
.containsExactlyInAnyOrder("user-defined-builder", AzureContextUtils.EVENT_HUB_CLIENT_BUILDER_BEAN_NAME);
100115
});
101116
}
102117

0 commit comments

Comments
 (0)