|
103 | 103 | import org.apache.pulsar.client.api.SubscriptionInitialPosition;
|
104 | 104 | import org.apache.pulsar.client.api.SubscriptionMode;
|
105 | 105 | import org.apache.pulsar.client.api.SubscriptionType;
|
| 106 | +import org.apache.pulsar.client.impl.ClientBuilderImpl; |
106 | 107 | import org.apache.pulsar.client.impl.ClientCnx;
|
107 | 108 | import org.apache.pulsar.client.impl.ConnectionPool;
|
108 | 109 | import org.apache.pulsar.client.impl.PulsarServiceNameResolver;
|
@@ -1943,5 +1944,49 @@ public void close() {
|
1943 | 1944 | }
|
1944 | 1945 | }
|
1945 | 1946 | }
|
| 1947 | + |
| 1948 | + @Test |
| 1949 | + public void testTlsWithAuthParams() throws Exception { |
| 1950 | + final String topicName = "persistent://prop/ns-abc/newTopic"; |
| 1951 | + final String subName = "newSub"; |
| 1952 | + Authentication auth; |
| 1953 | + |
| 1954 | + Set<String> providers = new HashSet<>(); |
| 1955 | + providers.add("org.apache.pulsar.broker.authentication.AuthenticationProviderTls"); |
| 1956 | + |
| 1957 | + conf.setAuthenticationEnabled(true); |
| 1958 | + conf.setAuthenticationProviders(providers); |
| 1959 | + conf.setBrokerServicePortTls(Optional.of(0)); |
| 1960 | + conf.setWebServicePortTls(Optional.of(0)); |
| 1961 | + conf.setTlsCertificateFilePath(BROKER_CERT_FILE_PATH); |
| 1962 | + conf.setTlsKeyFilePath(BROKER_KEY_FILE_PATH); |
| 1963 | + conf.setTlsAllowInsecureConnection(false); |
| 1964 | + conf.setTlsTrustCertsFilePath(CA_CERT_FILE_PATH); |
| 1965 | + conf.setNumExecutorThreadPoolSize(5); |
| 1966 | + restartBroker(); |
| 1967 | + |
| 1968 | + String authParam = String.format("tlsCertFile:%s,tlsKeyFile:%s", getTlsFileForClient("admin.cert"), |
| 1969 | + getTlsFileForClient("admin.key-pk8")); |
| 1970 | + String authClassName = "org.apache.pulsar.client.impl.auth.AuthenticationTls"; |
| 1971 | + ClientConfigurationData conf = new ClientConfigurationData(); |
| 1972 | + conf.setServiceUrl(brokerUrlTls.toString()); |
| 1973 | + conf.setAuthParams(authParam); |
| 1974 | + conf.setAuthPluginClassName(authClassName); |
| 1975 | + conf.setTlsAllowInsecureConnection(true); |
| 1976 | + |
| 1977 | + PulsarClient pulsarClient = null; |
| 1978 | + try { |
| 1979 | + pulsarClient = (new ClientBuilderImpl(conf)).build(); |
| 1980 | + |
| 1981 | + @Cleanup |
| 1982 | + Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName) |
| 1983 | + .subscribe(); |
| 1984 | + } catch (Exception e) { |
| 1985 | + fail("should not fail"); |
| 1986 | + } finally { |
| 1987 | + pulsarClient.close(); |
| 1988 | + } |
| 1989 | + } |
| 1990 | + |
1946 | 1991 | }
|
1947 | 1992 |
|
0 commit comments