Search in sources :

Example 56 with PropertyAdmin

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);
}
Also used : PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) AuthenticationBasic(org.apache.pulsar.client.impl.auth.AuthenticationBasic) Test(org.testng.annotations.Test)

Example 57 with PropertyAdmin

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");
}
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)

Example 58 with PropertyAdmin

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);
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 59 with PropertyAdmin

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();
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) URL(java.net.URL) TopicName(org.apache.pulsar.common.naming.TopicName) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) Test(org.testng.annotations.Test)

Example 60 with PropertyAdmin

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");
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin)

Aggregations

PropertyAdmin (org.apache.pulsar.common.policies.data.PropertyAdmin)83 Test (org.testng.annotations.Test)60 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)29 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)13 PulsarClient (org.apache.pulsar.client.api.PulsarClient)12 BeforeMethod (org.testng.annotations.BeforeMethod)12 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)11 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)9 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)9 AuthenticationTls (org.apache.pulsar.client.impl.auth.AuthenticationTls)8 HashSet (java.util.HashSet)6 URI (java.net.URI)5 URL (java.net.URL)5 Pattern (java.util.regex.Pattern)5 PulsarService (org.apache.pulsar.broker.PulsarService)5 RestException (org.apache.pulsar.broker.web.RestException)5 Authentication (org.apache.pulsar.client.api.Authentication)5 AuthAction (org.apache.pulsar.common.policies.data.AuthAction)5 KeeperException (org.apache.zookeeper.KeeperException)5 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)4