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(String certFilePath, String keyFilePath)
      Create TLS mutual authentication.
      Parameters:
      certFilePath - the path to the client certificate file (PEM format)
      keyFilePath - the path to the client private key file (PEM format)
      Returns:
      an Authentication instance configured for TLS mutual authentication
    • 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