diff --git a/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPFederationProviderFactory.java b/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPFederationProviderFactory.java index 5472bc7a7f..44987e96f5 100755 --- a/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPFederationProviderFactory.java +++ b/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPFederationProviderFactory.java @@ -16,7 +16,11 @@ import org.picketlink.idm.IdentityManager; import org.picketlink.idm.PartitionManager; import org.picketlink.idm.model.IdentityType; import org.picketlink.idm.model.basic.User; +import org.picketlink.idm.query.AttributeParameter; +import org.picketlink.idm.query.Condition; import org.picketlink.idm.query.IdentityQuery; +import org.picketlink.idm.query.IdentityQueryBuilder; +import org.picketlink.idm.query.QueryParameter; import java.util.Collections; import java.util.Date; @@ -84,13 +88,15 @@ public class LDAPFederationProviderFactory implements UserFederationProviderFact // Sync newly created users IdentityManager identityManager = partitionMgr.createIdentityManager(); - IdentityQuery userQuery = identityManager.createIdentityQuery(User.class) - .setParameter(IdentityType.CREATED_AFTER, lastSync); + IdentityQueryBuilder queryBuilder = identityManager.getQueryBuilder(); + Condition condition = queryBuilder.greaterThanOrEqualTo(IdentityType.CREATED_DATE, lastSync); + IdentityQuery userQuery = queryBuilder.createIdentityQuery(User.class).where(condition); syncImpl(sessionFactory, userQuery, realmId, model); // Sync updated users - userQuery = identityManager.createIdentityQuery(User.class) - .setParameter(IdentityType.MODIFIED_AFTER, lastSync); + queryBuilder = identityManager.getQueryBuilder(); + condition = queryBuilder.greaterThanOrEqualTo(LDAPUtils.MODIFY_DATE, lastSync); + userQuery = queryBuilder.createIdentityQuery(User.class).where(condition); syncImpl(sessionFactory, userQuery, realmId, model); } diff --git a/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPUtils.java b/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPUtils.java index e01a5314bc..db0e9b8ab1 100755 --- a/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPUtils.java +++ b/federation/ldap/src/main/java/org/keycloak/federation/ldap/LDAPUtils.java @@ -10,6 +10,8 @@ import org.picketlink.idm.credential.UsernamePasswordCredentials; import org.picketlink.idm.model.Attribute; import org.picketlink.idm.model.basic.BasicModel; import org.picketlink.idm.model.basic.User; +import org.picketlink.idm.query.AttributeParameter; +import org.picketlink.idm.query.QueryParameter; import java.util.List; @@ -20,6 +22,8 @@ import java.util.List; */ public class LDAPUtils { + public static QueryParameter MODIFY_DATE = new AttributeParameter("modifyDate"); + public static User addUser(PartitionManager partitionManager, String username, String firstName, String lastName, String email) { IdentityManager identityManager = getIdentityManager(partitionManager); diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/rule/LDAPRule.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/rule/LDAPRule.java index 8cd97934f9..1c631bb9ad 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/rule/LDAPRule.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/rule/LDAPRule.java @@ -25,8 +25,9 @@ public class LDAPRule extends ExternalResource { protected void after() { try { embeddedServer.tearDown(); + embeddedServer = null; } catch (Exception e) { - throw new RuntimeException("Error starting Embedded LDAP server.", e); + throw new RuntimeException("Error tearDown Embedded LDAP server.", e); } }