-
Notifications
You must be signed in to change notification settings - Fork 40.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pulsar auth parameters don't properly encode JSON values #40493
Pulsar auth parameters don't properly encode JSON values #40493
Conversation
The values in the `spring.pulsar.client.authentication.param` config props map are not currently JSON encoded. For simple values this is fine. However, some custom auth modules may require more complex parameter values that may contain special characters that results in invalid JSON. This commmit encodes the parameter values using a very simple hand-rolled escape function. Fixes spring-projects#40492
.collect(Collectors.joining(",", "{", "}")); | ||
} | ||
catch (Exception ex) { | ||
throw new IllegalStateException("Could not convert auth parameters to encoded string", ex); | ||
} | ||
} | ||
|
||
private String escapeJson(String raw) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we do not directly bring in a JSON library (e.g. Gson or Jackson) we can not use the simple facilities that these libs have to "encode a JSON string".
Here were the options:
Use JSON lib
Add required dependency on Jackson or Gson and use their built-in methods
- ✅ solid encode impl maintained by JSON lib
- ❌ ❌ ❌ have to bring in direct dep on JSON lib and this forces it upon our users (not an option)
Add feature to Spring Boot JsonParser
Add "encode a JSON string" to our JsonParser
abstraction
- ✅ can be used in other areas of Spring Boot codebase
- ❌ created and maintained by us (more work)
- ❌ impl no more solid than if it were a private impl inside the mapper
- ❌ nowhere else in the Boot codebase needs this AFAIK
Hand-roll basic encoder
Inline a simple encode JSON facility in the mapper.
- ❌ basic impl maintained by us
- ❌ ✅ not a perfect solution but will solve the majority of the cases
- ✅ ✅ no direct dep on JSON lib
- ✅ private impl localized to the mapper
@@ -81,8 +81,10 @@ void customizeClientBuilderWhenHasNoAuthentication() { | |||
@Test | |||
void customizeClientBuilderWhenHasAuthentication() throws UnsupportedAuthenticationException { | |||
PulsarProperties properties = new PulsarProperties(); | |||
Map<String, String> params = Map.of("param", "name"); | |||
String authParamString = "{\"param\":\"name\"}"; | |||
Map<String, String> params = Map.of("simpleParam", "foo", "complexParam", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not exhausting all possible replacements characters but are covering the majority.
@philwebb should we add a bit more coverage here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not Phil, but I think this is fine :)
The values in the `spring.pulsar.client.authentication.param` config props map are not currently JSON encoded. For simple values this is fine. However, some custom auth modules may require more complex parameter values that may contain special characters that results in invalid JSON. This commmit encodes the parameter values using a very simple hand-rolled escape function. See gh-40493
Thanks Chris! |
The values in the
spring.pulsar.client.authentication.param
config props map are not currently JSON encoded. For simple values this is fine. However, some custom auth modules may require more complex parameter values that may contain special characters that results in invalid JSON. This commmit encodes the parameter values using a very simple hand-rolled escape function.Fixes #40492