Search in sources :

Example 11 with AuthenticationTls

use of org.apache.pulsar.client.impl.auth.AuthenticationTls in project incubator-pulsar by apache.

the class ProxyWithAuthorizationNegTest method createPulsarClient.

@SuppressWarnings("deprecation")
private PulsarClient createPulsarClient(String proxyServiceUrl) throws PulsarClientException {
    Map<String, String> authParams = Maps.newHashMap();
    authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH);
    authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH);
    Authentication authTls = new AuthenticationTls();
    authTls.configure(authParams);
    return PulsarClient.builder().serviceUrl(proxyServiceUrl).statsInterval(0, TimeUnit.SECONDS).tlsTrustCertsFilePath(TLS_PROXY_TRUST_CERT_FILE_PATH).allowTlsInsecureConnection(true).authentication(authTls).enableTls(true).build();
}
Also used : AuthenticationTls(org.apache.pulsar.client.impl.auth.AuthenticationTls) Authentication(org.apache.pulsar.client.api.Authentication)

Example 12 with AuthenticationTls

use of org.apache.pulsar.client.impl.auth.AuthenticationTls in project incubator-pulsar by apache.

the class ProxyWithAuthorizationNegTest method createAdminClient.

protected final void createAdminClient() throws Exception {
    Map<String, String> authParams = Maps.newHashMap();
    authParams.put("tlsCertFile", TLS_SUPERUSER_CLIENT_CERT_FILE_PATH);
    authParams.put("tlsKeyFile", TLS_SUPERUSER_CLIENT_KEY_FILE_PATH);
    Authentication authTls = new AuthenticationTls();
    authTls.configure(authParams);
    org.apache.pulsar.client.api.ClientConfiguration clientConf = new org.apache.pulsar.client.api.ClientConfiguration();
    clientConf.setStatsInterval(0, TimeUnit.SECONDS);
    clientConf.setTlsTrustCertsFilePath(TLS_BROKER_TRUST_CERT_FILE_PATH);
    clientConf.setTlsAllowInsecureConnection(true);
    clientConf.setAuthentication(authTls);
    clientConf.setUseTls(true);
    admin = spy(new PulsarAdmin(brokerUrlTls, clientConf));
}
Also used : AuthenticationTls(org.apache.pulsar.client.impl.auth.AuthenticationTls) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Authentication(org.apache.pulsar.client.api.Authentication)

Example 13 with AuthenticationTls

use of org.apache.pulsar.client.impl.auth.AuthenticationTls in project incubator-pulsar by apache.

the class ProxyWithAuthorizationTest method createAdminClient.

protected final void createAdminClient() throws Exception {
    Map<String, String> authParams = Maps.newHashMap();
    authParams.put("tlsCertFile", TLS_SUPERUSER_CLIENT_CERT_FILE_PATH);
    authParams.put("tlsKeyFile", TLS_SUPERUSER_CLIENT_KEY_FILE_PATH);
    Authentication authTls = new AuthenticationTls();
    authTls.configure(authParams);
    org.apache.pulsar.client.api.ClientConfiguration clientConf = new org.apache.pulsar.client.api.ClientConfiguration();
    clientConf.setStatsInterval(0, TimeUnit.SECONDS);
    clientConf.setTlsTrustCertsFilePath(TLS_PROXY_TRUST_CERT_FILE_PATH);
    clientConf.setTlsAllowInsecureConnection(true);
    clientConf.setAuthentication(authTls);
    clientConf.setUseTls(true);
    admin = spy(new PulsarAdmin(brokerUrlTls, clientConf));
}
Also used : AuthenticationTls(org.apache.pulsar.client.impl.auth.AuthenticationTls) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Authentication(org.apache.pulsar.client.api.Authentication)

Example 14 with AuthenticationTls

use of org.apache.pulsar.client.impl.auth.AuthenticationTls in project incubator-pulsar by apache.

the class AuthenticatedProducerConsumerTest method testInternalServerExceptionOnLookup.

/**
 * verifies that topicLookup/PartitionMetadataLookup gives InternalServerError(500) instead 401(auth_failed) on
 * unknown-exception failure
 *
 * @throws Exception
 */
@Test
public void testInternalServerExceptionOnLookup() throws Exception {
    log.info("-- Starting {} test --", methodName);
    Map<String, String> authParams = new HashMap<>();
    authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH);
    authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH);
    Authentication authTls = new AuthenticationTls();
    authTls.configure(authParams);
    internalSetup(authTls);
    admin.clusters().createCluster("use", new ClusterData(brokerUrl.toString(), brokerUrlTls.toString(), "pulsar://localhost:" + BROKER_PORT, "pulsar+ssl://localhost:" + BROKER_PORT_TLS));
    admin.properties().createProperty("my-property", new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet("use")));
    String namespace = "my-property/use/my-ns";
    admin.namespaces().createNamespace(namespace);
    String topic = "persistent://" + namespace + "1/topic1";
    // this will cause NPE and it should throw 500
    mockZookKeeper.shutdown();
    pulsar.getConfiguration().setSuperUserRoles(Sets.newHashSet());
    try {
        admin.persistentTopics().getPartitionedTopicMetadata(topic);
    } catch (PulsarAdminException e) {
        Assert.assertTrue(e.getCause() instanceof InternalServerErrorException);
    }
    try {
        admin.lookups().lookupTopic(topic);
    } catch (PulsarAdminException e) {
        Assert.assertTrue(e.getCause() instanceof InternalServerErrorException);
    }
}
Also used : AuthenticationTls(org.apache.pulsar.client.impl.auth.AuthenticationTls) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test)

Example 15 with AuthenticationTls

use of org.apache.pulsar.client.impl.auth.AuthenticationTls in project incubator-pulsar by apache.

the class AuthenticatedProducerConsumerTest method testTlsSyncProducerAndConsumer.

@Test(dataProvider = "batch")
public void testTlsSyncProducerAndConsumer(int batchMessageDelayMs) throws Exception {
    log.info("-- Starting {} test --", methodName);
    Map<String, String> authParams = new HashMap<>();
    authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH);
    authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH);
    Authentication authTls = new AuthenticationTls();
    authTls.configure(authParams);
    internalSetup(authTls);
    admin.properties().createProperty("my-property", new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet("use")));
    admin.namespaces().createNamespace("my-property/use/my-ns");
    testSyncProducerAndConsumer(batchMessageDelayMs);
    log.info("-- Exiting {} test --", methodName);
}
Also used : AuthenticationTls(org.apache.pulsar.client.impl.auth.AuthenticationTls) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) Test(org.testng.annotations.Test)

Aggregations

AuthenticationTls (org.apache.pulsar.client.impl.auth.AuthenticationTls)17 Authentication (org.apache.pulsar.client.api.Authentication)10 Test (org.testng.annotations.Test)10 HashMap (java.util.HashMap)7 PropertyAdmin (org.apache.pulsar.common.policies.data.PropertyAdmin)6 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)5 PulsarClient (org.apache.pulsar.client.api.PulsarClient)5 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)5 HashSet (java.util.HashSet)4 IOException (java.io.IOException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)3 Cleanup (lombok.Cleanup)3 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)3 PersistenceException (org.apache.pulsar.broker.service.BrokerServiceException.PersistenceException)3 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)3 URI (java.net.URI)1 URL (java.net.URL)1