dan-s1 commented on code in PR #9998:
URL: https://github.com/apache/nifi/pull/9998#discussion_r2132888881


##########
nifi-extension-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBControllerService.java:
##########
@@ -96,10 +97,19 @@ protected MongoClient createClient(ConfigurationContext 
context, MongoClient exi
         }
 
         try {
-            final String uri = 
context.getProperty(URI).evaluateAttributeExpressions().getValue();
+            String uri = 
context.getProperty(URI).evaluateAttributeExpressions().getValue();
             final String user = 
context.getProperty(DB_USER).evaluateAttributeExpressions().getValue();
             final String passw = 
context.getProperty(DB_PASSWORD).evaluateAttributeExpressions().getValue();
 
+            // we need to create a new URI string that contains the user and 
password
+            // if not the creation of the connection string will fail for some
+            // authentication methods when calling the constructor of 
ConnectionString
+            if (user != null && passw != null && !uri.contains("@")) {
+                final String beforeInstance = StringUtils.substringBefore(uri, 
"://");
+                final String afterInstance = StringUtils.substringAfter(uri, 
"://");
+                uri = beforeInstance + "://" + user + ":" + passw + "@" + 
afterInstance;
+            }

Review Comment:
   It would be clearer to use URI terms when parsing out the specific parts of 
the URI. Also
   per changes I needed to make for #9975 instead of using string concatenation 
use the `formatted` method.
   ```suggestion
               if (user != null && passw != null && !uri.contains("@")) {
                   final String scheme = StringUtils.substringBefore(uri, 
"://");
                   final String path = StringUtils.substringAfter(uri, "://");
                  uri = "%s://%s:%s@%s".formatted(scheme, user, passw, path); 
               }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to