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


##########
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:
   Per changes I needed to make for #9975, the following would be cleaner
   ```suggestion
                   uri = "%s://%s:%s@%s".formatted(beforeInstance, user, passw, 
afterInstance); 
   ```



-- 
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