syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [1/3] syncope git commit: [SYNCOPE-858] Enhancement provided
Date Tue, 24 May 2016 13:22:29 GMT
Repository: syncope
Updated Branches:
  refs/heads/1_2_X d0b5a5732 -> 73362b1ab


[SYNCOPE-858] Enhancement provided


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

Branch: refs/heads/1_2_X
Commit: 6b63be450bac7c4821dc5a42eb24b5897dd6f380
Parents: d0b5a57
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Mon May 23 13:05:02 2016 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Mon May 23 13:05:02 2016 +0200

----------------------------------------------------------------------
 .../impl/AbstractPropagationTaskExecutor.java   | 39 +++++++++++++++-----
 .../syncope/core/rest/TaskTestITCase.java       | 28 +++++++-------
 2 files changed, 43 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/6b63be45/core/src/main/java/org/apache/syncope/core/propagation/impl/AbstractPropagationTaskExecutor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/propagation/impl/AbstractPropagationTaskExecutor.java
b/core/src/main/java/org/apache/syncope/core/propagation/impl/AbstractPropagationTaskExecutor.java
index 54b7084..14ea42b 100644
--- a/core/src/main/java/org/apache/syncope/core/propagation/impl/AbstractPropagationTaskExecutor.java
+++ b/core/src/main/java/org/apache/syncope/core/propagation/impl/AbstractPropagationTaskExecutor.java
@@ -54,6 +54,7 @@ import org.identityconnectors.framework.common.exceptions.ConnectorException;
 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.ConnectorObjectBuilder;
 import org.identityconnectors.framework.common.objects.Name;
 import org.identityconnectors.framework.common.objects.ObjectClass;
 import org.identityconnectors.framework.common.objects.Uid;
@@ -130,7 +131,7 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
         return result;
     }
 
