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 2013/01/22 17:20:11 UTC

svn commit: r1437022 - in /syncope/trunk: build-tools/src/main/resources/ common/src/main/java/org/apache/syncope/common/to/ core/src/main/java/org/apache/syncope/core/connid/ core/src/main/java/org/apache/syncope/core/persistence/dao/ core/src/main/ja...

Author: ilgrosso
Date: Tue Jan 22 16:20:11 2013
New Revision: 1437022

URL: http://svn.apache.org/viewvc?rev=1437022&view=rev
Log:
[SYNCOPE-249] core: sync extensions implemented (and test case updated)

Modified:
    syncope/trunk/build-tools/src/main/resources/content.ldif
    syncope/trunk/common/src/main/java/org/apache/syncope/common/to/RoleTO.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/UserDAO.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/SyncopeConnector.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/ConnectorFacadeProxy.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/LDAPMembershipSyncActions.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncJob.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncopeSyncResultHandler.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java

Modified: syncope/trunk/build-tools/src/main/resources/content.ldif
URL: http://svn.apache.org/viewvc/syncope/trunk/build-tools/src/main/resources/content.ldif?rev=1437022&r1=1437021&r2=1437022&view=diff
==============================================================================
--- syncope/trunk/build-tools/src/main/resources/content.ldif (original)
+++ syncope/trunk/build-tools/src/main/resources/content.ldif Tue Jan 22 16:20:11 2013
@@ -30,6 +30,7 @@ objectClass: top
 cn: testLDAPGroup
 uniqueMember: uid=admin,ou=system
 uniqueMember: uid=syncFromLDAP,ou=People,o=isp
+owner: uid=syncFromLDAP,ou=People,o=isp
 
 DN: uid=syncFromLDAP,ou=People,o=isp
 objectClass: organizationalPerson

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/to/RoleTO.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/to/RoleTO.java?rev=1437022&r1=1437021&r2=1437022&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/to/RoleTO.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/to/RoleTO.java Tue Jan 22 16:20:11 2013
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 import java.util.List;
 import org.codehaus.jackson.annotate.JsonIgnoreProperties;
 
-@JsonIgnoreProperties({"displayName", "empty"})
+@JsonIgnoreProperties({"displayName"})
 public class RoleTO extends AbstractAttributableTO {
 
     private static final long serialVersionUID = -7785920258290147542L;
@@ -118,15 +118,15 @@ public class RoleTO extends AbstractAttr
         return inheritVirtualAttributes;
     }
 
