Search in sources :

Example 16 with AuthenticationTls

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

the class AuthenticatedProducerConsumerTest method testAuthenticationFilterNegative.

/**
 * Verifies: on 500 server error, broker invalidates session and client receives 500 correctly.
 *
 * @throws Exception
 */
@Test
public void testAuthenticationFilterNegative() 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);
    final String cluster = "use";
    final ClusterData clusterData = new ClusterData(brokerUrl.toString(), brokerUrlTls.toString(), "pulsar://localhost:" + BROKER_PORT, "pulsar+ssl://localhost:" + BROKER_PORT_TLS);
    // this will cause NPE and it should throw 500
    doReturn(null).when(pulsar).getGlobalZkCache();
    try {
        admin.clusters().createCluster(cluster, clusterData);
    } catch (PulsarAdminException e) {
        Assert.assertTrue(e.getCause() instanceof InternalServerErrorException);
    }
    log.info("-- Exiting {} test --", methodName);
}
Also used : AuthenticationTls(org.apache.pulsar.client.impl.auth.AuthenticationTls) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test)

Example 17 with AuthenticationTls

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

the class AuthenticationTlsHostnameVerificationTest method setupClient.

protected void setupClient() throws Exception {
    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);
    org.apache.pulsar.client.api.ClientConfiguration clientConf = new org.apache.pulsar.client.api.ClientConfiguration();
    clientConf.setStatsInterval(0, TimeUnit.SECONDS);
    clientConf.setTlsTrustCertsFilePath(TLS_MIM_TRUST_CERT_FILE_PATH);
    clientConf.setTlsAllowInsecureConnection(true);
    clientConf.setAuthentication(authTls);
    clientConf.setUseTls(true);
    clientConf.setTlsHostnameVerificationEnable(hostnameVerificationEnabled);
    admin = spy(new PulsarAdmin(brokerUrlTls, clientConf));
    String lookupUrl;
    lookupUrl = new URI("pulsar+ssl://" + brokerHostName + ":" + BROKER_PORT_TLS).toString();
    pulsarClient = PulsarClient.builder().serviceUrl(lookupUrl).statsInterval(0, TimeUnit.SECONDS).tlsTrustCertsFilePath(TLS_MIM_TRUST_CERT_FILE_PATH).allowTlsInsecureConnection(true).authentication(authTls).enableTls(true).enableTlsHostnameVerification(hostnameVerificationEnabled).build();
    admin.properties().createProperty("my-property", new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet("use")));
    admin.namespaces().createNamespace("my-property/use/my-ns");
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) HashMap(java.util.HashMap) URI(java.net.URI) AuthenticationTls(org.apache.pulsar.client.impl.auth.AuthenticationTls) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin)

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