From 2158f4cc43ce07ae6780d56f720870be44255892 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sat, 16 Dec 2023 22:19:35 -0800 Subject: [PATCH] Polish 'Use authParamString to configure Pulsar authentication' See gh-38839 --- .../pulsar/PulsarPropertiesMapper.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarPropertiesMapper.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarPropertiesMapper.java index 4d5c1827f53..ed9411512eb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarPropertiesMapper.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/pulsar/PulsarPropertiesMapper.java @@ -73,23 +73,24 @@ final class PulsarPropertiesMapper { private void customizeAuthentication(AuthenticationConsumer authentication, PulsarProperties.Authentication properties) { - if (!StringUtils.hasText(properties.getPluginClassName())) { - return; - } - try { - // sort keys for testing and readability - Map 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 params) { + Map 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); } }