Search in sources :

Example 1 with AuthenticationException

use of org.apache.pulsar.client.api.PulsarClientException.AuthenticationException in project pulsar by apache.

the class AuthLogsTest method binaryEndpoint.

@Test
public void binaryEndpoint() throws Exception {
    log.info("LOG_TEST_SUCCESS_CLIENT should succeeed both client");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.pass")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
    }
    log.info("LOG_TEST_PRODUCER_AUTHN_FAIL");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("fail.ignored")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create()) {
        fail("Should fail auth");
    } catch (AuthenticationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_PRODUCER_AUTHN_ERROR");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("error.ignored")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create()) {
        fail("Should fail auth");
    } catch (AuthenticationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CONSUMER_AUTHN_FAIL");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("fail.ignored")).build();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
        fail("Should fail auth");
    } catch (AuthenticationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CONSUMER_AUTHN_ERROR");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("error.ignored")).build();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
        fail("Should fail auth");
    } catch (AuthenticationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_PRODUCER_AUTHZ_FAIL");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.fail")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create()) {
        fail("Should fail auth");
    } catch (AuthorizationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_PRODUCER_AUTHZ_ERROR");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.error")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create()) {
        fail("Should fail auth");
    } catch (AuthorizationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CONSUMER_AUTHZ_FAIL");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.fail")).build();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
        fail("Should fail auth");
    } catch (AuthorizationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CONSUMER_AUTHZ_ERROR");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.error")).build();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
        fail("Should fail auth");
    } catch (AuthorizationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CLIENT_DONE");
}
Also used : AuthenticationException(org.apache.pulsar.client.api.PulsarClientException.AuthenticationException) AuthorizationException(org.apache.pulsar.client.api.PulsarClientException.AuthorizationException) PulsarClient(org.apache.pulsar.client.api.PulsarClient) Test(org.testng.annotations.Test)

Example 2 with AuthenticationException

use of org.apache.pulsar.client.api.PulsarClientException.AuthenticationException in project pulsar by yahoo.

the class AuthLogsTest method binaryEndpoint.

@Test
public void binaryEndpoint() throws Exception {
    log.info("LOG_TEST_SUCCESS_CLIENT should succeeed both client");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.pass")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
    }
    log.info("LOG_TEST_PRODUCER_AUTHN_FAIL");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("fail.ignored")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create()) {
        fail("Should fail auth");
    } catch (AuthenticationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_PRODUCER_AUTHN_ERROR");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("error.ignored")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create()) {
        fail("Should fail auth");
    } catch (AuthenticationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CONSUMER_AUTHN_FAIL");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("fail.ignored")).build();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
        fail("Should fail auth");
    } catch (AuthenticationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CONSUMER_AUTHN_ERROR");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("error.ignored")).build();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
        fail("Should fail auth");
    } catch (AuthenticationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_PRODUCER_AUTHZ_FAIL");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.fail")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create()) {
        fail("Should fail auth");
    } catch (AuthorizationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_PRODUCER_AUTHZ_ERROR");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.error")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create()) {
        fail("Should fail auth");
    } catch (AuthorizationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CONSUMER_AUTHZ_FAIL");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.fail")).build();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
        fail("Should fail auth");
    } catch (AuthorizationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CONSUMER_AUTHZ_ERROR");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.error")).build();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
        fail("Should fail auth");
    } catch (AuthorizationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CLIENT_DONE");
}
Also used : AuthenticationException(org.apache.pulsar.client.api.PulsarClientException.AuthenticationException) AuthorizationException(org.apache.pulsar.client.api.PulsarClientException.AuthorizationException) PulsarClient(org.apache.pulsar.client.api.PulsarClient) Test(org.testng.annotations.Test)

Example 3 with AuthenticationException

use of org.apache.pulsar.client.api.PulsarClientException.AuthenticationException in project incubator-pulsar by apache.

the class AuthLogsTest method binaryEndpoint.

@Test
public void binaryEndpoint() throws Exception {
    log.info("LOG_TEST_SUCCESS_CLIENT should succeeed both client");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.pass")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
    }
    log.info("LOG_TEST_PRODUCER_AUTHN_FAIL");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("fail.ignored")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create()) {
        fail("Should fail auth");
    } catch (AuthenticationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_PRODUCER_AUTHN_ERROR");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("error.ignored")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create()) {
        fail("Should fail auth");
    } catch (AuthenticationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CONSUMER_AUTHN_FAIL");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("fail.ignored")).build();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
        fail("Should fail auth");
    } catch (AuthenticationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CONSUMER_AUTHN_ERROR");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("error.ignored")).build();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
        fail("Should fail auth");
    } catch (AuthenticationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_PRODUCER_AUTHZ_FAIL");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.fail")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create()) {
        fail("Should fail auth");
    } catch (AuthorizationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_PRODUCER_AUTHZ_ERROR");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.error")).build();
        Producer<byte[]> producer = client.newProducer().topic("foobar").create()) {
        fail("Should fail auth");
    } catch (AuthorizationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CONSUMER_AUTHZ_FAIL");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.fail")).build();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
        fail("Should fail auth");
    } catch (AuthorizationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CONSUMER_AUTHZ_ERROR");
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).authentication(new MockAuthentication("pass.error")).build();
        Consumer<byte[]> consumer = client.newConsumer().topic("foobar").subscriptionName("foobar").subscribe()) {
        fail("Should fail auth");
    } catch (AuthorizationException ae) {
    /* expected */
    }
    log.info("LOG_TEST_CLIENT_DONE");
}
Also used : AuthenticationException(org.apache.pulsar.client.api.PulsarClientException.AuthenticationException) AuthorizationException(org.apache.pulsar.client.api.PulsarClientException.AuthorizationException) PulsarClient(org.apache.pulsar.client.api.PulsarClient) Test(org.testng.annotations.Test)

Aggregations

PulsarClient (org.apache.pulsar.client.api.PulsarClient)3 AuthenticationException (org.apache.pulsar.client.api.PulsarClientException.AuthenticationException)3 AuthorizationException (org.apache.pulsar.client.api.PulsarClientException.AuthorizationException)3 Test (org.testng.annotations.Test)3