From 45215f361f6dcd36b45a581a551177f902ce80e3 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Mon, 11 Jan 2016 15:10:00 +0100 Subject: [PATCH 1/2] KEYCLOAK-2288 Upgrade Mongo driver version to 3.2.0 --- .../mongo/updater/impl/updates/Update.java | 2 +- .../mongo/updater/impl/updates/Update1_0_0_Final.java | 2 +- .../mongo/DefaultMongoConnectionFactoryProvider.java | 5 ----- .../connections/mongo/impl/MongoStoreImpl.java | 11 ++--------- pom.xml | 2 +- 5 files changed, 5 insertions(+), 17 deletions(-) diff --git a/connections/mongo-update/src/main/java/org/keycloak/connections/mongo/updater/impl/updates/Update.java b/connections/mongo-update/src/main/java/org/keycloak/connections/mongo/updater/impl/updates/Update.java index cc7a2d2855..8e32a73af1 100644 --- a/connections/mongo-update/src/main/java/org/keycloak/connections/mongo/updater/impl/updates/Update.java +++ b/connections/mongo-update/src/main/java/org/keycloak/connections/mongo/updater/impl/updates/Update.java @@ -44,7 +44,7 @@ public abstract class Update { o.append(f, 1); } - col.ensureIndex(o, new BasicDBObject("unique", unique).append("sparse", sparse)); + col.createIndex(o, new BasicDBObject("unique", unique).append("sparse", sparse)); log.debugv("Created index {0}, fields={1}, unique={2}, sparse={3}", name, Arrays.toString(fields), unique, sparse); } diff --git a/connections/mongo-update/src/main/java/org/keycloak/connections/mongo/updater/impl/updates/Update1_0_0_Final.java b/connections/mongo-update/src/main/java/org/keycloak/connections/mongo/updater/impl/updates/Update1_0_0_Final.java index a869c800fd..90b8235530 100644 --- a/connections/mongo-update/src/main/java/org/keycloak/connections/mongo/updater/impl/updates/Update1_0_0_Final.java +++ b/connections/mongo-update/src/main/java/org/keycloak/connections/mongo/updater/impl/updates/Update1_0_0_Final.java @@ -18,7 +18,7 @@ public class Update1_0_0_Final extends Update { @Override public void update(KeycloakSession session) throws ClassNotFoundException { DBCollection realmsCollection = db.getCollection("realms"); - realmsCollection.ensureIndex(new BasicDBObject("name", 1), new BasicDBObject("unique", true)); + realmsCollection.createIndex(new BasicDBObject("name", 1), new BasicDBObject("unique", true)); DefaultMongoUpdaterProvider.log.debugv("Created collection {0}", "realms"); 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 e76e93f446..cc8b1c2c94 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 @@ -174,7 +174,6 @@ public class DefaultMongoConnectionFactoryProvider implements MongoConnectionPro 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; @@ -198,7 +197,6 @@ public class DefaultMongoConnectionFactoryProvider implements MongoConnectionPro operationalInfo.put("mongoServerAddress", client.getAddress().toString()); operationalInfo.put("mongoDatabaseName", dbName); operationalInfo.put("mongoUser", user); - operationalInfo.put("mongoDriverVersion", client.getVersion()); logger.debugv("Initialized mongo model. host: %s, port: %d, db: %s", host, port, dbName); return client; @@ -214,9 +212,6 @@ public class DefaultMongoConnectionFactoryProvider implements MongoConnectionPro checkIntOption("socketTimeout", builder); checkBooleanOption("socketKeepAlive", builder); checkBooleanOption("autoConnectRetry", builder); - if (config.getLong("maxAutoConnectRetryTime") != null) { - builder.maxAutoConnectRetryTime(config.getLong("maxAutoConnectRetryTime")); - } if(config.getBoolean("ssl", false)) { builder.socketFactory(SSLSocketFactory.getDefault()); } diff --git a/connections/mongo/src/main/java/org/keycloak/connections/mongo/impl/MongoStoreImpl.java b/connections/mongo/src/main/java/org/keycloak/connections/mongo/impl/MongoStoreImpl.java index 94049f5674..bdc0818fc6 100755 --- a/connections/mongo/src/main/java/org/keycloak/connections/mongo/impl/MongoStoreImpl.java +++ b/connections/mongo/src/main/java/org/keycloak/connections/mongo/impl/MongoStoreImpl.java @@ -1,13 +1,6 @@ package org.keycloak.connections.mongo.impl; -import com.mongodb.BasicDBList; -import com.mongodb.BasicDBObject; -import com.mongodb.DB; -import com.mongodb.DBCollection; -import com.mongodb.DBCursor; -import com.mongodb.DBObject; -import com.mongodb.MongoException; -import com.mongodb.WriteResult; +import com.mongodb.*; import org.jboss.logging.Logger; import org.keycloak.connections.mongo.api.MongoCollection; import org.keycloak.connections.mongo.api.MongoEntity; @@ -133,7 +126,7 @@ public class MongoStoreImpl implements MongoStore { } public static ModelException convertException(MongoException e) { - if (e instanceof MongoException.DuplicateKey) { + if (e instanceof DuplicateKeyException) { return new ModelDuplicateException(e); } else { return new ModelException(e); diff --git a/pom.xml b/pom.xml index 83ac183320..71c616ffef 100755 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ 4.2.1 1.1.1.Final 2.7.0.Final - 2.11.3 + 3.2.0 3.1.4.GA 0.9.30 1.2.0.Beta1 From 8d2becf681a932ab6c95c03cb7d42aafc6ebe486 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Mon, 11 Jan 2016 15:47:09 +0100 Subject: [PATCH 2/2] Fix import of com.mongodb.util.MyAsserts.assertFalse --- .../adapter/servlet/AbstractSAMLServletsAdapterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractSAMLServletsAdapterTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractSAMLServletsAdapterTest.java index a5e67ababe..82ec4c9d02 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractSAMLServletsAdapterTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractSAMLServletsAdapterTest.java @@ -16,8 +16,8 @@ import org.w3c.dom.Document; import javax.ws.rs.core.Response; import java.util.List; -import static com.mongodb.util.MyAsserts.assertFalse; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.keycloak.testsuite.auth.page.AuthRealm.SAMLSERVLETDEMO; import static org.keycloak.testsuite.util.IOUtil.*;