-    protected void createOrUpdate(
+    protected Uid createOrUpdate(
             final PropagationTask task,
             final ConnectorObject beforeObj,
             final Connector connector,
@@ -160,9 +161,10 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
                     "Not attempted because there are mandatory attributes without value(s):
" + mandatoryAttrNames);
         }
 
+        Uid result;
         if (beforeObj == null) {
             LOG.debug("Create {} on {}", attributes, task.getResource().getName());
-            connector.create(
+            result = connector.create(
                     task.getResource().getPropagationMode(),
                     new ObjectClass(task.getObjectClassName()),
                     attributes,
@@ -197,6 +199,7 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
 
             if (originalAttrs.equals(attributes)) {
                 LOG.debug("Don't need to propagate anything: {} is equal to {}", originalAttrs,
attributes);
+                result = (Uid) AttributeUtil.find(Uid.NAME, attributes);
             } else {
                 LOG.debug("Attributes that would be updated {}", attributes);
 
@@ -210,10 +213,12 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
                 // 3. provision entry
                 LOG.debug("Update {} on {}", strictlyModified, task.getResource().getName());
 
-                connector.update(task.getResource().getPropagationMode(), beforeObj.getObjectClass(),
+                result = connector.update(task.getResource().getPropagationMode(), beforeObj.getObjectClass(),
                         beforeObj.getUid(), strictlyModified, null, propagationAttempted);
             }
         }
+
+        return result;
     }
 
     protected AbstractSubject getSubject(final PropagationTask task) {
@@ -245,11 +250,13 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
         return subject;
     }
 
-    protected void delete(final PropagationTask task, final ConnectorObject beforeObj,
+    protected Uid delete(final PropagationTask task, final ConnectorObject beforeObj,
             final Connector connector, final Set<String> propagationAttempted) {
 
+        Uid result;
         if (beforeObj == null) {
             LOG.debug("{} not found on external resource: ignoring delete", task.getAccountId());
+            result = null;
         } else {
             /*
              * We must choose here whether to
@@ -276,10 +283,13 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
                         beforeObj.getUid(),
                         null,
                         propagationAttempted);
+                result = beforeObj.getUid();
             } else {
-                createOrUpdate(task, beforeObj, connector, propagationAttempted);
+                result = createOrUpdate(task, beforeObj, connector, propagationAttempted);
             }
         }
+
+        return result;
     }
 
     @Override
@@ -298,6 +308,7 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
         Set<String> propagationAttempted = new HashSet<String>();
 
         ConnectorObject beforeObj = null;
+        Uid uid = null;
         ConnectorObject afterObj = null;
 
         Connector connector = null;
@@ -315,11 +326,11 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
             switch (task.getPropagationOperation()) {
                 case CREATE:
                 case UPDATE:
-                    createOrUpdate(task, beforeObj, connector, propagationAttempted);
+                    uid = createOrUpdate(task, beforeObj, connector, propagationAttempted);
                     break;
 
                 case DELETE:
-                    delete(task, beforeObj, connector, propagationAttempted);
+                    uid = delete(task, beforeObj, connector, propagationAttempted);
                     break;
 
                 default:
@@ -363,6 +374,9 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
         } finally {
             // Try to read remote object (user / group) AFTER any actual operation
             if (connector != null) {
+                if (uid != null) {
+                    task.setAccountId(uid.getUidValue());
+                }
                 try {
                     afterObj = getRemoteObject(task, connector, true);
                 } catch (Exception ignore) {
@@ -371,6 +385,14 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
                 }
             }
 
+            if (afterObj == null && uid != null) {
+                afterObj = new ConnectorObjectBuilder().
+                        setObjectClass(new ObjectClass(task.getObjectClassName())).
+                        setUid(uid).
+                        setName(AttributeUtil.getNameFromAttributes(task.getAttributes())).
+                        build();
+            }
+
             LOG.debug("Update execution for {}", task);
 
             execution.setStartDate(startDate);
@@ -435,9 +457,6 @@ public abstract class AbstractPropagationTaskExecutor implements PropagationTask
         execute(tasks, null);
     }
 
-    @Override
-    public abstract void execute(Collection<PropagationTask> tasks, final PropagationReporter
reporter);
-
     /**
      * Check whether an execution has to be stored, for a given task.
      *

http://git-wip-us.apache.org/repos/asf/syncope/blob/6b63be45/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java b/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
index 6862fdd..18329a4 100644
--- a/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
+++ b/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
@@ -52,7 +52,6 @@ import org.apache.syncope.common.to.MembershipTO;
 import org.apache.syncope.common.to.NotificationTO;
 import org.apache.syncope.common.to.NotificationTaskTO;
 import org.apache.syncope.common.to.PropagationTaskTO;
-import org.apache.syncope.common.to.ReportExecTO;
 import org.apache.syncope.common.to.ResourceTO;
 import org.apache.syncope.common.to.RoleTO;
 import org.apache.syncope.common.to.SchedTaskTO;
@@ -395,14 +394,11 @@ public class TaskTestITCase extends AbstractTest {
             assertNotNull(userTO);
             assertEquals("active", userTO.getStatus());
 
-            // SYNCOPE-317
-            execSyncTask(SYNC_TASK_ID, 50, false);
-
-            final Set<Long> pushTaskIds = new HashSet<Long>();
-            pushTaskIds.add(25L);
-            pushTaskIds.add(26L);
+            Set<Long> syncTaskIds = new HashSet<Long>();
+            syncTaskIds.add(25L);
+            syncTaskIds.add(26L);
+            execSyncTasks(syncTaskIds, 50, false);
 
-            execSyncTasks(pushTaskIds, 50, false);
             // Matching --> UNLINK
             assertFalse(readUser("test9").getResources().contains(RESOURCE_NAME_CSV));
             assertFalse(readUser("test7").getResources().contains(RESOURCE_NAME_CSV));
@@ -472,17 +468,18 @@ public class TaskTestITCase extends AbstractTest {
         TaskExecTO execution = execSyncTask(11L, 50, false);
 
         // 1. verify execution status
-        final String status = execution.getStatus();
+        String status = execution.getStatus();
         assertNotNull(status);
         assertTrue(PropagationTaskExecStatus.valueOf(status).isSuccessful());
 
         // 2. verify that synchronized role is found, with expected attributes
-        final PagedResult<RoleTO> matchingRoles = roleService.search(
+        PagedResult<RoleTO> matchingRoles = roleService.search(
                 SyncopeClient.getRoleSearchConditionBuilder().is("name").equalTo("testLDAPGroup").query());
         assertNotNull(matchingRoles);
         assertEquals(1, matchingRoles.getResult().size());
 
-        final PagedResult<UserTO> matchingUsers = userService.search(
+        // 3. verify that synchronized user is found
+        PagedResult<UserTO> matchingUsers = userService.search(
                 SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("syncFromLDAP").query());
         assertNotNull(matchingUsers);
         assertEquals(1, matchingUsers.getResult().size());
@@ -495,7 +492,7 @@ public class TaskTestITCase extends AbstractTest {
         // Check for SYNCOPE-123
         assertNotNull(matchingUsers.getResult().get(0).getAttrMap().get("photo"));
 
-        final RoleTO roleTO = matchingRoles.getResult().iterator().next();
+        RoleTO roleTO = matchingRoles.getResult().iterator().next();
         assertNotNull(roleTO);
         assertEquals("testLDAPGroup", roleTO.getName());
         assertEquals(8L, roleTO.getParent());
@@ -503,8 +500,11 @@ public class TaskTestITCase extends AbstractTest {
         assertEquals(matchingUsers.getResult().iterator().next().getId(), (long) roleTO.getUserOwner());
         assertNull(roleTO.getRoleOwner());
 
-        // 3. verify that LDAP group membership is propagated as Syncope role membership
-        final PagedResult<UserTO> members = userService.search(
+        // SYNCOPE-317
+        execSyncTask(11L, 50, false);
+
+        // 4. verify that LDAP group membership is propagated as Syncope role membership
+        PagedResult<UserTO> members = userService.search(
                 SyncopeClient.getUserSearchConditionBuilder().hasRoles(roleTO.getId()).query());
         assertNotNull(members);
         assertEquals(1, members.getResult().size());


Mime
View raw message