From eb197c46f792d3974c4a92539c1c3ff727025640 Mon Sep 17 00:00:00 2001 From: Carsten Saathoff Date: Fri, 9 Oct 2015 15:06:22 +0200 Subject: [PATCH] Setting operational attributes for mongo also when configured via URI. --- .../DefaultMongoConnectionFactoryProvider.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/connections/mongo/src/main/java/org/keycloak/connections/mongo/DefaultMongoConnectionFactoryProvider.java b/connections/mongo/src/main/java/org/keycloak/connections/mongo/DefaultMongoConnectionFactoryProvider.java index 743eaa0450..bd5a2a295e 100755 --- a/connections/mongo/src/main/java/org/keycloak/connections/mongo/DefaultMongoConnectionFactoryProvider.java +++ b/connections/mongo/src/main/java/org/keycloak/connections/mongo/DefaultMongoConnectionFactoryProvider.java @@ -148,15 +148,25 @@ public class DefaultMongoConnectionFactoryProvider implements MongoConnectionPro * @throws UnknownHostException */ protected MongoClient createMongoClient() throws UnknownHostException { + operationalInfo = new LinkedHashMap<>(); + String dbName = config.get("db", "keycloak"); + String uriString = config.get("uri"); if (uriString != null) { MongoClientURI uri = new MongoClientURI(uriString); MongoClient client = new MongoClient(uri); + + String hosts = String.join(", ", uri.getHosts()); + operationalInfo.put("mongoHosts", hosts); + operationalInfo.put("mongoDatabaseName", dbName); + operationalInfo.put("mongoUser", uri.getUsername()); + operationalInfo.put("mongoDriverVersion", client.getVersion()); + + logger.debugv("Initialized mongo model. host(s): %s, db: %s", uri.getHosts(), dbName); return client; } else { String host = config.get("host", ServerAddress.defaultHost()); int port = config.getInt("port", ServerAddress.defaultPort()); - String dbName = config.get("db", "keycloak"); String user = config.get("user"); String password = config.get("password"); @@ -171,7 +181,6 @@ public class DefaultMongoConnectionFactoryProvider implements MongoConnectionPro client = new MongoClient(new ServerAddress(host, port), clientOptions); } - operationalInfo = new LinkedHashMap<>(); operationalInfo.put("mongoServerAddress", client.getAddress().toString()); operationalInfo.put("mongoDatabaseName", dbName); operationalInfo.put("mongoUser", user);