Extend Authentication and Authorization in Pulsar
Pulsar provides a way to use custom authentication and authorization mechanisms.
Authentication​
You can use a custom authentication mechanism by providing the implementation in the form of two plugins.
- Client authentication plugin
- Proxy/Broker authentication plugin
Client authentication plugin​
For the client library, you need to implement org.apache.pulsar.client.api.Authentication
. By entering the command below, you can pass this class when you create a Pulsar client.
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar://localhost:6650")
.authentication(new MyAuthentication())
.build();
You can implement 2 interfaces on the client side:
This in turn requires you to provide the client credentials in the form of org.apache.pulsar.client.api.AuthenticationDataProvider
and also leaves the chance to return different kinds of authentication token for different types of connection or by passing a certificate chain to use for TLS.
You can find the following examples for different client authentication plugins:
Proxy/Broker authentication plugin​
On the proxy/broker side, you need to configure the corresponding plugin to validate the credentials that the client sends. The proxy and broker can support multiple authentication providers at the same time.
In conf/broker.conf
, you can choose to specify a list of valid providers:
# Authentication provider name list, which is comma separated list of class names
authenticationProviders=
For the implementation of the org.apache.pulsar.broker.authentication.AuthenticationProvider
interface, refer to here.
You can find the following examples for different broker authentication plugins: