mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish 'Use authParamString to configure Pulsar authentication'
See gh-38839
This commit is contained in:
parent
4c0a19e8c0
commit
2158f4cc43
@ -73,25 +73,26 @@ final class PulsarPropertiesMapper {
|
||||
|
||||
private void customizeAuthentication(AuthenticationConsumer authentication,
|
||||
PulsarProperties.Authentication properties) {
|
||||
if (!StringUtils.hasText(properties.getPluginClassName())) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.hasText(properties.getPluginClassName())) {
|
||||
try {
|
||||
// sort keys for testing and readability
|
||||
Map<String, String> params = new TreeMap<>(properties.getParam());
|
||||
String authParamString;
|
||||
try {
|
||||
authParamString = ObjectMapperFactory.create().writeValueAsString(params);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Could not convert auth parameters to encoded string", ex);
|
||||
}
|
||||
authentication.accept(properties.getPluginClassName(), authParamString);
|
||||
authentication.accept(properties.getPluginClassName(),
|
||||
getAuthenticationParamsJson(properties.getParam()));
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
<T> void customizeProducerBuilder(ProducerBuilder<T> producerBuilder) {
|
||||
PulsarProperties.Producer properties = this.properties.getProducer();
|
||||
|
Loading…
Reference in New Issue
Block a user