|
19 | 19 | import java.time.Duration;
|
20 | 20 | import java.util.ArrayList;
|
21 | 21 | import java.util.Map;
|
| 22 | +import java.util.TreeMap; |
22 | 23 | import java.util.concurrent.TimeUnit;
|
23 | 24 | import java.util.function.BiConsumer;
|
24 | 25 | import java.util.function.Consumer;
|
|
29 | 30 | import org.apache.pulsar.client.api.ProducerBuilder;
|
30 | 31 | import org.apache.pulsar.client.api.PulsarClientException.UnsupportedAuthenticationException;
|
31 | 32 | import org.apache.pulsar.client.api.ReaderBuilder;
|
| 33 | +import org.apache.pulsar.common.util.ObjectMapperFactory; |
32 | 34 |
|
33 | 35 | import org.springframework.boot.context.properties.PropertyMapper;
|
34 | 36 | import org.springframework.pulsar.listener.PulsarContainerProperties;
|
@@ -73,14 +75,25 @@ private void customizeAuthentication(AuthenticationConsumer authentication,
|
73 | 75 | PulsarProperties.Authentication properties) {
|
74 | 76 | if (StringUtils.hasText(properties.getPluginClassName())) {
|
75 | 77 | try {
|
76 |
| - authentication.accept(properties.getPluginClassName(), properties.getParam()); |
| 78 | + authentication.accept(properties.getPluginClassName(), |
| 79 | + getAuthenticationParamsJson(properties.getParam())); |
77 | 80 | }
|
78 | 81 | catch (UnsupportedAuthenticationException ex) {
|
79 | 82 | throw new IllegalStateException("Unable to configure Pulsar authentication", ex);
|
80 | 83 | }
|
81 | 84 | }
|
82 | 85 | }
|
83 | 86 |
|
| 87 | + private String getAuthenticationParamsJson(Map<String, String> params) { |
| 88 | + Map<String, String> sortedParams = new TreeMap<>(params); |
| 89 | + try { |
| 90 | + return ObjectMapperFactory.create().writeValueAsString(sortedParams); |
| 91 | + } |
| 92 | + catch (Exception ex) { |
| 93 | + throw new IllegalStateException("Could not convert auth parameters to encoded string", ex); |
| 94 | + } |
| 95 | + } |
| 96 | + |
84 | 97 | <T> void customizeProducerBuilder(ProducerBuilder<T> producerBuilder) {
|
85 | 98 | PulsarProperties.Producer properties = this.properties.getProducer();
|
86 | 99 | PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
@@ -158,8 +171,7 @@ private Consumer<Duration> timeoutProperty(BiConsumer<Integer, TimeUnit> setter)
|
158 | 171 |
|
159 | 172 | private interface AuthenticationConsumer {
|
160 | 173 |
|
161 |
| - void accept(String authPluginClassName, Map<String, String> authParams) |
162 |
| - throws UnsupportedAuthenticationException; |
| 174 | + void accept(String authPluginClassName, String authParamString) throws UnsupportedAuthenticationException; |
163 | 175 |
|
164 | 176 | }
|
165 | 177 |
|
|
0 commit comments