use of org.apache.pulsar.client.api.PulsarClientException.AuthorizationException 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");
}
use of org.apache.pulsar.client.api.PulsarClientException.AuthorizationException 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");
}
use of org.apache.pulsar.client.api.PulsarClientException.AuthorizationException 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");
}
Aggregations