Skip to content

Commit 2d9aead

Browse files
Copilotsaragluna
andcommitted
Add comprehensive documentation for Kafka authentication refactoring
- Add package-info.java documenting authentication architecture - Enhance AbstractKafkaPropertiesBeanPostProcessor JavaDoc - Document authentication flow and strategy pattern usage - Provide example configuration for OAuth2 authentication Co-authored-by: saragluna <[email protected]>
1 parent c4cbb50 commit 2d9aead

File tree

2 files changed

+90
-3
lines changed

2 files changed

+90
-3
lines changed

sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/kafka/AbstractKafkaPropertiesBeanPostProcessor.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,39 @@
2828

2929
/**
3030
* Abstract base class for Kafka properties BeanPostProcessors.
31-
* This class provides common functionality for configuring Kafka authentication
32-
* using different strategies (OAuth2, connection string, etc.).
31+
* <p>
32+
* This class provides common functionality for configuring Kafka authentication for Azure Event Hubs
33+
* using different strategies. It uses the Strategy pattern to delegate authentication configuration
34+
* to pluggable {@link KafkaAuthenticationStrategy} implementations.
35+
* </p>
36+
* <p>
37+
* The processor intercepts Kafka properties beans during Spring bean initialization and applies
38+
* authentication configuration to producer, consumer, and admin properties based on the configured
39+
* strategy.
40+
* </p>
41+
* <p>
42+
* <b>Authentication Flow:</b>
43+
* <ol>
44+
* <li>Bean post processor detects Kafka properties beans during initialization</li>
45+
* <li>Retrieves AzureGlobalProperties for credential configuration</li>
46+
* <li>For each set of properties (producer/consumer/admin):
47+
* <ul>
48+
* <li>Checks if authentication strategy should be applied via {@link KafkaAuthenticationStrategy#shouldApply}</li>
49+
* <li>If applicable, applies authentication via {@link KafkaAuthenticationStrategy#applyAuthentication}</li>
50+
* <li>Configures Kafka user agent for telemetry</li>
51+
* <li>Clears Azure-specific properties from raw properties map</li>
52+
* </ul>
53+
* </li>
54+
* </ol>
55+
* </p>
56+
* <p>
57+
* By default, uses {@link KafkaOAuth2AuthenticationStrategy} for OAuth2/Microsoft Entra ID authentication.
58+
* Subclasses can provide alternative strategies via the constructor.
59+
* </p>
3360
*
34-
* @param <T> the type of Kafka properties bean to process
61+
* @param <T> the type of Kafka properties bean to process (e.g., {@link KafkaProperties})
62+
* @see KafkaAuthenticationStrategy
63+
* @see KafkaOAuth2AuthenticationStrategy
3564
*/
3665
abstract class AbstractKafkaPropertiesBeanPostProcessor<T> implements BeanPostProcessor, ApplicationContextAware {
3766

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
/**
5+
* Authentication strategies for Azure Event Hubs Kafka support in Spring Cloud Azure.
6+
*
7+
* <h2>Overview</h2>
8+
* This package contains authentication strategy implementations for configuring Kafka clients
9+
* to connect to Azure Event Hubs using different authentication methods.
10+
*
11+
* <h2>Architecture</h2>
12+
* The authentication configuration uses the Strategy pattern to support different authentication methods:
13+
* <ul>
14+
* <li>{@link com.azure.spring.cloud.autoconfigure.implementation.kafka.authentication.KafkaAuthenticationStrategy} -
15+
* The strategy interface that defines how authentication should be applied</li>
16+
* <li>{@link com.azure.spring.cloud.autoconfigure.implementation.kafka.authentication.KafkaOAuth2AuthenticationStrategy} -
17+
* Implementation for OAuth2 authentication using Microsoft Entra ID</li>
18+
* </ul>
19+
*
20+
* <h2>Supported Authentication Methods</h2>
21+
*
22+
* <h3>OAuth2 Authentication (Microsoft Entra ID)</h3>
23+
* The {@code KafkaOAuth2AuthenticationStrategy} configures SASL/OAUTHBEARER authentication
24+
* for connecting to Azure Event Hubs using Microsoft Entra ID credentials.
25+
*
26+
* <p><b>Configuration Requirements:</b></p>
27+
* <ul>
28+
* <li>Bootstrap server must be an Event Hubs namespace endpoint (ends with :9093)</li>
29+
* <li>Security protocol should be SASL_SSL (or not configured)</li>
30+
* <li>SASL mechanism should be OAUTHBEARER (or not configured)</li>
31+
* </ul>
32+
*
33+
* <p><b>Properties Configured:</b></p>
34+
* <ul>
35+
* <li>{@code security.protocol} = SASL_SSL</li>
36+
* <li>{@code sasl.mechanism} = OAUTHBEARER</li>
37+
* <li>{@code sasl.jaas.config} = JAAS configuration with Azure credentials</li>
38+
* <li>{@code sasl.login.callback.handler.class} = KafkaOAuth2AuthenticateCallbackHandler</li>
39+
* </ul>
40+
*
41+
* <h2>Usage</h2>
42+
* The authentication strategies are used automatically by the Kafka bean post processors:
43+
* <ul>
44+
* <li>{@code KafkaPropertiesBeanPostProcessor} - For Spring Boot Kafka auto-configuration</li>
45+
* <li>{@code KafkaBinderConfigurationPropertiesBeanPostProcessor} - For Spring Cloud Stream Kafka binder</li>
46+
* </ul>
47+
*
48+
* <h2>Example Configuration</h2>
49+
* <pre>{@code
50+
* spring.kafka.bootstrap-servers=mynamespace.servicebus.windows.net:9093
51+
* spring.cloud.azure.credential.client-id=<client-id>
52+
* spring.cloud.azure.credential.client-secret=<client-secret>
53+
* spring.cloud.azure.profile.tenant-id=<tenant-id>
54+
* }</pre>
55+
*
56+
* @since 6.1.0
57+
*/
58+
package com.azure.spring.cloud.autoconfigure.implementation.kafka.authentication;

0 commit comments

Comments
 (0)