Class AuthenticationFactory

java.lang.Object
org.apache.pulsar.client.api.v5.auth.AuthenticationFactory

public final class AuthenticationFactory extends Object
Factory for creating common authentication providers.
  • Method Details

    • token

      public static Authentication token(String token)
      Create token-based authentication with a static token.
      Parameters:
      token - the JWT or other authentication token string
      Returns:
      an Authentication instance configured with the given token
    • token

      public static Authentication token(Supplier<String> tokenSupplier)
      Create token-based authentication with a dynamic token supplier.

      The supplier is invoked each time the client needs to authenticate, allowing for token refresh without recreating the client.

      Parameters:
      tokenSupplier - a supplier that provides the current authentication token
      Returns:
      an Authentication instance that retrieves tokens from the supplier
    • tls

      public static Authentication tls()
      Create the built-in TLS mutual-authentication marker plugin (PIP-478).

      This plugin carries no TLS material of its own: it only advertises the "tls" authentication method so the broker authenticates from the client certificate presented during the TLS handshake. Configure the client certificate, private key, and trust material through the client builder's tlsPolicy(...) (e.g. TlsPolicy.pem(trustCerts, certFile, keyFile)); the transport reads its material from the client TLS factory.

      Returns:
      an Authentication instance that advertises the "tls" method
    • create

      public static Authentication create(String authPluginClassName, String authParamsString) throws PulsarClientException
      Create an authentication provider by plugin class name and parameter string.
      Parameters:
      authPluginClassName - the fully qualified class name of the authentication plugin
      authParamsString - the authentication parameters as a serialized string
      Returns:
      an Authentication instance created from the specified plugin
      Throws:
      PulsarClientException - if the plugin class cannot be loaded or instantiated
    • create

      public static Authentication create(String authPluginClassName, Map<String,String> authParams) throws PulsarClientException
      Create an authentication provider by plugin class name and parameter map.
      Parameters:
      authPluginClassName - the fully qualified class name of the authentication plugin
      authParams - the authentication parameters as key-value pairs
      Returns:
      an Authentication instance created from the specified plugin
      Throws:
      PulsarClientException - if the plugin class cannot be loaded or instantiated