You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by gi...@git.apache.org on 2017/08/30 00:16:27 UTC

[GitHub] merlimat commented on a change in pull request #721: Parse authParamsString on plugin side

merlimat commented on a change in pull request #721: Parse authParamsString on plugin side
URL: https://github.com/apache/incubator-pulsar/pull/721#discussion_r135943825
 
 

 ##########
 File path: pulsar-client/src/main/java/org/apache/pulsar/client/api/Authentication.java
 ##########
 @@ -40,13 +53,46 @@
     AuthenticationDataProvider getAuthData() throws PulsarClientException;
 
     /**
-     * Configure the authentication plugins with the supplied parameters
+     * Configure the authentication plugins with the Map parameter
      *
      * @param authParams
      */
     void configure(Map<String, String> authParams);
 
     /**
+     * Configure the authentication plugins with the String parameter
+     *
+     * @param authParams
+     */
+    default void configure(String authParams) {
+        Map<String, String> authParamsMap = new HashMap<>();
+        Logger LOG = LoggerFactory.getLogger(Authentication.class);
+
+        // Convert JSON to Map
+        if (isNotBlank(authParams)) {
+            try {
+                ObjectMapper jsonMapper = ObjectMapperFactory.create();
+                authParamsMap = jsonMapper.readValue(authParams, new TypeReference<HashMap<String, String>>() {});
+            } catch (JsonParseException e) {
+                // If authParams is not JSON, separate by ?:? and ?,? for compatibility
+                LOG.warn("Authentication config parameter should be JSON: {}", e.getMessage());
 
 Review comment:
   If we're going to support both comma separated and Json, we shouldn't print a warning here
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services