Skip to content

Commit

Permalink
Polish 'Use authParamString to configure Pulsar authentication'
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Dec 17, 2023
1 parent 4c0a19e commit 2158f4c
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,24 @@ void customizeAdminBuilder(PulsarAdminBuilder adminBuilder, PulsarConnectionDeta

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

private String getAuthenticationParamsJson(Map<String, String> params) {
Map<String, String> sortedParams = new TreeMap<>(params);
try {
return ObjectMapperFactory.create().writeValueAsString(sortedParams);
}
catch (Exception ex) {
throw new IllegalStateException("Could not convert auth parameters to encoded string", ex);
}
}

Expand Down

0 comments on commit 2158f4c

Please sign in to comment.