|
4 | 4 |
|
5 | 5 | import org.apache.pulsar.client.admin.PulsarAdminBuilder; |
6 | 6 |
|
| 7 | +/** |
| 8 | + * Strategy interface for applying and validating authentication settings used to connect to Apache Pulsar. |
| 9 | + * <p> |
| 10 | + * Implementations of this interface encapsulate the behavior required for a specific Pulsar |
| 11 | + * authentication scheme, such as no authentication, basic authentication, or JWT-based authentication. |
| 12 | + * They are responsible for: |
| 13 | + * </p> |
| 14 | + * <ul> |
| 15 | + * <li>validating that all required authentication-related configuration values are present and well-formed, and</li> |
| 16 | + * <li>configuring a {@link PulsarAdminBuilder} with the authentication mechanism expected by Pulsar.</li> |
| 17 | + * </ul> |
| 18 | + * |
| 19 | + * <p> |
| 20 | + * The {@code config} map contains connection properties associated with a Pulsar destination. |
| 21 | + * Implementations may read authentication-specific keys from this map, such as usernames, |
| 22 | + * passwords, or tokens. |
| 23 | + * </p> |
| 24 | + */ |
7 | 25 | public interface PulsarAuthHandler { |
| 26 | + |
| 27 | + /** |
| 28 | + * Configures the provided {@link PulsarAdminBuilder} with the authentication settings |
| 29 | + * required by this handler. |
| 30 | + * <p> |
| 31 | + * Implementations may add authentication credentials or other related settings to the builder. |
| 32 | + * This method assumes that the supplied configuration has already been validated. |
| 33 | + * </p> |
| 34 | + * |
| 35 | + * @param builder the Pulsar admin builder to configure; must not be {@code null} |
| 36 | + * @param config the Pulsar connection configuration containing authentication properties; |
| 37 | + * must not be {@code null} |
| 38 | + */ |
8 | 39 | void configure(PulsarAdminBuilder builder, Map<String, Object> config); |
9 | 40 |
|
| 41 | + /** |
| 42 | + * Validates the authentication-related configuration required by this handler. |
| 43 | + * <p> |
| 44 | + * Implementations should verify that required configuration keys are present and that their |
| 45 | + * values are valid for the corresponding authentication scheme. If validation fails, an |
| 46 | + * {@link IllegalArgumentException} should be thrown with a descriptive message. |
| 47 | + * </p> |
| 48 | + * |
| 49 | + * @param config the Pulsar connection configuration to validate; must not be {@code null} |
| 50 | + * @throws IllegalArgumentException if required configuration values are missing, blank, or invalid |
| 51 | + */ |
10 | 52 | void validate(Map<String, Object> config) throws IllegalArgumentException; |
11 | 53 |
|
| 54 | + /** |
| 55 | + * Utility method to check whether a configuration value is missing or blank. |
| 56 | + * <p> |
| 57 | + * A value is considered missing if the map does not contain the key, if the associated value |
| 58 | + * is {@code null}, or if the string representation of the value is blank after trimming. |
| 59 | + * </p> |
| 60 | + * |
| 61 | + * @param config the configuration map to inspect; must not be {@code null} |
| 62 | + * @param key the configuration key to look up |
| 63 | + * @return {@code true} if the key is absent, mapped to {@code null}, or mapped to a blank value; |
| 64 | + * {@code false} otherwise |
| 65 | + */ |
12 | 66 | default boolean isConfigValueMissing(Map<String, ?> config, String key) { |
13 | 67 | return !config.containsKey(key) || |
14 | 68 | config.get(key) == null || |
|
0 commit comments