You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2015/06/11 16:17:40 UTC

[50/70] syncope git commit: [SYNCOPE-666] More cleanup + test for using realm in ConnObjectLink

[SYNCOPE-666] More cleanup + test for using realm in ConnObjectLink


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/54de3984
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/54de3984
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/54de3984

Branch: refs/heads/master
Commit: 54de3984790735467e69b46feb934d17f2fd2b42
Parents: a64ef15
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Mon Jun 8 09:04:50 2015 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Mon Jun 8 09:04:50 2015 +0200

----------------------------------------------------------------------
 .../syncope/core/logic/ResourceLogic.java       |  8 +-
 .../apache/syncope/core/logic/AbstractTest.java | 41 +++++++++
 .../apache/syncope/core/logic/MappingTest.java  | 67 ++++++++++++++
 .../syncope/core/logic/NotificationTest.java    | 21 +----
 .../syncope/core/misc/ConnObjectUtils.java      |  2 +-
 .../apache/syncope/core/misc/MappingUtils.java  | 97 +++++++++++++++-----
 .../syncope/core/misc/jexl/JexlUtils.java       | 23 +++--
 .../core/persistence/api/entity/AnyUtils.java   | 10 --
 .../persistence/jpa/entity/JPAAnyUtils.java     | 83 -----------------
 .../core/provisioning/api/VirAttrHandler.java   |  6 +-
 .../provisioning/java/VirAttrHandlerImpl.java   | 24 ++---
 .../java/data/AbstractAnyDataBinder.java        | 10 +-
 .../AbstractPropagationTaskExecutor.java        |  8 +-
 .../propagation/PropagationManagerImpl.java     | 21 ++---
 .../core/provisioning/java/sync/SyncUtils.java  | 13 +--
 .../core/reference/AuthenticationITCase.java    | 12 ++-
 16 files changed, 247 insertions(+), 199 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/logic/src/main/java/org/apache/syncope/core/logic/ResourceLogic.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/ResourceLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/ResourceLogic.java
index 863af12..df09b5f 100644
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/ResourceLogic.java
+++ b/core/logic/src/main/java/org/apache/syncope/core/logic/ResourceLogic.java
@@ -50,7 +50,6 @@ import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
 import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
 import org.apache.syncope.core.persistence.api.entity.Any;
 import org.apache.syncope.core.persistence.api.entity.AnyType;
-import org.apache.syncope.core.persistence.api.entity.AnyUtils;
 import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory;
 import org.apache.syncope.core.persistence.api.entity.resource.Provision;
 import org.identityconnectors.framework.common.objects.Attribute;
