Github user sjcorbett commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/894#discussion_r39422046
--- Diff:
software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/mongodb/MongoDBClientSupport.java
---
@@ -45,24 +47,36 @@
public class MongoDBClientSupport {
private static final Logger LOG =
LoggerFactory.getLogger(MongoDBClientSupport.class);
-
private ServerAddress address;
-
+
+ private boolean usesAuthentication;
+ private String username;
+ private String password;
+ private String authenticationDatabase;
+
private MongoClient client() {
- return new MongoClient(address, connectionOptions);
+ if (usesAuthentication) {
+ MongoCredential credential =
MongoCredential.createMongoCRCredential(username, authenticationDatabase,
password.toCharArray());
+ return new MongoClient(address, ImmutableList.of(credential),
connectionOptions);
+ } else {
+ return new MongoClient(address, connectionOptions);
+ }
}
// Set client to automatically reconnect to servers.
private static final MongoClientOptions connectionOptions =
MongoClientOptions.builder()
- .autoConnectRetry(true)
.socketKeepAlive(true)
.build();
private static final BasicBSONObject EMPTY_RESPONSE = new
BasicBSONObject();
- public MongoDBClientSupport(ServerAddress standalone) {
+ public MongoDBClientSupport(ServerAddress standalone, boolean
usesAuthentication, String username, String password, String
authenticationDatabase) {
--- End diff --
I think a nicer way to express this is to use two constructors, one with a
single `ServerAddress` argument and one as the line above, without
`usesAuthentication`. The constructors can set `usesAuthentication` themselves.
The `forServer` method can decide which to call by checking
`MongoDBAuthenticationUtils.usesAuthentication`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---