-    public void setInheritVirtualAttributes(boolean inheritVirtualAttributes) {
+    public void setInheritVirtualAttributes(final boolean inheritVirtualAttributes) {
         this.inheritVirtualAttributes = inheritVirtualAttributes;
     }
 
-    public boolean addEntitlement(String entitlement) {
+    public boolean addEntitlement(final String entitlement) {
         return entitlements.add(entitlement);
     }
 
-    public boolean removeEntitlement(String entitlement) {
+    public boolean removeEntitlement(final String entitlement) {
         return entitlements.remove(entitlement);
     }
 
@@ -134,7 +134,7 @@ public class RoleTO extends AbstractAttr
         return entitlements;
     }
 
-    public void setEntitlements(List<String> entitlements) {
+    public void setEntitlements(final List<String> entitlements) {
         this.entitlements.clear();
         if (entitlements != null && !entitlements.isEmpty()) {
             this.entitlements.addAll(entitlements);
@@ -145,7 +145,7 @@ public class RoleTO extends AbstractAttr
         return passwordPolicy;
     }
 
-    public void setPasswordPolicy(Long passwordPolicy) {
+    public void setPasswordPolicy(final Long passwordPolicy) {
         this.passwordPolicy = passwordPolicy;
     }
 
@@ -158,7 +158,7 @@ public class RoleTO extends AbstractAttr
      *
      * @param inheritPasswordPolicy 'true' to inherit policy, false otherwise.
      */
-    public void setInheritPasswordPolicy(boolean inheritPasswordPolicy) {
+    public void setInheritPasswordPolicy(final boolean inheritPasswordPolicy) {
         this.inheritPasswordPolicy = inheritPasswordPolicy;
     }
 
@@ -166,7 +166,7 @@ public class RoleTO extends AbstractAttr
         return accountPolicy;
     }
 
-    public void setAccountPolicy(Long accountPolicy) {
+    public void setAccountPolicy(final Long accountPolicy) {
         this.accountPolicy = accountPolicy;
     }
 
@@ -179,7 +179,7 @@ public class RoleTO extends AbstractAttr
      *
      * @param inheritAccountPolicy 'true' to inherit policy, false otherwise.
      */
-    public void setInheritAccountPolicy(boolean inheritAccountPolicy) {
+    public void setInheritAccountPolicy(final boolean inheritAccountPolicy) {
         this.inheritAccountPolicy = inheritAccountPolicy;
     }
 
@@ -187,10 +187,6 @@ public class RoleTO extends AbstractAttr
         return getId() + " " + getName();
     }
 
-    public String getEmpty() {
-        return "";
-    }
-
     public static long fromDisplayName(final String displayName) {
         long result = 0;
         if (displayName != null && !displayName.isEmpty() && displayName.indexOf(' ') != -1) {

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java?rev=1437022&r1=1437021&r2=1437022&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java Tue Jan 22 16:20:11 2013
@@ -261,6 +261,18 @@ public class ConnObjectUtil {
                     }
                     break;
 
+                case RoleOwnerSchema:
+                    if (attributableTO instanceof RoleTO && attribute != null && !attribute.getValue().isEmpty()) {
+                        // using a special attribute (with schema "", that will be ignored) for carrying the
+                        // RoleOwnerSchema value
+                        attributeTO = new AttributeTO();
+                        attributeTO.setSchema("");
+                        attributeTO.addValue(attribute.getValue().get(0).toString());
+
+                        ((RoleTO) attributableTO).addAttribute(attributeTO);
+                    }
+                    break;
+
                 case UserSchema:
                 case RoleSchema:
                     attributeTO = new AttributeTO();

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/UserDAO.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/UserDAO.java?rev=1437022&r1=1437021&r2=1437022&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/UserDAO.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/UserDAO.java Tue Jan 22 16:20:11 2013
@@ -20,7 +20,6 @@ package org.apache.syncope.core.persiste
 
 import java.util.List;
 import java.util.Set;
-
 import org.apache.syncope.core.persistence.beans.ExternalResource;
 import org.apache.syncope.core.persistence.beans.user.SyncopeUser;
 import org.apache.syncope.core.persistence.beans.user.UAttrValue;

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/SyncopeConnector.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/SyncopeConnector.java?rev=1437022&r1=1437021&r2=1437022&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/SyncopeConnector.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/SyncopeConnector.java Tue Jan 22 16:20:11 2013
@@ -21,7 +21,6 @@ package org.apache.syncope.core.propagat
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
-
 import org.apache.syncope.common.types.PropagationMode;
 import org.apache.syncope.common.types.ResourceOperation;
 import org.apache.syncope.core.persistence.beans.AbstractMappingItem;
@@ -81,12 +80,12 @@ public interface SyncopeConnector {
     /**
      * Sync users from a connector instance.
      *
-     * @param objectClass ConnId's object class.
+     * @param objectClass ConnId's object class
      * @param token to be passed to the underlying connector
-     * @param handler to be used to handle deltas.
+     * @param handler to be used to handle deltas
+     * @param options ConnId's OperationOptions
      */
-    void sync(ObjectClass objectClass, SyncToken token,
-            SyncResultsHandler handler, OperationOptions options);
+    void sync(ObjectClass objectClass, SyncToken token, SyncResultsHandler handler, OperationOptions options);
 
     /**
      * Read latest sync token from a connector instance.
@@ -104,8 +103,7 @@ public interface SyncopeConnector {
      * @param options ConnId's OperationOptions
      * @return ConnId's connector object for given uid
      */
-    ConnectorObject getObject(ObjectClass objectClass, Uid uid,
-            OperationOptions options);
+    ConnectorObject getObject(ObjectClass objectClass, Uid uid, OperationOptions options);
 
     /**
      * Get remote object used by the propagation manager in order to choose for a create (object doesn't exist) or an
@@ -122,8 +120,15 @@ public interface SyncopeConnector {
             ResourceOperation operationType, ObjectClass objectClass, Uid uid,
             OperationOptions options);
 
-    List<ConnectorObject> search(ObjectClass objectClass, Filter filter,
-            OperationOptions options);
+    /**
+     * Search for remote objects.
+     *
+     * @param objectClass ConnId's object class
+     * @param filter search filter
+     * @param options ConnId's OperationOptions
+     * @return ConnId's connector objects matching the given filter
+     */
+    List<ConnectorObject> search(ObjectClass objectClass, Filter filter, OperationOptions options);
 
     /**
      * Get remote object used by the propagation manager in order to choose for a create (object doesn't exist) or an
@@ -133,8 +138,7 @@ public interface SyncopeConnector {
      * @param handler to be used to handle deltas.
      * @param options ConnId's OperationOptions.
      */
-    void getAllObjects(ObjectClass objectClass, SyncResultsHandler handler,
-            OperationOptions options);
+    void getAllObjects(ObjectClass objectClass, SyncResultsHandler handler, OperationOptions options);
 
     /**
      * Read attribute for a given connector object.
@@ -145,8 +149,7 @@ public interface SyncopeConnector {
      * @param attributeName attribute to read
      * @return attribute (if present)
      */
-    Attribute getObjectAttribute(ObjectClass objectClass, Uid uid,
-            OperationOptions options, String attributeName);
+    Attribute getObjectAttribute(ObjectClass objectClass, Uid uid, OperationOptions options, String attributeName);
 
     /**
      *
@@ -155,8 +158,7 @@ public interface SyncopeConnector {
      * @param options ConnId's OperationOptions
      * @return attributes (if present)
      */
-    Set<Attribute> getObjectAttributes(ObjectClass objectClass, Uid uid,
-            OperationOptions options);
+    Set<Attribute> getObjectAttributes(ObjectClass objectClass, Uid uid, OperationOptions options);
 
     /**
      * Return resource schema names.
@@ -183,9 +185,8 @@ public interface SyncopeConnector {
      */
     ConnInstance getActiveConnInstance();
 
-    OperationOptions getOperationOptions(
-            Collection<AbstractMappingItem> mapItems);
+    OperationOptions getOperationOptions(Collection<AbstractMappingItem> mapItems);
 
+    @Override
     String toString();
-
-}
\ No newline at end of file
+}

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/ConnectorFacadeProxy.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/ConnectorFacadeProxy.java?rev=1437022&r1=1437021&r2=1437022&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/ConnectorFacadeProxy.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/propagation/impl/ConnectorFacadeProxy.java Tue Jan 22 16:20:11 2013
@@ -83,7 +83,7 @@ public class ConnectorFacadeProxy implem
     /**
      * Active Connector instance.
      *
-     * @see org.apache.syncope.core.persistence.beans.ConnInstance
+     * @see ConnInstance
      */
     private final ConnInstance activeConnInstance;
 
@@ -163,7 +163,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#create(org.apache.syncope.common.types.PropagationMode, org.identityconnectors.framework.common.objects.ObjectClass, java.util.Set, org.identityconnectors.framework.common.objects.OperationOptions, java.util.Set)
+     * @see SyncopeConnector#create(PropagationMode, ObjectClass, Set, OperationOptions, Set)
      */
     @Override
     public Uid create(final PropagationMode propagationMode, final ObjectClass objectClass, final Set<Attribute> attrs,
@@ -187,7 +187,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#update(org.apache.syncope.common.types.PropagationMode, org.identityconnectors.framework.common.objects.ObjectClass, org.identityconnectors.framework.common.objects.Uid, java.util.Set, org.identityconnectors.framework.common.objects.OperationOptions, java.util.Set)
+     * @see SyncopeConnector#update(PropagationMode, ObjectClass, Uid, Set, OperationOptions, Set)
      */
     @Override
     public Uid update(final PropagationMode propagationMode, final ObjectClass objectClass, final Uid uid,
@@ -212,7 +212,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#delete(org.apache.syncope.common.types.PropagationMode, org.identityconnectors.framework.common.objects.ObjectClass, org.identityconnectors.framework.common.objects.Uid, org.identityconnectors.framework.common.objects.OperationOptions, java.util.Set)
+     * @see SyncopeConnector#delete(PropagationMode, ObjectClass, Uid, OperationOptions, Set)
      */
     @Override
     public void delete(final PropagationMode propagationMode, final ObjectClass objectClass, final Uid uid,
@@ -232,7 +232,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#sync(org.identityconnectors.framework.common.objects.ObjectClass, org.identityconnectors.framework.common.objects.SyncToken, org.identityconnectors.framework.common.objects.SyncResultsHandler, org.identityconnectors.framework.common.objects.OperationOptions)
+     * @see SyncopeConnector#sync(ObjectClass, SyncToken, SyncResultsHandler, OperationOptions)
      */
     @Override
     public void sync(final ObjectClass objectClass, final SyncToken token, final SyncResultsHandler handler,
@@ -247,7 +247,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#getLatestSyncToken(org.identityconnectors.framework.common.objects.ObjectClass)
+     * @see SyncopeConnector#getLatestSyncToken(ObjectClass)
      */
     @Override
     public SyncToken getLatestSyncToken(final ObjectClass objectClass) {
@@ -264,7 +264,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#getObject(org.identityconnectors.framework.common.objects.ObjectClass, org.identityconnectors.framework.common.objects.Uid, org.identityconnectors.framework.common.objects.OperationOptions)
+     * @see SyncopeConnector#getObject(ObjectClass, Uid, OperationOptions)
      */
     @Override
     public ConnectorObject getObject(final ObjectClass objectClass, final Uid uid, final OperationOptions options) {
@@ -272,7 +272,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#getObject(org.apache.syncope.common.types.PropagationMode, org.apache.syncope.common.types.ResourceOperation, org.identityconnectors.framework.common.objects.ObjectClass, org.identityconnectors.framework.common.objects.Uid, org.identityconnectors.framework.common.objects.OperationOptions)
+     * @see SyncopeConnector#getObject(PropagationMode, ResourceOperation, ObjectClass, Uid, OperationOptions)
      */
     @Override
     public ConnectorObject getObject(final PropagationMode propagationMode, final ResourceOperation operationType,
@@ -318,7 +318,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#search(org.identityconnectors.framework.common.objects.ObjectClass, org.identityconnectors.framework.common.objects.filter.Filter, org.identityconnectors.framework.common.objects.OperationOptions)
+     * @see SyncopeConnector#search(ObjectClass, filter.Filter, OperationOptions)
      */
     @Override
     public List<ConnectorObject> search(final ObjectClass objectClass, final Filter filter,
@@ -343,7 +343,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#getAllObjects(org.identityconnectors.framework.common.objects.ObjectClass, org.identityconnectors.framework.common.objects.SyncResultsHandler, org.identityconnectors.framework.common.objects.OperationOptions)
+     * @see SyncopeConnector#getAllObjects(ObjectClass, SyncResultsHandler, OperationOptions)
      */
     @Override
     public void getAllObjects(final ObjectClass objectClass, final SyncResultsHandler handler,
@@ -371,7 +371,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#getObjectAttribute(org.identityconnectors.framework.common.objects.ObjectClass, org.identityconnectors.framework.common.objects.Uid, org.identityconnectors.framework.common.objects.OperationOptions, java.lang.String)
+     * @see SyncopeConnector#getObjectAttribute(ObjectClass, Uid, OperationOptions, String)
      */
     @Override
     public Attribute getObjectAttribute(final ObjectClass objectClass, final Uid uid, final OperationOptions options,
@@ -390,7 +390,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#getObjectAttributes(org.identityconnectors.framework.common.objects.ObjectClass, org.identityconnectors.framework.common.objects.Uid, org.identityconnectors.framework.common.objects.OperationOptions)
+     * @see SyncopeConnector#getObjectAttributes(ObjectClass, Uid, OperationOptions)
      */
     @Override
     public Set<Attribute> getObjectAttributes(final ObjectClass objectClass, final Uid uid,
@@ -411,7 +411,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#getSchema(boolean)
+     * @see SyncopeConnector#getSchema(boolean)
      */
     @Override
     public Set<String> getSchema(final boolean showall) {
@@ -436,7 +436,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#validate()
+     * @see SyncopeConnector#validate()
      */
     @Override
     public void validate() {
@@ -444,7 +444,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#test()
+     * @see SyncopeConnector#test()
      */
     @Override
     public void test() {
@@ -452,7 +452,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#getActiveConnInstance()
+     * @see SyncopeConnector#getActiveConnInstance()
      */
     @Override
     public ConnInstance getActiveConnInstance() {
@@ -460,7 +460,7 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#getOperationOptions(java.util.Collection)
+     * @see SyncopeConnector#getOperationOptions(Collection)
      */
     @Override
     public OperationOptions getOperationOptions(final Collection<AbstractMappingItem> mapItems) {
@@ -528,12 +528,11 @@ public class ConnectorFacadeProxy implem
     }
 
     /* (non-Javadoc)
-     * @see org.apache.syncope.core.propagation.impl.SyncopeConnector#toString()
+     * @see SyncopeConnector#toString()
      */
     @Override
     public String toString() {
         return "ConnectorFacadeProxy{"
                 + "connector=" + connector + "\n" + "capabitilies=" + activeConnInstance.getCapabilities() + '}';
     }
-
 }

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/LDAPMembershipSyncActions.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/LDAPMembershipSyncActions.java?rev=1437022&r1=1437021&r2=1437022&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/LDAPMembershipSyncActions.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/LDAPMembershipSyncActions.java Tue Jan 22 16:20:11 2013
@@ -28,7 +28,6 @@ import org.apache.syncope.common.mod.Mem
 import org.apache.syncope.common.mod.UserMod;
 import org.apache.syncope.common.to.AbstractAttributableTO;
 import org.apache.syncope.common.to.RoleTO;
-import org.apache.syncope.common.types.AttributableType;
 import org.apache.syncope.core.notification.NotificationManager;
 import org.apache.syncope.core.persistence.beans.ExternalResource;
 import org.apache.syncope.core.persistence.beans.PropagationTask;
@@ -36,24 +35,19 @@ import org.apache.syncope.core.persisten
 import org.apache.syncope.core.persistence.beans.membership.Membership;
 import org.apache.syncope.core.persistence.beans.role.SyncopeRole;
 import org.apache.syncope.core.persistence.dao.RoleDAO;
-import org.apache.syncope.core.propagation.ConnectorFactory;
 import org.apache.syncope.core.propagation.PropagationException;
 import org.apache.syncope.core.propagation.PropagationTaskExecutor;
 import org.apache.syncope.core.propagation.SyncopeConnector;
 import org.apache.syncope.core.propagation.impl.PropagationManager;
 import org.apache.syncope.core.sync.DefaultSyncActions;
 import org.apache.syncope.core.sync.SyncResult;
-import org.apache.syncope.core.util.AttributableUtil;
 import org.apache.syncope.core.workflow.WorkflowResult;
 import org.apache.syncope.core.workflow.user.UserWorkflowAdapter;
 import org.identityconnectors.framework.common.objects.Attribute;
-import org.identityconnectors.framework.common.objects.ConnectorObject;
-import org.identityconnectors.framework.common.objects.Name;
 import org.identityconnectors.framework.common.objects.ObjectClass;
 import org.identityconnectors.framework.common.objects.OperationOptionsBuilder;
 import org.identityconnectors.framework.common.objects.SyncDelta;
 import org.identityconnectors.framework.common.objects.SyncResultsHandler;
-import org.identityconnectors.framework.common.objects.filter.EqualsFilter;
 import org.quartz.JobExecutionException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -74,9 +68,6 @@ public class LDAPMembershipSyncActions e
     protected RoleDAO roleDAO;
 
     @Autowired
-    protected ConnectorFactory connInstanceLoader;
-
-    @Autowired
     protected UserWorkflowAdapter uwfAdapter;
 
     @Autowired
@@ -169,8 +160,8 @@ public class LDAPMembershipSyncActions e
         if (membAttr == null) {
             final OperationOptionsBuilder oob = new OperationOptionsBuilder();
             oob.setAttributesToGet(getGroupMembershipAttrName());
-            membAttr = connector.getObjectAttribute(
-                    ObjectClass.GROUP, delta.getUid(), oob.build(), getGroupMembershipAttrName());
+            membAttr = connector.getObjectAttribute(ObjectClass.GROUP, delta.getUid(), oob.build(),
+                    getGroupMembershipAttrName());
         }
         if (membAttr != null && membAttr.getValue() != null) {
             result = membAttr.getValue();
@@ -221,44 +212,13 @@ public class LDAPMembershipSyncActions e
 
         final SyncTask task = handler.getSyncTask();
         final ExternalResource resource = task.getResource();
-
-        SyncopeConnector connector;
-        try {
-            connector = connInstanceLoader.getConnector(resource);
-        } catch (Exception e) {
-            final String msg = String.format("Connector instance bean for resource %s and connInstance %s not found",
-                    resource, resource.getConnector());
-
-            throw new JobExecutionException(msg, e);
-        }
+        final SyncopeConnector connector = handler.getConnector();
 
         for (Object membValue : getMembAttrValues(delta, connector)) {
-
-            final List<ConnectorObject> found = connector.search(ObjectClass.ACCOUNT,
-                    new EqualsFilter(new Name(membValue.toString())),
-                    connector.getOperationOptions(resource.getUmapping().getItems()));
-
-            if (found.isEmpty()) {
-                LOG.debug("No account found on {} with __NAME__ {}", resource, membValue.toString());
-            } else {
-                if (found.size() > 1) {
-                    LOG.warn("More than one account found on {} with __NAME__ {} - taking first only",
-                            resource, membValue.toString());
-                }
-
-                ConnectorObject externalAccount = found.iterator().next();
-                final List<Long> userIds = handler.findExisting(externalAccount.getUid().getUidValue(),
-                        externalAccount, AttributableUtil.getInstance(AttributableType.USER));
-                if (userIds.isEmpty()) {
-                    LOG.debug("No matching user found for {}, aborting", externalAccount);
-                } else {
-                    if (userIds.size() > 1) {
-                        LOG.warn("More than one user found {} - taking first only", userIds);
-                    }
-
-                    UserMod userMod = getUserMod(userIds.iterator().next(), roleTO);
-                    userUpdate(userMod, resource.getName());
-                }
+            Long userId = handler.findMatchingAttributableId(ObjectClass.ACCOUNT, membValue.toString());
+            if (userId != null) {
+                UserMod userMod = getUserMod(userId, roleTO);
+                userUpdate(userMod, resource.getName());
             }
         }
 

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncJob.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncJob.java?rev=1437022&r1=1437021&r2=1437022&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncJob.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncJob.java Tue Jan 22 16:20:11 2013
@@ -20,7 +20,10 @@ package org.apache.syncope.core.sync.imp
 
 import java.util.ArrayList;
 import java.util.List;
-
+import java.util.Map;
+import org.apache.commons.lang.StringUtils;
+import org.apache.syncope.common.mod.ReferenceMod;
+import org.apache.syncope.common.mod.RoleMod;
 import org.apache.syncope.common.types.ConflictResolutionAction;
 import org.apache.syncope.common.types.SyncPolicySpec;
 import org.apache.syncope.common.types.TraceLevel;
@@ -33,13 +36,18 @@ import org.apache.syncope.core.persisten
 import org.apache.syncope.core.persistence.beans.user.UMapping;
 import org.apache.syncope.core.persistence.dao.EntitlementDAO;
 import org.apache.syncope.core.persistence.dao.ResourceDAO;
+import org.apache.syncope.core.persistence.dao.RoleDAO;
+import org.apache.syncope.core.persistence.dao.UserDAO;
 import org.apache.syncope.core.propagation.ConnectorFactory;
 import org.apache.syncope.core.propagation.SyncopeConnector;
 import org.apache.syncope.core.quartz.AbstractTaskJob;
+import org.apache.syncope.core.rest.controller.UnauthorizedRoleException;
 import org.apache.syncope.core.sync.SyncActions;
 import org.apache.syncope.core.sync.SyncResult;
 import org.apache.syncope.core.util.ApplicationContextProvider;
 import org.apache.syncope.core.util.EntitlementUtil;
+import org.apache.syncope.core.util.NotFoundException;
+import org.apache.syncope.core.workflow.role.RoleWorkflowAdapter;
 import org.identityconnectors.framework.common.objects.ObjectClass;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -79,6 +87,24 @@ public class SyncJob extends AbstractTas
     private EntitlementDAO entitlementDAO;
 
     /**
+     * Role DAO.
+     */
+    @Autowired
+    private UserDAO userDAO;
+
+    /**
+     * Role DAO.
+     */
+    @Autowired
+    private RoleDAO roleDAO;
+
+    /**
+     * Role workflow adapter.
+     */
+    @Autowired
+    private RoleWorkflowAdapter rwfAdapter;
+
+    /**
      * SyncJob actions.
      */
     private SyncActions actions;
@@ -302,6 +328,32 @@ public class SyncJob extends AbstractTas
                 new UsernamePasswordAuthenticationToken(userDetails, "FAKE_PASSWORD", authorities));
     }
 
+    protected void setRoleOwners(final SyncopeSyncResultHandler handler)
+            throws UnauthorizedRoleException, NotFoundException {
+
+        for (Map.Entry<Long, String> entry : handler.getRoleOwnerMap().entrySet()) {
+            RoleMod roleMod = new RoleMod();
+            roleMod.setId(entry.getKey());
+
+            if (StringUtils.isBlank(entry.getValue())) {
+                roleMod.setRoleOwner(null);
+                roleMod.setUserOwner(null);
+            } else {
+                Long userId = handler.findMatchingAttributableId(ObjectClass.ACCOUNT, entry.getValue());
+                if (userId == null) {
+                    Long roleId = handler.findMatchingAttributableId(ObjectClass.GROUP, entry.getValue());
+                    if (roleId != null) {
+                        roleMod.setRoleOwner(new ReferenceMod(roleId));
+                    }
+                } else {
+                    roleMod.setUserOwner(new ReferenceMod(userId));
+                }
+            }
+
+            rwfAdapter.update(roleMod);
+        }
+    }
+
     @Override
     protected String doExecute(final boolean dryRun) throws JobExecutionException {
         // get all entitlements to perform updates
@@ -349,7 +401,8 @@ public class SyncJob extends AbstractTas
         final SyncopeSyncResultHandler handler =
                 (SyncopeSyncResultHandler) ((DefaultListableBeanFactory) ApplicationContextProvider.
                 getApplicationContext().getBeanFactory()).createBean(
-                SyncopeSyncResultHandler.class, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
+                SyncopeSyncResultHandler.class, AbstractBeanDefinition.AUTOWIRE_BY_NAME, false);
+        handler.setConnector(connector);
         handler.setActions(actions);
         handler.setDryRun(dryRun);
         handler.setResAct(resAct);
@@ -391,6 +444,13 @@ public class SyncJob extends AbstractTas
         } catch (Exception e) {
             throw new JobExecutionException("While syncing on connector", e);
         }
+
+        try {
+            setRoleOwners(handler);
+        } catch (Exception e) {
+            LOG.error("While setting role owners", e);
+        }
+
         actions.afterAll(handler, results);
 
         final String result = createReport(results, syncTask.getResource().getSyncTraceLevel(), dryRun);

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncopeSyncResultHandler.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncopeSyncResultHandler.java?rev=1437022&r1=1437021&r2=1437022&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncopeSyncResultHandler.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/sync/impl/SyncopeSyncResultHandler.java Tue Jan 22 16:20:11 2013
@@ -25,12 +25,14 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import org.apache.syncope.common.mod.AbstractAttributableMod;
+import org.apache.syncope.common.mod.AttributeMod;
 import org.apache.syncope.common.mod.RoleMod;
 import org.apache.syncope.common.mod.UserMod;
 import org.apache.syncope.common.search.AttributableCond;
 import org.apache.syncope.common.search.AttributeCond;
 import org.apache.syncope.common.search.NodeCond;
 import org.apache.syncope.common.to.AbstractAttributableTO;
+import org.apache.syncope.common.to.AttributeTO;
 import org.apache.syncope.common.to.RoleTO;
 import org.apache.syncope.common.to.UserTO;
 import org.apache.syncope.common.types.AttributableType;
@@ -56,6 +58,7 @@ import org.apache.syncope.core.persisten
 import org.apache.syncope.core.persistence.validation.attrvalue.ParsingValidationException;
 import org.apache.syncope.core.propagation.PropagationException;
 import org.apache.syncope.core.propagation.PropagationTaskExecutor;
+import org.apache.syncope.core.propagation.SyncopeConnector;
 import org.apache.syncope.core.propagation.impl.PropagationManager;
 import org.apache.syncope.core.rest.controller.UnauthorizedRoleException;
 import org.apache.syncope.core.rest.data.RoleDataBinder;
@@ -71,10 +74,13 @@ import org.apache.syncope.core.workflow.
 import org.identityconnectors.framework.common.objects.Attribute;
 import org.identityconnectors.framework.common.objects.AttributeUtil;
 import org.identityconnectors.framework.common.objects.ConnectorObject;
+import org.identityconnectors.framework.common.objects.Name;
+import org.identityconnectors.framework.common.objects.ObjectClass;
 import org.identityconnectors.framework.common.objects.OperationalAttributes;
 import org.identityconnectors.framework.common.objects.SyncDelta;
 import org.identityconnectors.framework.common.objects.SyncDeltaType;
 import org.identityconnectors.framework.common.objects.SyncResultsHandler;
+import org.identityconnectors.framework.common.objects.filter.EqualsFilter;
 import org.quartz.JobExecutionException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -112,7 +118,7 @@ public class SyncopeSyncResultHandler im
     private RoleDAO roleDAO;
 
     /**
-     * User search DAO.
+     * Search DAO.
      */
     @Autowired
     private AttributableSearchDAO searchDAO;
@@ -166,6 +172,11 @@ public class SyncopeSyncResultHandler im
     private NotificationManager notificationManager;
 
     /**
+     * Syncing connector.
+     */
+    private SyncopeConnector connector;
+
+    /**
      * SyncJob actions.
      */
     private SyncActions actions;
@@ -178,6 +189,16 @@ public class SyncopeSyncResultHandler im
 
     private boolean dryRun;
 
+    private Map<Long, String> roleOwnerMap = new HashMap<Long, String>();
+
+    public SyncopeConnector getConnector() {
+        return connector;
+    }
+
+    public void setConnector(final SyncopeConnector connector) {
+        this.connector = connector;
+    }
+
     public SyncActions getActions() {
         return actions;
     }
@@ -218,6 +239,10 @@ public class SyncopeSyncResultHandler im
         this.dryRun = dryRun;
     }
 
+    public Map<Long, String> getRoleOwnerMap() {
+        return roleOwnerMap;
+    }
+
     @Override
     public boolean handle(final SyncDelta delta) {
         try {
@@ -389,6 +414,39 @@ public class SyncopeSyncResultHandler im
                 : findByAttributableSearch(connObj, policySpec, attrUtil);
     }
 
+    public Long findMatchingAttributableId(final ObjectClass objectClass, final String name) {
+        Long result = null;
+
+        final AttributableUtil attrUtil = AttributableUtil.getInstance(objectClass);
+
+        final List<ConnectorObject> found = connector.search(objectClass,
+                new EqualsFilter(new Name(name)),
+                connector.getOperationOptions(attrUtil.getMappingItems(syncTask.getResource())));
+
+        if (found.isEmpty()) {
+            LOG.debug("No {} found on {} with __NAME__ {}", objectClass, syncTask.getResource(), name);
+        } else {
+            if (found.size() > 1) {
+                LOG.warn("More than one {} found on {} with __NAME__ {} - taking first only",
+                        objectClass, syncTask.getResource(), name);
+            }
+
+            ConnectorObject connObj = found.iterator().next();
+            final List<Long> subjectIds = findExisting(connObj.getUid().getUidValue(), connObj, attrUtil);
+            if (subjectIds.isEmpty()) {
+                LOG.debug("No matching {} found for {}, aborting", attrUtil.getType(), connObj);
+            } else {
+                if (subjectIds.size() > 1) {
+                    LOG.warn("More than one {} found {} - taking first only", attrUtil.getType(), subjectIds);
+                }
+
+                result = subjectIds.iterator().next();
+            }
+        }
+
+        return result;
+    }
+
     protected List<SyncResult> create(SyncDelta delta, final AttributableUtil attrUtil, final boolean dryRun)
             throws JobExecutionException {
 
@@ -447,6 +505,10 @@ public class SyncopeSyncResultHandler im
                 }
                 if (AttributableType.ROLE == attrUtil.getType()) {
                     WorkflowResult<Long> created = rwfAdapter.create((RoleTO) subjectTO);
+                    AttributeTO roleOwner = subjectTO.getAttributeMap().get("");
+                    if (roleOwner != null) {
+                        roleOwnerMap.put(created.getResult(), roleOwner.getValues().iterator().next());
+                    }
 
                     EntitlementUtil.extendAuthContext(created.getResult());
 
@@ -532,6 +594,15 @@ public class SyncopeSyncResultHandler im
                         }
                         if (AttributableType.ROLE == attrUtil.getType()) {
                             WorkflowResult<Long> updated = rwfAdapter.update((RoleMod) mod);
+                            String roleOwner = null;
+                            for (AttributeMod attrMod : mod.getAttributesToBeUpdated()) {
+                                if ("".equals(attrMod.getSchema())) {
+                                    roleOwner = attrMod.getValuesToBeAdded().iterator().next();
+                                }
+                            }
+                            if (roleOwner != null) {
+                                roleOwnerMap.put(updated.getResult(), roleOwner);
+                            }
 
                             List<PropagationTask> tasks = propagationManager.getRoleUpdateTaskIds(updated,
                                     mod.getVirtualAttributesToBeRemoved(), mod.getVirtualAttributesToBeUpdated(),

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java?rev=1437022&r1=1437021&r2=1437022&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java Tue Jan 22 16:20:11 2013
@@ -27,8 +27,8 @@ import static org.junit.Assert.assertTru
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
-
 import org.apache.syncope.common.search.AttributableCond;
+import org.apache.syncope.common.search.AttributeCond;
 import org.apache.syncope.common.search.MembershipCond;
 import org.apache.syncope.common.search.NodeCond;
 import org.apache.syncope.common.to.AttributeTO;
@@ -212,126 +212,112 @@ public class TaskTestITCase extends Abst
         }
     }
 
-	@Test
-	public void sync() {
-		try {
-			// -----------------------------
-			// Create a new user ... it should be updated applying sync policy
-			// -----------------------------
-			UserTO inUserTO = new UserTO();
-			inUserTO.setPassword("password123");
-			String userName = "test9";
-			inUserTO.setUsername(userName);
-			inUserTO.addAttribute(attributeTO("firstname", "nome9"));
-			inUserTO.addAttribute(attributeTO("surname", "cognome"));
-			inUserTO.addAttribute(attributeTO("type", "a type"));
-			inUserTO.addAttribute(attributeTO("fullname", "nome cognome"));
-			inUserTO.addAttribute(attributeTO("userId",
-					"user5@syncope.apache.org"));
-			inUserTO.addAttribute(attributeTO("email",
-					"user5@syncope.apache.org"));
-			inUserTO.addDerivedAttribute(attributeTO("csvuserid", null));
-
-			inUserTO = userService.create(inUserTO);
-			assertNotNull(inUserTO);
-			// -----------------------------
-
-			int usersPre = userService.count();
-			assertNotNull(usersPre);
-
-			// Update sync task
-			SyncTaskTO task = taskService.read(TaskType.SYNCHRONIZATION,
-					SYNC_TASK_ID);
-			assertNotNull(task);
-
-			// add custom SyncJob actions
-			task.setActionsClassName(TestSyncActions.class.getName());
-
-			// add user template
-			UserTO template = new UserTO();
-			template.addAttribute(attributeTO("type",
-					"email == 'test8@syncope.apache.org'? 'TYPE_8': 'TYPE_OTHER'"));
-			template.addDerivedAttribute(attributeTO("cn", null));
-			template.addResource("resource-testdb");
-
-			MembershipTO membershipTO = new MembershipTO();
-			membershipTO.setRoleId(8L);
-			membershipTO.addAttribute(attributeTO("subscriptionDate",
-					"'2009-08-18T16:33:12.203+0200'"));
-			template.addMembership(membershipTO);
-
-			task.setUserTemplate(template);
-
-			SyncTaskTO actual = taskService.update(task.getId(), task);
-			assertNotNull(actual);
-			assertEquals(task.getId(), actual.getId());
-			assertEquals(TestSyncActions.class.getName(),
-					actual.getActionsClassName());
-
-			execSyncTask(SYNC_TASK_ID, 50, false);
-
-			// after execution of the sync task the user data should be synced
-			// from
-			// csv datasource and processed by user template
-			UserTO userTO = userService.read(inUserTO.getId());
-			assertNotNull(userTO);
-			assertEquals("test9", userTO.getUsername());
-			assertEquals(
-					ActivitiDetector.isActivitiEnabledForUsers() ? "active"
-							: "created", userTO.getStatus());
-			assertEquals("test9@syncope.apache.org", userTO.getAttributeMap()
-					.get("email").getValues().get(0));
-			assertEquals("test9@syncope.apache.org", userTO.getAttributeMap()
-					.get("userId").getValues().get(0));
-			assertTrue(Integer.valueOf(userTO.getAttributeMap().get("fullname")
-					.getValues().get(0)) <= 10);
-
-			// check for user template
-			userTO = userService.read("test7");
-			assertNotNull(userTO);
-			assertEquals("TYPE_OTHER", userTO.getAttributeMap().get("type")
-					.getValues().get(0));
-			assertEquals(2, userTO.getResources().size());
-			assertTrue(userTO.getResources().contains("resource-testdb"));
-			assertTrue(userTO.getResources().contains("ws-target-resource-2"));
-			assertEquals(1, userTO.getMemberships().size());
-			assertTrue(userTO.getMemberships().get(0).getAttributeMap()
-					.containsKey("subscriptionDate"));
-
-			userTO = userService.read("test8");
-			assertNotNull(userTO);
-			assertEquals("TYPE_8", userTO.getAttributeMap().get("type")
-					.getValues().get(0));
-
-			// check for sync results
-			int usersPost = userService.count();
-			assertNotNull(usersPost);
-			assertEquals(usersPre + 9, usersPost);
-
-			// Check for issue 215:
-			// * expected disabled user test1
-			// * expected enabled user test2
-
-			userTO = userService.read("test1");
-			assertNotNull(userTO);
-			assertEquals("suspended", userTO.getStatus());
-
-			userTO = userService.read("test3");
-			assertNotNull(userTO);
-			assertEquals("active", userTO.getStatus());
-
-		} finally {
-			// remove initial and synchronized users to make test re-runnable
-			for (int i = 0; i < 10; i++) {
-				String cUserName = "test" + i;
-				UserTO cUserTO = userService.read(cUserName);
-				userService.delete(cUserTO.getId());
-			}
-		}
-	}
+    @Test
+    public void sync() {
+        try {
+            // -----------------------------
+            // Create a new user ... it should be updated applying sync policy
+            // -----------------------------
+            UserTO inUserTO = new UserTO();
+            inUserTO.setPassword("password123");
+            String userName = "test9";
+            inUserTO.setUsername(userName);
+            inUserTO.addAttribute(attributeTO("firstname", "nome9"));
+            inUserTO.addAttribute(attributeTO("surname", "cognome"));
+            inUserTO.addAttribute(attributeTO("type", "a type"));
+            inUserTO.addAttribute(attributeTO("fullname", "nome cognome"));
+            inUserTO.addAttribute(attributeTO("userId", "user5@syncope.apache.org"));
+            inUserTO.addAttribute(attributeTO("email", "user5@syncope.apache.org"));
+            inUserTO.addDerivedAttribute(attributeTO("csvuserid", null));
+
+            inUserTO = userService.create(inUserTO);
+            assertNotNull(inUserTO);
+            // -----------------------------
+
+            int usersPre = userService.count();
+            assertNotNull(usersPre);
+
+            // Update sync task
+            SyncTaskTO task = taskService.read(TaskType.SYNCHRONIZATION, SYNC_TASK_ID);
+            assertNotNull(task);
+
+            // add custom SyncJob actions
+            task.setActionsClassName(TestSyncActions.class.getName());
+
+            // add user template
+            UserTO template = new UserTO();
+            template.addAttribute(attributeTO("type", "email == 'test8@syncope.apache.org'? 'TYPE_8': 'TYPE_OTHER'"));
+            template.addDerivedAttribute(attributeTO("cn", null));
+            template.addResource("resource-testdb");
+
+            MembershipTO membershipTO = new MembershipTO();
+            membershipTO.setRoleId(8L);
+            membershipTO.addAttribute(attributeTO("subscriptionDate", "'2009-08-18T16:33:12.203+0200'"));
+            template.addMembership(membershipTO);
+
+            task.setUserTemplate(template);
+
+            SyncTaskTO actual = taskService.update(task.getId(), task);
+            assertNotNull(actual);
+            assertEquals(task.getId(), actual.getId());
+            assertEquals(TestSyncActions.class.getName(), actual.getActionsClassName());
+
+            execSyncTask(SYNC_TASK_ID, 50, false);
+
+            // after execution of the sync task the user data should be synced
+            // from
+            // csv datasource and processed by user template
+            UserTO userTO = userService.read(inUserTO.getId());
+            assertNotNull(userTO);
+            assertEquals("test9", userTO.getUsername());
+            assertEquals(ActivitiDetector.isActivitiEnabledForUsers() ? "active"
+                    : "created", userTO.getStatus());
+            assertEquals("test9@syncope.apache.org", userTO.getAttributeMap().get("email").getValues().get(0));
+            assertEquals("test9@syncope.apache.org", userTO.getAttributeMap().get("userId").getValues().get(0));
+            assertTrue(Integer.valueOf(userTO.getAttributeMap().get("fullname").getValues().get(0)) <= 10);
+
+            // check for user template
+            userTO = userService.read("test7");
+            assertNotNull(userTO);
+            assertEquals("TYPE_OTHER", userTO.getAttributeMap().get("type").getValues().get(0));
+            assertEquals(2, userTO.getResources().size());
+            assertTrue(userTO.getResources().contains("resource-testdb"));
+            assertTrue(userTO.getResources().contains("ws-target-resource-2"));
+            assertEquals(1, userTO.getMemberships().size());
+            assertTrue(userTO.getMemberships().get(0).getAttributeMap().containsKey("subscriptionDate"));
+
+            userTO = userService.read("test8");
+            assertNotNull(userTO);
+            assertEquals("TYPE_8", userTO.getAttributeMap().get("type").getValues().get(0));
+
+            // check for sync results
+            int usersPost = userService.count();
+            assertNotNull(usersPost);
+            assertEquals(usersPre + 9, usersPost);
+
+            // Check for issue 215:
+            // * expected disabled user test1
+            // * expected enabled user test2
+
+            userTO = userService.read("test1");
+            assertNotNull(userTO);
+            assertEquals("suspended", userTO.getStatus());
+
+            userTO = userService.read("test3");
+            assertNotNull(userTO);
+            assertEquals("active", userTO.getStatus());
+        } finally {
+            // remove initial and synchronized users to make test re-runnable
+            for (int i = 0; i < 10; i++) {
+                String cUserName = "test" + i;
+                UserTO cUserTO = userService.read(cUserName);
+                userService.delete(cUserTO.getId());
+            }
+        }
+    }
 
     @Test
-    public void reconcileUsers() {
+    public void reconcileFromDB() {
         // Update sync task
         SyncTaskTO task = taskService.read(TaskType.SYNCHRONIZATION, 7L);
         assertNotNull(task);
@@ -363,7 +349,7 @@ public class TaskTestITCase extends Abst
     }
 
     @Test
-    public void reconcileRoles() {
+    public void reconcileFromLDAP() {
         // Update sync task
         SyncTaskTO task = taskService.read(TaskType.SYNCHRONIZATION, 11L);
         assertNotNull(task);
@@ -396,11 +382,20 @@ public class TaskTestITCase extends Abst
         assertNotNull(matchingRoles);
         assertEquals(1, matchingRoles.size());
 
+        final AttributableCond usernameLeafCond = new AttributableCond(AttributeCond.Type.EQ);
+        usernameLeafCond.setSchema("username");
+        usernameLeafCond.setExpression("syncFromLDAP");
+        final List<UserTO> matchingUsers = userService.search(NodeCond.getLeafCond(usernameLeafCond));
+        assertNotNull(matchingUsers);
+        assertEquals(1, matchingUsers.size());
+
         final RoleTO roleTO = matchingRoles.iterator().next();
         assertNotNull(roleTO);
         assertEquals("testLDAPGroup", roleTO.getName());
         assertEquals(8L, roleTO.getParent());
         assertEquals("true", roleTO.getAttributeMap().get("show").getValues().get(0));
+        assertEquals(matchingUsers.iterator().next().getId(), (long) roleTO.getUserOwner());
+        assertNull(roleTO.getRoleOwner());
 
         // 3. verify that LDAP group membership is propagated as Syncope role membership
         final MembershipCond membershipCond = new MembershipCond();
@@ -485,13 +480,13 @@ public class TaskTestITCase extends Abst
             assertNotNull(taskTO);
             assertEquals(1, taskTO.getExecutions().size());
         } finally {
-        	// Remove execution to make test re-runnable
-        	TaskExecTO taskExecTO = taskService.deleteExecution(taskTO.getExecutions().get(0).getId());
-        	assertNotNull(taskExecTO);
+            // Remove execution to make test re-runnable
+            TaskExecTO taskExecTO = taskService.deleteExecution(taskTO.getExecutions().get(0).getId());
+            assertNotNull(taskExecTO);
         }
     }
 
-	private NotificationTaskTO findNotificationTaskBySender(String sender) {		
+    private NotificationTaskTO findNotificationTaskBySender(String sender) {
         List<NotificationTaskTO> tasks = taskService.list(TaskType.NOTIFICATION);
         assertNotNull(tasks);
         assertFalse(tasks.isEmpty());
@@ -502,12 +497,12 @@ public class TaskTestITCase extends Abst
                 taskTO = task;
             }
         }
-		return taskTO;
-	}
+        return taskTO;
+    }
 
-	private String createNotificationTask() {
-		// 1. Create notification
-		NotificationTO notification = new NotificationTO();
+    private String createNotificationTask() {
+        // 1. Create notification
+        NotificationTO notification = new NotificationTO();
         notification.setTraceLevel(TraceLevel.FAILURES);
         notification.addEvent("create");
 
@@ -540,8 +535,8 @@ public class TaskTestITCase extends Abst
 
         userTO = userService.create(userTO);
         assertNotNull(userTO);
-		return sender;
-	}
+        return sender;
+    }
 
     @Test
     public void issueSYNCOPE68() {
@@ -559,8 +554,8 @@ public class TaskTestITCase extends Abst
         userTO.addAttribute(attributeTO("userId", "testuser2@syncope.apache.org"));
         userTO.addAttribute(attributeTO("email", "testuser2@syncope.apache.org"));
 
-    	userTO.addResource("ws-target-resource-nopropagation2");
-    	userTO.addResource("ws-target-resource-nopropagation4");
+        userTO.addResource("ws-target-resource-nopropagation2");
+        userTO.addResource("ws-target-resource-nopropagation4");
 
         MembershipTO membershipTO = new MembershipTO();
         membershipTO.setRoleId(7L);
@@ -611,15 +606,15 @@ public class TaskTestITCase extends Abst
             assertEquals(2, userTO.getMemberships().size());
             assertEquals(4, userTO.getResources().size());
         } finally {
-        	UserTO dUserTO = userService.delete(userTO.getId());
-        	assertNotNull(dUserTO);
+            UserTO dUserTO = userService.delete(userTO.getId());
+            assertNotNull(dUserTO);
         }
-    	System.out.println("After");
+        System.out.println("After");
         List<PropagationTaskTO> tasksA = taskService.list(TaskType.PROPAGATION);
         for (PropagationTaskTO task : tasksA) {
-        	System.out.println(task.getId());
-        	System.out.println(task.getAccountId());
-        	System.out.println(task.getOldAccountId());
+            System.out.println(task.getId());
+            System.out.println(task.getAccountId());
+            System.out.println(task.getOldAccountId());
         }
     }
 
@@ -712,9 +707,9 @@ public class TaskTestITCase extends Abst
     @Test
     public void issueSYNCOPE272() {
 
-    	try {
-        	//Create user with testdb resource
-        	UserTO userTO = UserTestITCase.getUniqueSampleTO("syncope272@syncope.apache.org");
+        try {
+            //Create user with testdb resource
+            UserTO userTO = UserTestITCase.getUniqueSampleTO("syncope272@syncope.apache.org");
             userTO.addResource("resource-testdb");
 
             userTO = userService.create(userTO);
@@ -756,13 +751,13 @@ public class TaskTestITCase extends Abst
             userTO = userService.read(userTO.getUsername());
             assertNotNull(userTO);
             assertNotNull(userTO.getAttributeMap().get("firstname").getValues().get(0));
-    	} finally {
-			// remove initial and synchronized users to make test re-runnable
-			for (int i = 0; i < 10; i++) {
-				String cUserName = "test" + i;
-				UserTO cUserTO = userService.read(cUserName);
-				userService.delete(cUserTO.getId());
-			}
-    	}
+        } finally {
+            // remove initial and synchronized users to make test re-runnable
+            for (int i = 0; i < 10; i++) {
+                String cUserName = "test" + i;
+                UserTO cUserTO = userService.read(cUserName);
+                userService.delete(cUserTO.getId());
+            }
+        }
     }
 }
\ No newline at end of file