From b2cc74bf58e94e32e368ef2dc93cf935119731c3 Mon Sep 17 00:00:00 2001 From: mposolda Date: Fri, 11 Oct 2013 11:40:51 +0200 Subject: [PATCH] Fix errors in testsuite when Mongo model is used --- .../keycloak/models/mongo/impl/MongoDBImpl.java | 16 +++++++++------- .../mongo/keycloak/adapters/UserAdapter.java | 5 ++++- .../credentials/PasswordCredentialHandler.java | 8 +++----- testsuite/integration/pom.xml | 16 ++++++++++------ 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/impl/MongoDBImpl.java b/model/mongo/src/main/java/org/keycloak/models/mongo/impl/MongoDBImpl.java index 6273ba2eb8..09ca78e378 100644 --- a/model/mongo/src/main/java/org/keycloak/models/mongo/impl/MongoDBImpl.java +++ b/model/mongo/src/main/java/org/keycloak/models/mongo/impl/MongoDBImpl.java @@ -249,16 +249,18 @@ public class MongoDBImpl implements NoSQL { throw new IllegalArgumentException("Property " + listPropertyName + " doesn't exist on object " + object); } List list = (List)listProperty.getValue(object); + + // If list is null, we skip both object and DB update if (list != null) { list.remove(itemToPull); - } - // Pull item from DB - Object dbItemToPull = typeConverter.convertApplicationObjectToDBObject(itemToPull, Object.class); - BasicDBObject query = new BasicDBObject("_id", new ObjectId(oidProperty.getValue(object))); - BasicDBObject pullObject = new BasicDBObject(listPropertyName, dbItemToPull); - BasicDBObject pullCommand = new BasicDBObject("$pull", pullObject); - getDBCollectionForType(type).update(query, pullCommand); + // Pull item from DB + Object dbItemToPull = typeConverter.convertApplicationObjectToDBObject(itemToPull, Object.class); + BasicDBObject query = new BasicDBObject("_id", new ObjectId(oidProperty.getValue(object))); + BasicDBObject pullObject = new BasicDBObject(listPropertyName, dbItemToPull); + BasicDBObject pullCommand = new BasicDBObject("$pull", pullObject); + getDBCollectionForType(type).update(query, pullCommand); + } } // Possibility to add user-defined converters diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/UserAdapter.java b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/UserAdapter.java index 06e70cf679..c047361f31 100644 --- a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/UserAdapter.java +++ b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/UserAdapter.java @@ -128,7 +128,10 @@ public class UserAdapter implements UserModel { @Override public void addRequiredAction(RequiredAction action) { - noSQL.pushItemToList(user, "requiredActions", action); + // Push action only if it's not already here + if (user.getRequiredActions() == null || !user.getRequiredActions().contains(action)) { + noSQL.pushItemToList(user, "requiredActions", action); + } } @Override diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/credentials/PasswordCredentialHandler.java b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/credentials/PasswordCredentialHandler.java index a2f61c9811..719760a0f5 100644 --- a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/credentials/PasswordCredentialHandler.java +++ b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/credentials/PasswordCredentialHandler.java @@ -87,15 +87,13 @@ public class PasswordCredentialHandler { public void update(NoSQL noSQL, UserData user, String password, Date effectiveDate, Date expiryDate) { - // Try to look if user already has password + // Delete existing password of user NoSQLQuery query = noSQL.createQueryBuilder() .andCondition("userId", user.getId()) .build(); + noSQL.removeObjects(PasswordData.class, query); - PasswordData passwordData = noSQL.loadSingleObject(PasswordData.class, query); - if (passwordData == null) { - passwordData = new PasswordData(); - } + PasswordData passwordData = new PasswordData(); String passwordSalt = generateSalt(); diff --git a/testsuite/integration/pom.xml b/testsuite/integration/pom.xml index 55a3ee1913..3f1fc2ebdc 100644 --- a/testsuite/integration/pom.xml +++ b/testsuite/integration/pom.xml @@ -7,11 +7,11 @@ ../../pom.xml 4.0.0 - + keycloak-testsuite-integration Keycloak Integration TestSuite - - + + @@ -21,7 +21,7 @@ - + org.bouncycastle @@ -72,7 +72,7 @@ keycloak-forms ${project.version} - + org.jboss.logging jboss-logging @@ -185,6 +185,10 @@ org.seleniumhq.selenium selenium-java + + org.mongodb + mongo-java-driver + @@ -198,7 +202,7 @@ - + jboss-managed