Package org.apache.pulsar.client.api.v5.auth


package org.apache.pulsar.client.api.v5.auth
Pluggable authentication (and end-to-end encryption) types for the v5 client (PIP-478).

Authentication carries only lifecycle (configure / initializeAsync / capability / close); the credential work lives on opt-in capability interfaces the framework discovers only through Authentication.capability(Class) — never instanceof. The capabilities are segregated on two axes (transport × style):

The capability matrix
Pulsar binary protocolHTTP
Single-pass BinaryAuthDataProvider HttpAuthHeadersProvider
Multi-round challenge/response BinaryAuthChallengeHandler HttpAuthChallengeHandler

The convenience composite SinglePassAuthentication bundles the common single-pass-over-both-transports combination. All capability methods are asynchronous, so credential acquisition never blocks the Netty event loop.

Two configuration paths.

  • Programmatic — build and configure an instance yourself, then pass it to the builder's authentication(Authentication). Authentication.configure(Map) is NOT called (the instance is presumed already configured). The convenience factories in AuthenticationFactory return such instances.
  • Reflective by class name — authentication(authPluginClassName, authParams): the framework loads the class, constructs it no-arg, and calls Authentication.configure(Map) with the parsed params. A class implementing only this v5 SPI works over this path exactly like a built-in.

Binary routing rules (normative). For every plugin, ClientCnx routes as:

  1. Initial connect → BinaryAuthDataProvider; this capability is required for the binary transport — a plugin that does not expose it fails at client build with an UnsupportedAuthenticationException.
  2. The refresh sentinel (AuthData.REFRESH_AUTH_DATA_BYTES) → the current credential is re-produced through BinaryAuthDataProvider on a fresh exchange; the sentinel is filtered out and never reaches the challenge handler.
  3. Any other challenge → BinaryAuthChallengeHandler; a plugin that receives a challenge without exposing the handler fails the connection with an AuthenticationException.

The package also provides end-to-end encryption support via PublicKeyProvider (producer side) and PrivateKeyProvider (consumer side); for local PEM-file-backed setups use PemFileKeyProvider.