use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.
the class PersistentTopicsTest method testGetMessageById.
@Test
public void testGetMessageById() throws Exception {
TenantInfoImpl tenantInfo = new TenantInfoImpl(Sets.newHashSet("role1", "role2"), Sets.newHashSet("test"));
admin.tenants().createTenant("tenant-xyz", tenantInfo);
admin.namespaces().createNamespace("tenant-xyz/ns-abc", Sets.newHashSet("test"));
final String topicName1 = "persistent://tenant-xyz/ns-abc/testGetMessageById1";
final String topicName2 = "persistent://tenant-xyz/ns-abc/testGetMessageById2";
admin.topics().createNonPartitionedTopic(topicName1);
admin.topics().createNonPartitionedTopic(topicName2);
@Cleanup ProducerBase<byte[]> producer1 = (ProducerBase<byte[]>) pulsarClient.newProducer().topic(topicName1).enableBatching(false).create();
String data1 = "test1";
MessageIdImpl id1 = (MessageIdImpl) producer1.send(data1.getBytes());
@Cleanup ProducerBase<byte[]> producer2 = (ProducerBase<byte[]>) pulsarClient.newProducer().topic(topicName2).enableBatching(false).create();
String data2 = "test2";
MessageIdImpl id2 = (MessageIdImpl) producer2.send(data2.getBytes());
Message<byte[]> message1 = admin.topics().getMessageById(topicName1, id1.getLedgerId(), id1.getEntryId());
Assert.assertEquals(message1.getData(), data1.getBytes());
Message<byte[]> message2 = admin.topics().getMessageById(topicName2, id2.getLedgerId(), id2.getEntryId());
Assert.assertEquals(message2.getData(), data2.getBytes());
Message<byte[]> message3 = null;
try {
message3 = admin.topics().getMessageById(topicName2, id1.getLedgerId(), id1.getEntryId());
Assert.fail();
} catch (Exception e) {
Assert.assertNull(message3);
}
Message<byte[]> message4 = null;
try {
message4 = admin.topics().getMessageById(topicName1, id2.getLedgerId(), id2.getEntryId());
Assert.fail();
} catch (Exception e) {
Assert.assertNull(message4);
}
}
use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.
the class AdminApiTlsAuthTest method testUnauthorizedUserAsOriginalPrincipal.
@Test
public void testUnauthorizedUserAsOriginalPrincipal() throws Exception {
try (PulsarAdmin admin = buildAdminClient("admin")) {
admin.tenants().createTenant("tenant1", new TenantInfoImpl(ImmutableSet.of("proxy", "user1"), ImmutableSet.of("test")));
admin.namespaces().createNamespace("tenant1/ns1");
}
WebTarget root = buildWebClient("proxy");
try {
root.path("/admin/v2/namespaces").path("tenant1").request(MediaType.APPLICATION_JSON).header("X-Original-Principal", "user2").get(new GenericType<List<String>>() {
});
Assert.fail("user2 should not be authorized");
} catch (NotAuthorizedException e) {
// expected
}
}
use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.
the class AdminApiTlsAuthTest method testProxyRoleCantListNamespacesEvenWithAccess.
@Test
public void testProxyRoleCantListNamespacesEvenWithAccess() throws Exception {
try (PulsarAdmin admin = buildAdminClient("admin")) {
admin.tenants().createTenant("tenant1", new TenantInfoImpl(ImmutableSet.of("proxy"), ImmutableSet.of("test")));
admin.namespaces().createNamespace("tenant1/ns1");
}
try (PulsarAdmin admin = buildAdminClient("proxy")) {
admin.namespaces().getNamespaces("tenant1");
Assert.fail("Shouldn't be able to list namespaces");
} catch (PulsarAdminException.NotAuthorizedException e) {
// expected
}
}
use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.
the class AdminApiTlsAuthTest method testUnauthorizedUserAsOriginalPrincipalProxyIsSuperUser.
@Test
public void testUnauthorizedUserAsOriginalPrincipalProxyIsSuperUser() throws Exception {
try (PulsarAdmin admin = buildAdminClient("admin")) {
admin.tenants().createTenant("tenant1", new TenantInfoImpl(ImmutableSet.of("user1"), ImmutableSet.of("test")));
admin.namespaces().createNamespace("tenant1/ns1");
}
WebTarget root = buildWebClient("superproxy");
try {
root.path("/admin/v2/namespaces").path("tenant1").request(MediaType.APPLICATION_JSON).header("X-Original-Principal", "user2").get(new GenericType<List<String>>() {
});
Assert.fail("user2 should not be authorized");
} catch (NotAuthorizedException e) {
// expected
}
}
use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.
the class AdminApiTlsAuthTest method testProxyUserViaProxy.
@Test
public void testProxyUserViaProxy() throws Exception {
try (PulsarAdmin admin = buildAdminClient("admin")) {
admin.tenants().createTenant("tenant1", new TenantInfoImpl(ImmutableSet.of("proxy"), ImmutableSet.of("test")));
admin.namespaces().createNamespace("tenant1/ns1");
}
WebTarget root = buildWebClient("superproxy");
try {
root.path("/admin/v2/namespaces").path("tenant1").request(MediaType.APPLICATION_JSON).header("X-Original-Principal", "proxy").get(new GenericType<List<String>>() {
});
Assert.fail("proxy should not be authorized");
} catch (NotAuthorizedException e) {
// expected
}
}
Aggregations