-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Refactor Kafka authentication using strategy and template method patterns #47209
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
base: main
Are you sure you want to change the base?
Conversation
- Create KafkaAuthenticationConfigurer interface for strategy pattern - Implement OAuth2AuthenticationConfigurer to handle OAuth2/OAUTHBEARER auth - Refactor AbstractKafkaPropertiesBeanPostProcessor to use the new strategy - All existing tests pass without modification Co-authored-by: saragluna <31124698+saragluna@users.noreply.github.com>
- Create README.md explaining architecture and authentication methods - Add detailed Javadoc to all auto-configuration classes - Improve AbstractKafkaPropertiesBeanPostProcessor documentation - Fix checkstyle issues - All tests passing ✅ Co-authored-by: saragluna <31124698+saragluna@users.noreply.github.com>
| * Configures OAuth2 (OAUTHBEARER) authentication for Kafka using Azure Identity credentials. | ||
| * This configurer handles Azure Event Hubs for Kafka scenarios with Microsoft Entra ID authentication. | ||
| */ | ||
| class OAuth2AuthenticationConfigurer implements KafkaAuthenticationConfigurer { |
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.
There should be annother ConnectionStringAuthenticationConfigurer, and it's also a strategy, the common logic should be extracted to a common template. @copilot
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.
@copilot, there should be annother ConnectionStringAuthenticationConfigurer, and it's also a strategy, the common logic should be extracted to a common template.
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.
Done! I've created ConnectionStringAuthenticationConfigurer as a strategy and extracted common logic into AbstractKafkaAuthenticationConfigurer template class.
Changes:
AbstractKafkaAuthenticationConfigurer- Template base with common validation logic (bootstrap server checks, SASL protocol validation, property getters)ConnectionStringAuthenticationConfigurer- Implements connection string auth strategyOAuth2AuthenticationConfigurer- Refactored to extend the template- Both configurers now share common code and follow the same structure
Commit: b001273 (documentation update), e241088 (implementation)
- Create AbstractKafkaAuthenticationConfigurer as base template class - Create ConnectionStringAuthenticationConfigurer for deprecated connection string auth - Refactor OAuth2AuthenticationConfigurer to extend template - Update eventhubs.kafka.KafkaPropertiesBeanPostProcessor to use ConnectionStringAuthenticationConfigurer - All tests pass ✅ Co-authored-by: saragluna <31124698+saragluna@users.noreply.github.com>
- Document AbstractKafkaAuthenticationConfigurer template class - Add class hierarchy diagram - Update extension points with template usage examples - Document inherited methods available to subclasses Co-authored-by: saragluna <31124698+saragluna@users.noreply.github.com>
|
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:
|
Description
Spring Cloud Azure's Kafka authentication implementation was scattered across multiple packages with duplicated logic. Two authentication methods exist: OAuth2/OAUTHBEARER (recommended, uses Azure Identity) and connection string-based SASL_PLAIN (deprecated). The implementation lacked clear separation of concerns and was difficult to extend.
This PR refactors the implementation using both Strategy Pattern and Template Method Pattern to consolidate common logic and make both authentication methods follow a consistent structure.
Changes
Strategy Pattern Introduction
KafkaAuthenticationConfigurerinterface for authentication strategiesOAuth2AuthenticationConfigurerConnectionStringAuthenticationConfigurerfor connection string authenticationAbstractKafkaPropertiesBeanPostProcessorto delegate to configurersTemplate Method Pattern Implementation
AbstractKafkaAuthenticationConfigureras template base classOAuth2AuthenticationConfigurerandConnectionStringAuthenticationConfigurerextend the templateDocumentation
kafka/README.mdcovering architecture, authentication methods, and migration guideCode Organization
eventhubs.kafka.KafkaPropertiesBeanPostProcessorto useConnectionStringAuthenticationConfigurerArchitecture
Authentication Methods
OAuth2/OAUTHBEARER (Recommended)
Connection String (Deprecated)
Impact
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines
Pull request includes test coverage for the included changes.
Fixes [FEATURE REQ] Refactor Kafka support in Spring Cloud Azure #47196
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.