Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulsar authentication param properties cause IllegalStateException with Pulsar Client 3.1.0 #38839

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
Expand All @@ -29,6 +30,7 @@
import org.apache.pulsar.client.api.ProducerBuilder;
import org.apache.pulsar.client.api.PulsarClientException.UnsupportedAuthenticationException;
import org.apache.pulsar.client.api.ReaderBuilder;
import org.apache.pulsar.common.util.ObjectMapperFactory;

import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.pulsar.listener.PulsarContainerProperties;
Expand Down Expand Up @@ -71,13 +73,23 @@ void customizeAdminBuilder(PulsarAdminBuilder adminBuilder, PulsarConnectionDeta

private void customizeAuthentication(AuthenticationConsumer authentication,
PulsarProperties.Authentication properties) {
if (StringUtils.hasText(properties.getPluginClassName())) {
if (!StringUtils.hasText(properties.getPluginClassName())) {
return;
}
try {
// sort keys for testing and readability
Map<String, String> params = new TreeMap<>(properties.getParam());
String authParamString;
try {
authentication.accept(properties.getPluginClassName(), properties.getParam());
philwebb marked this conversation as resolved.
Show resolved Hide resolved
authParamString = ObjectMapperFactory.create().writeValueAsString(params);
}
catch (UnsupportedAuthenticationException ex) {
throw new IllegalStateException("Unable to configure Pulsar authentication", ex);
catch (Exception ex) {
throw new IllegalStateException("Could not convert auth parameters to encoded string", ex);
}
authentication.accept(properties.getPluginClassName(), authParamString);
}
catch (UnsupportedAuthenticationException ex) {
throw new IllegalStateException("Unable to configure Pulsar authentication", ex);
}
}

Expand Down Expand Up @@ -158,7 +170,7 @@ private Consumer<Duration> timeoutProperty(BiConsumer<Integer, TimeUnit> setter)

private interface AuthenticationConsumer {

void accept(String authPluginClassName, Map<String, String> authParams)
void accept(String authPluginClassName, String authParamString)
throws UnsupportedAuthenticationException;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ void customizeClientBuilderWhenHasNoAuthentication() {
void customizeClientBuilderWhenHasAuthentication() throws UnsupportedAuthenticationException {
PulsarProperties properties = new PulsarProperties();
Map<String, String> params = Map.of("param", "name");
String authParamString = "{\"param\":\"name\"}";
properties.getClient().getAuthentication().setPluginClassName("myclass");
properties.getClient().getAuthentication().setParam(params);
ClientBuilder builder = mock(ClientBuilder.class);
new PulsarPropertiesMapper(properties).customizeClientBuilder(builder,
new PropertiesPulsarConnectionDetails(properties));
then(builder).should().authentication("myclass", params);
then(builder).should().authentication("myclass", authParamString);
}

@Test
Expand Down Expand Up @@ -112,12 +113,13 @@ void customizeAdminBuilderWhenHasNoAuthentication() {
void customizeAdminBuilderWhenHasAuthentication() throws UnsupportedAuthenticationException {
PulsarProperties properties = new PulsarProperties();
Map<String, String> params = Map.of("param", "name");
String authParamString = "{\"param\":\"name\"}";
properties.getAdmin().getAuthentication().setPluginClassName("myclass");
properties.getAdmin().getAuthentication().setParam(params);
PulsarAdminBuilder builder = mock(PulsarAdminBuilder.class);
new PulsarPropertiesMapper(properties).customizeAdminBuilder(builder,
new PropertiesPulsarConnectionDetails(properties));
then(builder).should().authentication("myclass", params);
then(builder).should().authentication("myclass", authParamString);
}

@Test
Expand Down
Loading