Skip to content

Commit 2158f4c

Browse files
committed
Polish 'Use authParamString to configure Pulsar authentication'
See gh-38839
1 parent 4c0a19e commit 2158f4c

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarPropertiesMapper.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,24 @@ void customizeAdminBuilder(PulsarAdminBuilder adminBuilder, PulsarConnectionDeta
7373

7474
private void customizeAuthentication(AuthenticationConsumer authentication,
7575
PulsarProperties.Authentication properties) {
76-
if (!StringUtils.hasText(properties.getPluginClassName())) {
77-
return;
78-
}
79-
try {
80-
// sort keys for testing and readability
81-
Map<String, String> params = new TreeMap<>(properties.getParam());
82-
String authParamString;
76+
if (StringUtils.hasText(properties.getPluginClassName())) {
8377
try {
84-
authParamString = ObjectMapperFactory.create().writeValueAsString(params);
78+
authentication.accept(properties.getPluginClassName(),
79+
getAuthenticationParamsJson(properties.getParam()));
8580
}
86-
catch (Exception ex) {
87-
throw new IllegalStateException("Could not convert auth parameters to encoded string", ex);
81+
catch (UnsupportedAuthenticationException ex) {
82+
throw new IllegalStateException("Unable to configure Pulsar authentication", ex);
8883
}
89-
authentication.accept(properties.getPluginClassName(), authParamString);
9084
}
91-
catch (UnsupportedAuthenticationException ex) {
92-
throw new IllegalStateException("Unable to configure Pulsar authentication", ex);
85+
}
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);
9394
}
9495
}
9596

0 commit comments

Comments
 (0)