-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix TokenCredential bean name resolution in Spring Cloud Stream Binder and EventHubs Messaging #47444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: rujche <[email protected]>
Co-authored-by: rujche <[email protected]>
Co-authored-by: rujche <[email protected]>
...spring/cloud/stream/binder/eventhubs/implementation/config/EventHubsBinderConfiguration.java
Show resolved
Hide resolved
Co-authored-by: rujche <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: rujche <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
...ud/autoconfigure/implementation/eventhubs/AzureEventHubsMessagingAutoConfigurationTests.java
Show resolved
Hide resolved
Co-authored-by: rujche <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
...ud/autoconfigure/implementation/eventhubs/AzureEventHubsMessagingAutoConfigurationTests.java
Outdated
Show resolved
Hide resolved
Co-authored-by: rujche <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
...ud/autoconfigure/implementation/eventhubs/AzureEventHubsMessagingAutoConfigurationTests.java
Show resolved
Hide resolved
…-bean-name property test Co-authored-by: rujche <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
| this.contextRunner | ||
| .withPropertyValues( | ||
| "spring.cloud.azure.eventhubs.connection-string=" + String.format(CONNECTION_STRING_FORMAT, "test-namespace"), | ||
| "spring.cloud.azure.credential.token-credential-bean-name=my-token-credential" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Reconsider what's the expected behavior when setting
spring.cloud.azure.credential.token-credential-bean-name=my-token-credential. - Update all the 3 tests files, assert that after setting
spring.cloud.azure.credential.token-credential-bean-name=my-token-credential, themy-token-credentialbean will be used to do authentication for event hubs and service bus. Only keep this test case, delete all other new added test cases in this PR. - Always use import instead of using full qualified class name.
- Reconsider whether
resolveTokenCredentialmethod should takeazureTokenCredentialResolveras parameter? I fell only eventHubsProperties is enouth, it check whetherDEFAULT_TOKEN_CREDENTIAL_BEAN_NAMEshould be used or the property likespring.cloud.azure.credential.token-credential-bean-nameshould be used. - Reconsider the bean name configured by
spring.cloud.azure.credential.token-credential-bean-nameandspring.cloud.azure.xxx.credential.token-credential-bean-name, herexxxshould be like eventhub related string or service bus related string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll refactor the implementation based on your feedback:
Key changes:
- Simplify credential resolution to only use properties (remove azureTokenCredentialResolver parameter from resolveTokenCredential)
- Support both global (
spring.cloud.azure.credential.token-credential-bean-name) and service-specific (spring.cloud.azure.eventhubs.credential.token-credential-bean-name,spring.cloud.azure.servicebus.credential.token-credential-bean-name) properties with service-specific taking precedence - Replace all 3 test files with single comprehensive test that verifies the property mechanism works (using the custom credential bean)
- Use imports everywhere instead of fully qualified class names
The implementation will look up the TokenCredential bean from Spring context using the bean name specified in properties, matching the pattern used in ServiceBus Messaging AutoConfiguration.
|
Closing this PR. Use this one instead: #47470 |
Description
Spring Cloud Stream Binder for EventHubs and ServiceBus ignored the
token-credential-bean-nameproperty, always using the default credential regardless of user configuration. Additionally, EventHubs Messaging AutoConfiguration lacked credential support that was present in ServiceBus Messaging AutoConfiguration.This fix enables users to configure custom TokenCredential beans via the
token-credential-bean-nameproperties for both Spring Cloud Stream Binder and Spring Messaging applications.Root Cause
@Qualifier(DEFAULT_TOKEN_CREDENTIAL_BEAN_NAME), preventing custom credential resolution via thetoken-credential-bean-namepropertyChanges Made
Stream Binder Fix
Modified
EventHubsBinderConfigurationandServiceBusBinderConfigurationto:ObjectProvider<AzureEventHubsProperties>/ObjectProvider<AzureServiceBusProperties>token-credential-bean-nameproperty from service-specific or global configurationspring.cloud.azure.credential.token-credential-bean-name) and service-specific (spring.cloud.azure.eventhubs.credential.token-credential-bean-name,spring.cloud.azure.servicebus.credential.token-credential-bean-name) propertiesMessaging AutoConfiguration Enhancement
Modified
AzureEventHubsMessagingAutoConfigurationto match ServiceBus implementation:defaultEventHubsNamespaceProcessorFactoryanddefaultEventHubsNamespaceProducerFactoryObjectProvider<AzureTokenCredentialResolver>andObjectProvider<TokenCredential>parameters to factory bean methodssetDefaultCredential()andsetTokenCredentialResolver()on the factoriesTokenCredential,AzureTokenCredentialResolver)This provides consistency across EventHubs and ServiceBus for both Stream Binder and Spring Messaging layers.
Testing
Integration-style tests added:
EventHubsBinderConfigurationTests.tokenCredentialBeanNamePropertyShouldTakeEffect(): Verifiesspring.cloud.azure.eventhubs.credential.token-credential-bean-nameproperly resolves and uses custom credential bean in Stream BinderServiceBusBinderConfigurationTests.tokenCredentialBeanNamePropertyShouldTakeEffect(): Verifiesspring.cloud.azure.servicebus.credential.token-credential-bean-nameproperly resolves and uses custom credential bean in Stream BinderAzureEventHubsMessagingAutoConfigurationTests.tokenCredentialBeanNamePropertyShouldTakeEffect(): Verifiesspring.cloud.azure.credential.token-credential-bean-nameproperly resolves and uses custom credential bean in Messaging layerAll tests verify that the custom credential bean is properly injected into factories and used for authentication when the property is configured.
Test Results:
Usage
Users can now configure custom TokenCredential beans for both Stream Binder and Messaging applications:
Service-specific configuration (takes precedence):
Global configuration:
spring.cloud.azure.credential.token-credential-bean-name=myCustomCredentialAll SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines
Original prompt
token-credential-bean-nameproperty #47285✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.