@@ -201,10 +200,7 @@ public class ResourceLogic extends AbstractTransactionalLogic<ResourceTO> {
         if (any == null) {
             throw new NotFoundException(anyType + " " + key);
         }
-
-        AnyUtils attrUtils = anyUtilsFactory.getInstance(anyType.getKind());
-
-        MappingItem connObjectKeyItem = attrUtils.getConnObjectKeyItem(provision);
+        MappingItem connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
         if (connObjectKeyItem == null) {
             throw new NotFoundException(
                     "ConnObjectKey mapping for " + anyType + " " + key + " on resource '" + resourceKey + "'");
@@ -214,7 +210,7 @@ public class ResourceLogic extends AbstractTransactionalLogic<ResourceTO> {
         Connector connector = connFactory.getConnector(resource);
         ConnectorObject connectorObject = connector.getObject(
                 provision.getObjectClass(), new Uid(connObjectKeyValue),
-                connector.getOperationOptions(attrUtils.getMappingItems(provision, MappingPurpose.BOTH)));
+                connector.getOperationOptions(MappingUtils.getMappingItems(provision, MappingPurpose.BOTH)));
         if (connectorObject == null) {
             throw new NotFoundException("Object " + connObjectKeyValue + " with class " + provision.getObjectClass()
                     + " not found on resource " + resourceKey);

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java
----------------------------------------------------------------------
diff --git a/core/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java b/core/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java
new file mode 100644
index 0000000..161d0c1
--- /dev/null
+++ b/core/logic/src/test/java/org/apache/syncope/core/logic/AbstractTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.logic;
+
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.transaction.annotation.Transactional;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {
+    "classpath:provisioningContext.xml",
+    "classpath:logicContext.xml",
+    "classpath:workflowContext.xml",
+    "classpath:persistenceTest.xml",
+    "classpath:logicTest.xml"
+})
+@Transactional
+public abstract class AbstractTest {
+
+    protected static final Logger LOG = LoggerFactory.getLogger(AbstractTest.class);
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/logic/src/test/java/org/apache/syncope/core/logic/MappingTest.java
----------------------------------------------------------------------
diff --git a/core/logic/src/test/java/org/apache/syncope/core/logic/MappingTest.java b/core/logic/src/test/java/org/apache/syncope/core/logic/MappingTest.java
new file mode 100644
index 0000000..1f1dab7
--- /dev/null
+++ b/core/logic/src/test/java/org/apache/syncope/core/logic/MappingTest.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.logic;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.syncope.core.misc.MappingUtils;
+import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
+import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
+import org.apache.syncope.core.persistence.api.entity.resource.Provision;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.identityconnectors.framework.common.objects.Name;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class MappingTest extends AbstractTest {
+
+    @Autowired
+    private ExternalResourceDAO resourceDAO;
+
+    @Autowired
+    private AnyTypeDAO anyTypeDAO;
+
+    @Autowired
+    private UserDAO userDAO;
+
+    @Test
+    public void connObjectLink() {
+        ExternalResource ldap = resourceDAO.find("resource-ldap");
+        assertNotNull(ldap);
+
+        Provision provision = ldap.getProvision(anyTypeDAO.findUser());
+        assertNotNull(provision);
+        assertNotNull(provision.getMapping());
+        assertNotNull(provision.getMapping().getConnObjectLink());
+
+        User user = userDAO.find("rossini");
+        assertNotNull(user);
+
+        Name name = MappingUtils.evaluateNAME(user, provision, user.getUsername());
+        assertEquals("uid=rossini,ou=people,o=isp", name.getNameValue());
+
+        provision.getMapping().setConnObjectLink("'uid=' + username + ',o=' + realm + ',ou=people,o=isp'");
+
+        name = MappingUtils.evaluateNAME(user, provision, user.getUsername());
+        assertEquals("uid=rossini,o=even,ou=people,o=isp", name.getNameValue());
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/logic/src/test/java/org/apache/syncope/core/logic/NotificationTest.java
----------------------------------------------------------------------
diff --git a/core/logic/src/test/java/org/apache/syncope/core/logic/NotificationTest.java b/core/logic/src/test/java/org/apache/syncope/core/logic/NotificationTest.java
index 4401a6b..bc425dc 100644
--- a/core/logic/src/test/java/org/apache/syncope/core/logic/NotificationTest.java
+++ b/core/logic/src/test/java/org/apache/syncope/core/logic/NotificationTest.java
@@ -70,9 +70,6 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.mail.javamail.JavaMailSender;
 import org.springframework.mail.javamail.JavaMailSenderImpl;
@@ -82,22 +79,8 @@ import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.core.userdetails.User;
 import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.transaction.annotation.Transactional;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = {
-    "classpath:provisioningContext.xml",
-    "classpath:logicContext.xml",
-    "classpath:workflowContext.xml",
-    "classpath:persistenceTest.xml",
-    "classpath:logicTest.xml"
-})
-@Transactional
-public class NotificationTest {
-
-    private static final Logger LOG = LoggerFactory.getLogger(NotificationTest.class);
+
+public class NotificationTest extends AbstractTest {
 
     private static final String SMTP_HOST = "localhost";
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java
index c86ee7c..807ea0f 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java
@@ -199,7 +199,7 @@ public class ConnObjectUtils {
 
         // 1. fill with data from connector object
         anyTO.setRealm(syncTask.getDestinatioRealm().getFullPath());
-        for (MappingItem item : anyUtils.getMappingItems(provision, MappingPurpose.SYNCHRONIZATION)) {
+        for (MappingItem item : MappingUtils.getMappingItems(provision, MappingPurpose.SYNCHRONIZATION)) {
             Attribute attr = obj.getAttributeByName(item.getExtAttrName());
 
             AttrTO attrTO;

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/misc/src/main/java/org/apache/syncope/core/misc/MappingUtils.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/MappingUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/MappingUtils.java
index 97008d0..140c5ad 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/MappingUtils.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/MappingUtils.java
@@ -120,7 +120,6 @@ public final class MappingUtils {
     /**
      * Prepare attributes for sending to a connector instance.
      *
-     * @param anyUtils any object
      * @param any given any object
      * @param password clear-text password
      * @param changePwd whether password should be included for propagation attributes or not
@@ -130,8 +129,8 @@ public final class MappingUtils {
      * @param provision provision information
      * @return connObjectLink + prepared attributes
      */
-    public static Pair<String, Set<Attribute>> prepareAttributes(
-            final AnyUtils anyUtils, final Any<?, ?, ?> any,
+    public static Pair<String, Set<Attribute>> prepareAttrs(
+            final Any<?, ?, ?> any,
             final String password,
             final boolean changePwd,
             final Set<String> vAttrsToBeRemoved,
@@ -149,7 +148,7 @@ public final class MappingUtils {
         Set<Attribute> attributes = new HashSet<>();
         String connObjectKey = null;
 
-        for (MappingItem mapping : anyUtils.getMappingItems(provision, MappingPurpose.PROPAGATION)) {
+        for (MappingItem mapping : getMappingItems(provision, MappingPurpose.PROPAGATION)) {
             LOG.debug("Processing schema {}", mapping.getIntAttrName());
 
             try {
@@ -188,11 +187,10 @@ public final class MappingUtils {
         }
 
         Attribute connObjectKeyExtAttr =
-                AttributeUtil.find(anyUtils.getConnObjectKeyItem(provision).getExtAttrName(), attributes);
+                AttributeUtil.find(getConnObjectKeyItem(provision).getExtAttrName(), attributes);
         if (connObjectKeyExtAttr != null) {
             attributes.remove(connObjectKeyExtAttr);
-            attributes.add(AttributeBuilder.build(
-                    anyUtils.getConnObjectKeyItem(provision).getExtAttrName(), connObjectKey));
+            attributes.add(AttributeBuilder.build(getConnObjectKeyItem(provision).getExtAttrName(), connObjectKey));
         }
         attributes.add(evaluateNAME(any, provision, connObjectKey));
 
@@ -373,26 +371,23 @@ public final class MappingUtils {
      * @param connObjectKey connector object key
      * @return the value to be propagated as __NAME__
      */
-    public static Name evaluateNAME(final Any<?, ?, ?> any,
-            final Provision provision, final String connObjectKey) {
-
-        final AnyUtilsFactory anyUtilsFactory =
-                ApplicationContextProvider.getApplicationContext().getBean(AnyUtilsFactory.class);
-        final AnyUtils anyUtils = anyUtilsFactory.getInstance(any);
-
+    public static Name evaluateNAME(final Any<?, ?, ?> any, final Provision provision, final String connObjectKey) {
         if (StringUtils.isBlank(connObjectKey)) {
             // LOG error but avoid to throw exception: leave it to the external resource
             LOG.error("Missing ConnObjectKey for '{}': ", provision.getResource());
         }
 
         // Evaluate connObjectKey expression
+        String connObjectLink = provision == null || provision.getMapping() == null
+                ? null
+                : provision.getMapping().getConnObjectLink();
         String evalConnObjectLink = null;
-        if (StringUtils.isNotBlank(anyUtils.getConnObjectLink(provision))) {
-            final JexlContext jexlContext = new MapContext();
+        if (StringUtils.isNotBlank(connObjectLink)) {
+            JexlContext jexlContext = new MapContext();
             JexlUtils.addFieldsToContext(any, jexlContext);
             JexlUtils.addPlainAttrsToContext(any.getPlainAttrs(), jexlContext);
             JexlUtils.addDerAttrsToContext(any.getDerAttrs(), any.getPlainAttrs(), jexlContext);
-            evalConnObjectLink = JexlUtils.evaluate(anyUtils.getConnObjectLink(provision), jexlContext);
+            evalConnObjectLink = JexlUtils.evaluate(connObjectLink, jexlContext);
         }
 
         // If connObjectLink evaluates to an empty string, just use the provided connObjectKey as Name(),
@@ -414,11 +409,7 @@ public final class MappingUtils {
     }
 
     private static String getGroupOwnerValue(final Provision provision, final Any<?, ?, ?> any) {
-        AnyUtilsFactory anyUtilsFactory =
-                ApplicationContextProvider.getApplicationContext().getBean(AnyUtilsFactory.class);
-
-        Pair<String, Attribute> preparedAttr = prepareAttr(
-                provision, anyUtilsFactory.getInstance(any).getConnObjectKeyItem(provision),
+        Pair<String, Attribute> preparedAttr = prepareAttr(provision, getConnObjectKeyItem(provision),
                 any, null, null, Collections.<String>emptySet(), Collections.<String, AttrMod>emptyMap());
         String connObjectKey = preparedAttr.getKey();
 
@@ -611,6 +602,68 @@ public final class MappingUtils {
                 : values.get(0).getValueAsString();
     }
 
+    public static MappingItem getConnObjectKeyItem(final Provision provision) {
+        Mapping mapping = null;
+        if (provision != null) {
+            mapping = provision.getMapping();
+        }
+
+        return mapping == null
+                ? null
+                : mapping.getConnObjectKeyItem();
+    }
+
+    public static List<MappingItem> getMappingItems(final Provision provision, final MappingPurpose purpose) {
+        List<? extends MappingItem> items = Collections.<MappingItem>emptyList();
+        if (provision != null) {
+            items = provision.getMapping().getItems();
+        }
+
+        List<MappingItem> result = new ArrayList<>();
+
+        switch (purpose) {
+            case SYNCHRONIZATION:
+                for (MappingItem item : items) {
+                    if (MappingPurpose.PROPAGATION != item.getPurpose()
+                            && MappingPurpose.NONE != item.getPurpose()) {
+
+                        result.add(item);
+                    }
+                }
+                break;
+
+            case PROPAGATION:
+                for (MappingItem item : items) {
+                    if (MappingPurpose.SYNCHRONIZATION != item.getPurpose()
+                            && MappingPurpose.NONE != item.getPurpose()) {
+
+                        result.add(item);
+                    }
+                }
+                break;
+
+            case BOTH:
+                for (MappingItem item : items) {
+                    if (MappingPurpose.NONE != item.getPurpose()) {
+                        result.add(item);
+                    }
+                }
+                break;
+
+            case NONE:
+                for (MappingItem item : items) {
+                    if (MappingPurpose.NONE == item.getPurpose()) {
+                        result.add(item);
+                    }
+                }
+                break;
+
+            default:
+        }
+
+        return result;
+    }
+
     /**
      * Private default constructor, for static-only classes.
      */

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/misc/src/main/java/org/apache/syncope/core/misc/jexl/JexlUtils.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/jexl/JexlUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/jexl/JexlUtils.java
index 9aad079..443bbae 100644
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/jexl/JexlUtils.java
+++ b/core/misc/src/main/java/org/apache/syncope/core/misc/jexl/JexlUtils.java
@@ -22,7 +22,6 @@ import java.beans.IntrospectionException;
 import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Field;
-import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
@@ -106,24 +105,22 @@ public final class JexlUtils {
 
         try {
             for (PropertyDescriptor desc : Introspector.getBeanInfo(object.getClass()).getPropertyDescriptors()) {
-                final Class<?> type = desc.getPropertyType();
-                final String fieldName = desc.getName();
+                Class<?> type = desc.getPropertyType();
+                String fieldName = desc.getName();
 
                 if ((!fieldName.startsWith("pc"))
                         && (!ArrayUtils.contains(IGNORE_FIELDS, fieldName))
                         && (!Iterable.class.isAssignableFrom(type))
                         && (!type.isArray())) {
-                    try {
-                        final Method getter = desc.getReadMethod();
-
-                        final Object fieldValue;
 
-                        if (getter == null) {
+                    try {
+                        Object fieldValue;
+                        if (desc.getReadMethod() == null) {
                             final Field field = object.getClass().getDeclaredField(fieldName);
                             field.setAccessible(true);
                             fieldValue = field.get(object);
                         } else {
-                            fieldValue = getter.invoke(object);
+                            fieldValue = desc.getReadMethod().invoke(object);
                         }
 
                         context.set(fieldName, fieldValue == null
@@ -133,7 +130,6 @@ public final class JexlUtils {
                                         : fieldValue));
 
                         LOG.debug("Add field {} with value {}", fieldName, fieldValue);
-
                     } catch (Exception iae) {
                         LOG.error("Reading '{}' value error", fieldName, iae);
                     }
@@ -143,6 +139,13 @@ public final class JexlUtils {
             LOG.error("Reading class attributes error", ie);
         }
 
+        if (object instanceof Any) {
+            Any<?, ?, ?> any = (Any<?, ?, ?>) object;
+            if (any.getRealm() != null) {
+                context.set("realm", any.getRealm().getName());
+            }
+        }
+
         return context;
     }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/AnyUtils.java
----------------------------------------------------------------------
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/AnyUtils.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/AnyUtils.java
index 836f0e3..8c64086 100644
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/AnyUtils.java
+++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/entity/AnyUtils.java
@@ -18,13 +18,9 @@
  */
 package org.apache.syncope.core.persistence.api.entity;
 
-import org.apache.syncope.core.persistence.api.entity.resource.MappingItem;
-import java.util.List;
 import org.apache.syncope.common.lib.to.AnyTO;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.lib.types.IntMappingType;
-import org.apache.syncope.common.lib.types.MappingPurpose;
-import org.apache.syncope.core.persistence.api.entity.resource.Provision;
 
 public interface AnyUtils {
 
@@ -52,12 +48,6 @@ public interface AnyUtils {
 
     <T extends VirAttr<?>> T newVirAttr();
 
-    MappingItem getConnObjectKeyItem(Provision provision);
-
-    String getConnObjectLink(Provision provision);
-
-    List<MappingItem> getMappingItems(Provision provision, MappingPurpose purpose);
-
     IntMappingType plainIntMappingType();
 
     IntMappingType derIntMappingType();

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyUtils.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyUtils.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyUtils.java
index 989c642..9d0f798 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyUtils.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyUtils.java
@@ -18,25 +18,18 @@
  */
 package org.apache.syncope.core.persistence.jpa.entity;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
 import org.apache.syncope.common.lib.to.AnyObjectTO;
 import org.apache.syncope.common.lib.to.AnyTO;
 import org.apache.syncope.common.lib.to.GroupTO;
 import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.lib.types.IntMappingType;
-import org.apache.syncope.common.lib.types.MappingPurpose;
 import org.apache.syncope.core.persistence.api.entity.Any;
 import org.apache.syncope.core.persistence.api.entity.AnyUtils;
 import org.apache.syncope.core.persistence.api.entity.DerAttr;
-import org.apache.syncope.core.persistence.api.entity.resource.MappingItem;
 import org.apache.syncope.core.persistence.api.entity.PlainAttr;
 import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
 import org.apache.syncope.core.persistence.api.entity.VirAttr;
-import org.apache.syncope.core.persistence.api.entity.resource.Mapping;
-import org.apache.syncope.core.persistence.api.entity.resource.Provision;
 import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAADerAttr;
 import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAPlainAttr;
 import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAPlainAttrUniqueValue;
@@ -319,82 +312,6 @@ public class JPAAnyUtils implements AnyUtils {
     }
 
     @Override
-    public MappingItem getConnObjectKeyItem(final Provision provision) {
-        Mapping mapping = null;
-        if (provision != null) {
-            mapping = provision.getMapping();
-        }
-
-        return mapping == null
-                ? null
-                : mapping.getConnObjectKeyItem();
-    }
-
-    @Override
-    public String getConnObjectLink(final Provision provision) {
-        Mapping mapping = null;
-        if (provision != null) {
-            mapping = provision.getMapping();
-        }
-
-        return mapping == null
-                ? null
-                : mapping.getConnObjectLink();
-    }
-
-    @Override
-    public List<MappingItem> getMappingItems(final Provision provision, final MappingPurpose purpose) {
-        List<? extends MappingItem> items = Collections.<MappingItem>emptyList();
-        if (provision != null) {
-            items = provision.getMapping().getItems();
-        }
-
-        List<MappingItem> result = new ArrayList<>();
-
-        switch (purpose) {
-            case SYNCHRONIZATION:
-                for (MappingItem item : items) {
-                    if (MappingPurpose.PROPAGATION != item.getPurpose()
-                            && MappingPurpose.NONE != item.getPurpose()) {
-
-                        result.add(item);
-                    }
-                }
-                break;
-
-            case PROPAGATION:
-                for (MappingItem item : items) {
-                    if (MappingPurpose.SYNCHRONIZATION != item.getPurpose()
-                            && MappingPurpose.NONE != item.getPurpose()) {
-
-                        result.add(item);
-                    }
-                }
-                break;
-
-            case BOTH:
-                for (MappingItem item : items) {
-                    if (MappingPurpose.NONE != item.getPurpose()) {
-                        result.add(item);
-                    }
-                }
-                break;
-
-            case NONE:
-                for (MappingItem item : items) {
-                    if (MappingPurpose.NONE == item.getPurpose()) {
-                        result.add(item);
-                    }
-                }
-                break;
-
-            default:
-        }
-
-        return result;
-    }
-
-    @Override
     public IntMappingType plainIntMappingType() {
         IntMappingType result = null;
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/VirAttrHandler.java
----------------------------------------------------------------------
diff --git a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/VirAttrHandler.java b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/VirAttrHandler.java
index 4cec074..8916d27 100644
--- a/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/VirAttrHandler.java
+++ b/core/provisioning-api/src/main/java/org/apache/syncope/core/provisioning/api/VirAttrHandler.java
@@ -26,7 +26,6 @@ import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.lib.types.IntMappingType;
 import org.apache.syncope.common.lib.types.PropagationByResource;
 import org.apache.syncope.core.persistence.api.entity.Any;
-import org.apache.syncope.core.persistence.api.entity.AnyUtils;
 import org.apache.syncope.core.persistence.api.entity.VirSchema;
 import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
 
@@ -64,8 +63,7 @@ public interface VirAttrHandler {
     void retrieveVirAttrValues(Any<?, ?, ?> any);
 
     void updateOnResourcesIfMappingMatches(
-            Any<?, ?, ?> any, AnyUtils anyUtils, String schemaKey,
-            Iterable<? extends ExternalResource> resources, IntMappingType mappingType,
-            PropagationByResource propByRes);
+            Any<?, ?, ?> any, String schemaKey, Iterable<? extends ExternalResource> resources,
+            IntMappingType mappingType, PropagationByResource propByRes);
 
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/VirAttrHandlerImpl.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/VirAttrHandlerImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/VirAttrHandlerImpl.java
index 21626f5..888329c 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/VirAttrHandlerImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/VirAttrHandlerImpl.java
@@ -117,12 +117,12 @@ public class VirAttrHandlerImpl implements VirAttrHandler {
     }
 
     @Override
-    public void updateOnResourcesIfMappingMatches(final Any<?, ?, ?> any, final AnyUtils anyUtils,
-            final String schemaKey, final Iterable<? extends ExternalResource> resources,
-            final IntMappingType mappingType, final PropagationByResource propByRes) {
+    public void updateOnResourcesIfMappingMatches(final Any<?, ?, ?> any, final String schemaKey,
+            final Iterable<? extends ExternalResource> resources, final IntMappingType mappingType,
+            final PropagationByResource propByRes) {
 
         for (ExternalResource resource : resources) {
-            for (MappingItem mapItem : anyUtils.getMappingItems(
+            for (MappingItem mapItem : MappingUtils.getMappingItems(
                     resource.getProvision(any.getType()), MappingPurpose.PROPAGATION)) {
 
                 if (schemaKey.equals(mapItem.getIntAttrName()) && mapItem.getIntMappingType() == mappingType) {
@@ -166,7 +166,7 @@ public class VirAttrHandlerImpl implements VirAttrHandler {
                 }
 
                 for (ExternalResource resource : externalResources) {
-                    for (MappingItem mapItem : anyUtils.getMappingItems(
+                    for (MappingItem mapItem : MappingUtils.getMappingItems(
                             resource.getProvision(any.getType()), MappingPurpose.PROPAGATION)) {
 
                         if (virSchema.getKey().equals(mapItem.getIntAttrName())
@@ -199,8 +199,8 @@ public class VirAttrHandlerImpl implements VirAttrHandler {
                     any.add(virAttr);
                 }
 
-                updateOnResourcesIfMappingMatches(any, anyUtils, virSchema.getKey(),
-                        externalResources, anyUtils.derIntMappingType(), propByRes);
+                updateOnResourcesIfMappingMatches(
+                        any, virSchema.getKey(), externalResources, anyUtils.derIntMappingType(), propByRes);
 
                 List<String> values = new ArrayList<>(virAttr.getValues());
                 values.removeAll(vAttrToBeUpdated.getValuesToBeRemoved());
@@ -322,19 +322,19 @@ public class VirAttrHandlerImpl implements VirAttrHandler {
 
             AnyUtils anyUtils = anyUtilsFactory.getInstance(any);
 
-            for (ExternalResource resource : getTargetResources(virAttr, type, anyUtils, any.getType())) {
+            for (ExternalResource resource : getTargetResources(virAttr, type, any.getType())) {
                 Provision provision = resource.getProvision(any.getType());
                 LOG.debug("Search values into {},{}", resource, provision);
 
                 try {
-                    List<MappingItem> mappings = anyUtils.getMappingItems(provision, MappingPurpose.BOTH);
+                    List<MappingItem> mappings = MappingUtils.getMappingItems(provision, MappingPurpose.BOTH);
 
                     ConnectorObject connectorObject;
                     if (externalResources.containsKey(resource.getKey())) {
                         connectorObject = externalResources.get(resource.getKey());
                     } else {
                         LOG.debug("Perform connection to {}", resource.getKey());
-                        String connObjectKey = anyUtils.getConnObjectKeyItem(provision) == null
+                        String connObjectKey = MappingUtils.getConnObjectKeyItem(provision) == null
                                 ? null
                                 : MappingUtils.getConnObjectKeyValue(any, provision);
 
@@ -395,7 +395,7 @@ public class VirAttrHandlerImpl implements VirAttrHandler {
     }
 
     private Collection<ExternalResource> getTargetResources(
-            final VirAttr<?> attr, final IntMappingType type, final AnyUtils anyUtils, final AnyType anyType) {
+            final VirAttr<?> attr, final IntMappingType type, final AnyType anyType) {
 
         return CollectionUtils.select(getAllResources(attr.getOwner()), new Predicate<ExternalResource>() {
 
@@ -403,7 +403,7 @@ public class VirAttrHandlerImpl implements VirAttrHandler {
             public boolean evaluate(final ExternalResource resource) {
                 return resource.getProvision(anyType) != null
                         && !MappingUtils.getMatchingMappingItems(
-                                anyUtils.getMappingItems(resource.getProvision(anyType), MappingPurpose.BOTH),
+                                MappingUtils.getMappingItems(resource.getProvision(anyType), MappingPurpose.BOTH),
                                 attr.getSchema().getKey(), type).isEmpty();
             }
         });

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java
index 4a8a35b..90f5e91 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java
@@ -368,7 +368,7 @@ abstract class AbstractAnyDataBinder {
                 }
 
                 for (ExternalResource resource : resources) {
-                    for (MappingItem mapItem : anyUtils.getMappingItems(
+                    for (MappingItem mapItem : MappingUtils.getMappingItems(
                             resource.getProvision(any.getType()), MappingPurpose.PROPAGATION)) {
 
                         if (schema.getKey().equals(mapItem.getIntAttrName())
@@ -402,7 +402,7 @@ abstract class AbstractAnyDataBinder {
             }
 
             if (schema != null && attr != null && attr.getSchema() != null) {
-                virAttrHander.updateOnResourcesIfMappingMatches(any, anyUtils, schema.getKey(),
+                virAttrHander.updateOnResourcesIfMappingMatches(any, schema.getKey(),
                         resources, anyUtils.plainIntMappingType(), propByRes);
 
                 // 1.1 remove values
@@ -460,7 +460,7 @@ abstract class AbstractAnyDataBinder {
                 }
 
                 for (ExternalResource resource : resources) {
-                    for (MappingItem mapItem : anyUtils.getMappingItems(
+                    for (MappingItem mapItem : MappingUtils.getMappingItems(
                             resource.getProvision(any.getType()), MappingPurpose.PROPAGATION)) {
 
                         if (derSchema.getKey().equals(mapItem.getIntAttrName())
@@ -486,7 +486,7 @@ abstract class AbstractAnyDataBinder {
         for (String derAttrToBeAdded : anyMod.getDerAttrsToAdd()) {
             DerSchema derSchema = getDerSchema(derAttrToBeAdded);
             if (derSchema != null) {
-                virAttrHander.updateOnResourcesIfMappingMatches(any, anyUtils, derSchema.getKey(),
+                virAttrHander.updateOnResourcesIfMappingMatches(any, derSchema.getKey(),
                         resources, anyUtils.derIntMappingType(), propByRes);
 
                 DerAttr derAttr = any.getDerAttr(derSchema.getKey());
@@ -700,7 +700,7 @@ abstract class AbstractAnyDataBinder {
         for (ExternalResource resource : iterable) {
             Provision provision = resource.getProvision(any.getType());
             if (provision != null && provision.getMapping() != null) {
-                MappingItem connObjectKeyItem = anyUtilsFactory.getInstance(any).getConnObjectKeyItem(provision);
+                MappingItem connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
                 if (connObjectKeyItem == null) {
                     throw new NotFoundException(
                             "ConnObjectKey mapping for " + any.getType().getKey() + " " + any.getKey()

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/AbstractPropagationTaskExecutor.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/AbstractPropagationTaskExecutor.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/AbstractPropagationTaskExecutor.java
index 6a67ccf..e557699 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/AbstractPropagationTaskExecutor.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/AbstractPropagationTaskExecutor.java
@@ -48,9 +48,9 @@ import org.apache.syncope.core.misc.AuditManager;
 import org.apache.syncope.core.misc.spring.ApplicationContextProvider;
 import org.apache.syncope.core.misc.ConnObjectUtils;
 import org.apache.syncope.core.misc.ExceptionUtils2;
+import org.apache.syncope.core.misc.MappingUtils;
 import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
 import org.apache.syncope.core.persistence.api.entity.Any;
-import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory;
 import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
 import org.apache.syncope.core.persistence.api.entity.group.Group;
 import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
@@ -124,9 +124,6 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
     protected AuditManager auditManager;
 
     @Autowired
-    protected AnyUtilsFactory anyUtilsFactory;
-
-    @Autowired
     protected EntityFactory entityFactory;
 
     @Override
@@ -537,8 +534,7 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
                     task.getPropagationOperation(),
                     new ObjectClass(task.getObjectClassName()),
                     new Uid(connObjectKey),
-                    connector.getOperationOptions(anyUtilsFactory.getInstance(task.getAnyTypeKind()).
-                            getMappingItems(provision, MappingPurpose.PROPAGATION)));
+                    connector.getOperationOptions(MappingUtils.getMappingItems(provision, MappingPurpose.PROPAGATION)));
         } catch (TimeoutException toe) {
             LOG.debug("Request timeout", toe);
             throw toe;

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/PropagationManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/PropagationManagerImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/PropagationManagerImpl.java
index 2649623..59f8994 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/PropagationManagerImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/PropagationManagerImpl.java
@@ -49,8 +49,6 @@ import org.apache.syncope.core.misc.MappingUtils;
 import org.apache.syncope.core.misc.jexl.JexlUtils;
 import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
 import org.apache.syncope.core.persistence.api.entity.Any;
-import org.apache.syncope.core.persistence.api.entity.AnyUtils;
-import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory;
 import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
 import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
 import org.apache.syncope.core.persistence.api.entity.resource.MappingItem;
@@ -102,9 +100,6 @@ public class PropagationManagerImpl implements PropagationManager {
     protected ConnObjectUtils connObjectUtils;
 
     @Autowired
-    protected AnyUtilsFactory anyUtilsFactory;
-
-    @Autowired
     protected VirAttrHandler virAttrHandler;
 
     @Override
@@ -412,8 +407,6 @@ public class PropagationManagerImpl implements PropagationManager {
 
         LOG.debug("Provisioning any {}:\n{}", any, propByRes);
 
-        AnyUtils anyUtils = anyUtilsFactory.getInstance(any);
-
         if (!propByRes.get(ResourceOperation.CREATE).isEmpty()
                 && vAttrsToBeRemoved != null && vAttrsToBeUpdated != null) {
 
@@ -421,9 +414,9 @@ public class PropagationManagerImpl implements PropagationManager {
 
             // update vAttrsToBeUpdated as well
             for (VirAttr<?> virAttr : any.getVirAttrs()) {
-                final String schema = virAttr.getSchema().getKey();
+                String schema = virAttr.getSchema().getKey();
 
-                final AttrMod attributeMod = new AttrMod();
+                AttrMod attributeMod = new AttrMod();
                 attributeMod.setSchema(schema);
                 attributeMod.getValuesToBeAdded().addAll(virAttr.getValues());
 
@@ -446,7 +439,7 @@ public class PropagationManagerImpl implements PropagationManager {
                 } else if (provision == null) {
                     LOG.error("No provision specified on resource {} for type {}, ignoring...",
                             resource, any.getType());
-                } else if (anyUtils.getMappingItems(provision, MappingPurpose.PROPAGATION).isEmpty()) {
+                } else if (MappingUtils.getMappingItems(provision, MappingPurpose.PROPAGATION).isEmpty()) {
                     LOG.warn("Requesting propagation for {} but no propagation mapping provided for {}",
                             any.getType(), resource);
                 } else {
@@ -454,7 +447,7 @@ public class PropagationManagerImpl implements PropagationManager {
                     task.setResource(resource);
                     task.setObjectClassName(
                             resource.getProvision(any.getType()).getObjectClass().getObjectClassValue());
-                    task.setAnyTypeKind(anyUtils.getAnyTypeKind());
+                    task.setAnyTypeKind(any.getType().getKind());
                     if (!deleteOnResource) {
                         task.setAnyKey(any.getKey());
                     }
@@ -462,15 +455,15 @@ public class PropagationManagerImpl implements PropagationManager {
                     task.setPropagationMode(resource.getPropagationMode());
                     task.setOldConnObjectKey(propByRes.getOldConnObjectKey(resource.getKey()));
 
-                    Pair<String, Set<Attribute>> preparedAttrs = MappingUtils.prepareAttributes(anyUtils, any,
-                            password, changePwd, vAttrsToBeRemoved, vAttrsToBeUpdated, enable, provision);
+                    Pair<String, Set<Attribute>> preparedAttrs = MappingUtils.prepareAttrs(
+                            any, password, changePwd, vAttrsToBeRemoved, vAttrsToBeUpdated, enable, provision);
                     task.setConnObjectKey(preparedAttrs.getKey());
 
                     // Check if any of mandatory attributes (in the mapping) is missing or not received any value: 
                     // if so, add special attributes that will be evaluated by PropagationTaskExecutor
                     List<String> mandatoryMissing = new ArrayList<>();
                     List<String> mandatoryNullOrEmpty = new ArrayList<>();
-                    for (MappingItem item : anyUtils.getMappingItems(provision, MappingPurpose.PROPAGATION)) {
+                    for (MappingItem item : MappingUtils.getMappingItems(provision, MappingPurpose.PROPAGATION)) {
                         if (!item.isConnObjectKey()
                                 && JexlUtils.evaluateMandatoryCondition(item.getMandatoryCondition(), any)) {
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncUtils.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncUtils.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncUtils.java
index 71ad319..14c94f70 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncUtils.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/sync/SyncUtils.java
@@ -28,6 +28,7 @@ import org.apache.syncope.common.lib.SyncopeConstants;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.lib.types.MappingPurpose;
 import org.apache.syncope.common.lib.types.SyncPolicySpec;
+import org.apache.syncope.core.misc.MappingUtils;
 import org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException;
 import org.apache.syncope.core.persistence.api.dao.AnyDAO;
 import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
@@ -119,7 +120,7 @@ public class SyncUtils {
 
         List<ConnectorObject> found = connector.search(provision.getObjectClass(),
                 new EqualsFilter(new Name(name)), connector.getOperationOptions(
-                        anyUtils.getMappingItems(provision, MappingPurpose.SYNCHRONIZATION)));
+                        MappingUtils.getMappingItems(provision, MappingPurpose.SYNCHRONIZATION)));
 
         if (found.isEmpty()) {
             LOG.debug("No {} found on {} with __NAME__ {}", provision.getObjectClass(), resource, name);
@@ -162,7 +163,7 @@ public class SyncUtils {
 
         List<Long> result = new ArrayList<>();
 
-        MappingItem connObjectKeyItem = anyUtils.getConnObjectKeyItem(provision);
+        MappingItem connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
         switch (connObjectKeyItem.getIntMappingType()) {
             case UserPlainSchema:
             case GroupPlainSchema:
@@ -249,12 +250,12 @@ public class SyncUtils {
             final ConnectorObject connObj,
             final List<String> altSearchSchemas,
             final Provision provision,
-            final AnyUtils anyUtils) {
+            final AnyTypeKind anyTypeKind) {
 
         // search for external attribute's name/value of each specified name
         Map<String, Attribute> extValues = new HashMap<>();
 
-        for (MappingItem item : anyUtils.getMappingItems(provision, MappingPurpose.SYNCHRONIZATION)) {
+        for (MappingItem item : MappingUtils.getMappingItems(provision, MappingPurpose.SYNCHRONIZATION)) {
             extValues.put(item.getIntAttrName(), connObj.getAttributeByName(item.getExtAttrName()));
         }
 
@@ -309,7 +310,7 @@ public class SyncUtils {
                     : SearchCond.getAndCond(searchCond, nodeCond);
         }
 
-        return search(searchCond, anyUtils.getAnyTypeKind());
+        return search(searchCond, anyTypeKind);
     }
 
     private SyncCorrelationRule getCorrelationRule(final Provision provision, final SyncPolicySpec policySpec) {
@@ -367,7 +368,7 @@ public class SyncUtils {
         return syncRule == null
                 ? altSearchSchemas == null || altSearchSchemas.isEmpty()
                         ? findByConnObjectKeyItem(uid, provision, anyUtils)
-                        : findByAnySearch(connObj, altSearchSchemas, provision, anyUtils)
+                        : findByAnySearch(connObj, altSearchSchemas, provision, anyUtils.getAnyTypeKind())
                 : findByCorrelationRule(connObj, syncRule, anyUtils.getAnyTypeKind());
     }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/54de3984/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AuthenticationITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AuthenticationITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AuthenticationITCase.java
index 8005b24..6ea8cb0 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AuthenticationITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AuthenticationITCase.java
@@ -30,6 +30,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.Predicate;
 import org.apache.commons.collections4.Transformer;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.client.lib.SyncopeClient;
@@ -194,6 +195,8 @@ public class AuthenticationITCase extends AbstractITCase {
         userTO = createUser(userTO);
         assertNotNull(userTO);
 
+        // 1. user assigned to role 1, with search entitlement on realms /odd and /even: won't find anything with 
+        // root realm
         UserService userService2 = clientFactory.create(userTO.getUsername(), "password123").
                 getService(UserService.class);
 
@@ -214,13 +217,20 @@ public class AuthenticationITCase extends AbstractITCase {
         assertFalse(matchedUserKeys.contains(2L));
         assertFalse(matchedUserKeys.contains(5L));
 
+        // 2. user assigned to role 4, with search entitlement on realm /even/two
         UserService userService3 = clientFactory.create("puccini", ADMIN_PWD).getService(UserService.class);
 
         matchedUsers = userService3.search(
                 SyncopeClient.getAnySearchQueryBuilder().realm("/even/two").
                 fiql(SyncopeClient.getUserSearchConditionBuilder().isNotNull("loginDate").query()).build());
         assertNotNull(matchedUsers);
-        assertTrue(matchedUsers.getResult().isEmpty());
+        assertTrue(CollectionUtils.matchesAll(matchedUsers.getResult(), new Predicate<UserTO>() {
+
+            @Override
+            public boolean evaluate(final UserTO matched) {
+                return "/even/two".equals(matched.getRealm());
+            }
+        }));
     }
 
     @Test