use of org.apache.pulsar.common.policies.data.PropertyAdmin in project incubator-pulsar by apache.
the class AuthenticatedProducerConsumerTest method testBasicArp1SyncProducerAndConsumer.
@Test(dataProvider = "batch")
public void testBasicArp1SyncProducerAndConsumer(int batchMessageDelayMs) throws Exception {
log.info("-- Starting {} test --", methodName);
AuthenticationBasic authPassword = new AuthenticationBasic();
authPassword.configure("{\"userId\":\"superUser2\",\"password\":\"superpassword\"}");
internalSetup(authPassword);
admin.properties().createProperty("my-property", new PropertyAdmin(Lists.newArrayList(), Sets.newHashSet("use")));
admin.namespaces().createNamespace("my-property/use/my-ns");
testSyncProducerAndConsumer(batchMessageDelayMs);
log.info("-- Exiting {} test --", methodName);
}
use of org.apache.pulsar.common.policies.data.PropertyAdmin 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");
}
use of org.apache.pulsar.common.policies.data.PropertyAdmin in project incubator-pulsar by apache.
the class AuthorizationProducerConsumerTest method testSubscriptionPrefixAuthorization.
@Test
public void testSubscriptionPrefixAuthorization() throws Exception {
log.info("-- Starting {} test --", methodName);
conf.setAuthorizationProvider(TestAuthorizationProviderWithSubscriptionPrefix.class.getName());
setup();
ClientConfiguration adminConf = new ClientConfiguration();
Authentication adminAuthentication = new ClientAuthentication("superUser");
adminConf.setAuthentication(adminAuthentication);
admin = spy(new PulsarAdmin(brokerUrl, adminConf));
String lookupUrl;
lookupUrl = new URI("pulsar://localhost:" + BROKER_PORT).toString();
Authentication authentication = new ClientAuthentication(clientRole);
pulsarClient = PulsarClient.builder().serviceUrl(lookupUrl).authentication(authentication).build();
admin.properties().createProperty("prop-prefix", new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet("use")));
admin.namespaces().createNamespace("prop-prefix/use/ns");
// (1) Valid subscription name will be approved by authorization service
Consumer<byte[]> consumer = pulsarClient.newConsumer().topic("persistent://prop-prefix/use/ns/t1").subscriptionName(clientRole + "-sub1").subscribe();
consumer.close();
// (2) InValid subscription name will be rejected by authorization service
try {
consumer = pulsarClient.newConsumer().topic("persistent://prop-prefix/use/ns/t1").subscriptionName("sub1").subscribe();
Assert.fail("should have failed with authorization error");
} catch (PulsarClientException.AuthorizationException pa) {
// Ok
}
log.info("-- Exiting {} test --", methodName);
}
use of org.apache.pulsar.common.policies.data.PropertyAdmin in project incubator-pulsar by apache.
the class BrokerServiceLookupTest method testPartitionedMetadataWithDeprecatedVersion.
@Test
public void testPartitionedMetadataWithDeprecatedVersion() throws Exception {
final String cluster = "use2";
final String property = "my-property2";
final String namespace = "my-ns";
final String topicName = "my-partitioned";
final int totalPartitions = 10;
final TopicName dest = TopicName.get("persistent", property, cluster, namespace, topicName);
admin.clusters().createCluster(cluster, new ClusterData("http://127.0.0.1:" + BROKER_WEBSERVICE_PORT, null, null, null));
admin.properties().createProperty(property, new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet(cluster)));
admin.namespaces().createNamespace(property + "/" + cluster + "/" + namespace);
admin.persistentTopics().createPartitionedTopic(dest.toString(), totalPartitions);
stopBroker();
conf.setClientLibraryVersionCheckEnabled(true);
startBroker();
URI brokerServiceUrl = new URI(pulsar.getWebServiceAddress());
URL url = brokerServiceUrl.toURL();
String path = String.format("admin/%s/partitions", dest.getLookupName());
AsyncHttpClient httpClient = getHttpClient("Pulsar-Java-1.20");
PartitionedTopicMetadata metadata = getPartitionedMetadata(httpClient, url, path);
assertEquals(metadata.partitions, totalPartitions);
httpClient.close();
httpClient = getHttpClient("Pulsar-CPP-v1.21");
metadata = getPartitionedMetadata(httpClient, url, path);
assertEquals(metadata.partitions, totalPartitions);
httpClient.close();
httpClient = getHttpClient("Pulsar-CPP-v1.21-SNAPSHOT");
metadata = getPartitionedMetadata(httpClient, url, path);
assertEquals(metadata.partitions, totalPartitions);
httpClient.close();
httpClient = getHttpClient("");
try {
metadata = getPartitionedMetadata(httpClient, url, path);
fail("should have failed due to invalid version");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof PulsarClientException);
}
httpClient.close();
httpClient = getHttpClient("Pulsar-CPP-v1.20-SNAPSHOT");
try {
metadata = getPartitionedMetadata(httpClient, url, path);
fail("should have failed due to invalid version");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof PulsarClientException);
}
httpClient.close();
httpClient = getHttpClient("Pulsar-CPP-v1.20");
try {
metadata = getPartitionedMetadata(httpClient, url, path);
fail("should have failed due to invalid version");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof PulsarClientException);
}
httpClient.close();
}
use of org.apache.pulsar.common.policies.data.PropertyAdmin in project incubator-pulsar by apache.
the class BrokerTestBase method baseSetup.
public void baseSetup() throws Exception {
super.internalSetup();
admin.clusters().createCluster("use", new ClusterData(brokerUrl.toString()));
admin.properties().createProperty("prop", new PropertyAdmin(Lists.newArrayList("appid1"), Sets.newHashSet("use")));
admin.namespaces().createNamespace("prop/use/ns-abc");
}
Aggregations