syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [2/2] syncope git commit: [SYNCOPE-1200] Ensuring createApproval works, besides updateApproval
Date Tue, 29 Aug 2017 12:47:47 GMT
[SYNCOPE-1200] Ensuring createApproval works, besides updateApproval


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

Branch: refs/heads/master
Commit: 93b84e7ed4be0a33e5e955df4c15e41a05bb57e0
Parents: 1fa7fe1
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Tue Aug 29 14:43:13 2017 +0200
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Tue Aug 29 14:47:37 2017 +0200

----------------------------------------------------------------------
 .../java/data/AbstractAnyDataBinder.java        |  9 ++----
 .../java/data/AnyObjectDataBinderImpl.java      |  7 +++--
 .../java/data/GroupDataBinderImpl.java          | 10 ++++---
 .../java/data/UserDataBinderImpl.java           |  8 +++---
 .../cxf/service/UserWorkflowServiceImpl.java    | 12 ++++----
 .../flowable/FlowableUserWorkflowAdapter.java   | 28 +++++++++++++++++--
 .../workflow/flowable/task/AutoActivate.java    | 29 ++++++++++++++++++++
 .../syncope/fit/core/UserWorkflowITCase.java    | 15 +++++++++-
 8 files changed, 91 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/93b84e7e/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 dbf992b..0c7ed6f 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
@@ -75,7 +75,6 @@ import org.apache.syncope.core.persistence.api.entity.group.Group;
 import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
 import org.apache.syncope.core.persistence.api.entity.resource.MappingItem;
 import org.apache.syncope.core.persistence.api.entity.resource.Provision;
-import org.apache.syncope.core.persistence.api.entity.user.User;
 import org.apache.syncope.core.provisioning.api.DerAttrHandler;
 import org.apache.syncope.core.provisioning.api.IntAttrName;
 import org.apache.syncope.core.provisioning.api.MappingManager;
@@ -640,14 +639,10 @@ abstract class AbstractAnyDataBinder {
         return membershipTO;
     }
 
-    protected Map<String, String> getConnObjectKeys(final Any<?> any) {
+    protected Map<String, String> getConnObjectKeys(final Any<?> any, final AnyUtils
anyUtils) {
         Map<String, String> connObjectKeys = new HashMap<>();
 
-        Iterable<? extends ExternalResource> iterable = any instanceof User
-                ? userDAO.findAllResources((User) any)
-                : any instanceof AnyObject
-                        ? anyObjectDAO.findAllResources((AnyObject) any)
-                        : ((Group) any).getResources();
+        Iterable<? extends ExternalResource> iterable = anyUtils.getAllResources(any);
         for (ExternalResource resource : iterable) {
             Optional<? extends Provision> provision = resource.getProvision(any.getType());
             if (provision.isPresent() && provision.get().getMapping() != null) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/93b84e7e/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java
index 78811e5..8827a19 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java
@@ -251,10 +251,12 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements
An
 
         SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
 
+        AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.ANY_OBJECT);
+
         Collection<String> currentResources = anyObjectDAO.findAllResourceKeys(anyObject.getKey());
 
         // fetch connObjectKeys before update
-        Map<String, String> oldConnObjectKeys = getConnObjectKeys(anyObject);
+        Map<String, String> oldConnObjectKeys = getConnObjectKeys(anyObject, anyUtils);
 
         // realm
         setRealm(anyObject, anyObjectPatch);
@@ -266,7 +268,6 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements
An
             anyObject.setName(anyObjectPatch.getName().getValue());
         }
 
-        AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.ANY_OBJECT);
         // attributes and resources
         propByRes.merge(fill(anyObject, anyObjectPatch, anyUtils, scce));
 
@@ -416,7 +417,7 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements
An
         }
 
         // check if some connObjectKey was changed by the update above
-        Map<String, String> newcCnnObjectKeys = getConnObjectKeys(anyObject);
+        Map<String, String> newcCnnObjectKeys = getConnObjectKeys(anyObject, anyUtils);
         oldConnObjectKeys.entrySet().stream().
                 filter(entry -> newcCnnObjectKeys.containsKey(entry.getKey())
                 && !entry.getValue().equals(newcCnnObjectKeys.get(entry.getKey()))).

http://git-wip-us.apache.org/repos/asf/syncope/blob/93b84e7e/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/GroupDataBinderImpl.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/GroupDataBinderImpl.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/GroupDataBinderImpl.java
index 8ba464e..da70ed8 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/GroupDataBinderImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/GroupDataBinderImpl.java
@@ -43,6 +43,7 @@ import org.apache.syncope.core.persistence.api.dao.search.SearchCond;
 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.AnyTypeClass;
+import org.apache.syncope.core.persistence.api.entity.AnyUtils;
 import org.apache.syncope.core.persistence.api.entity.DerSchema;
 import org.apache.syncope.core.persistence.api.entity.DynGroupMembership;
 import org.apache.syncope.core.persistence.api.entity.Entity;
@@ -192,8 +193,10 @@ public class GroupDataBinderImpl extends AbstractAnyDataBinder implements
GroupD
 
         SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
 
+        AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.GROUP);
+
         // fetch connObjectKeys before update
-        Map<String, String> oldConnObjectKeys = getConnObjectKeys(group);
+        Map<String, String> oldConnObjectKeys = getConnObjectKeys(group, anyUtils);
 
         // realm
         setRealm(group, groupPatch);
@@ -218,15 +221,14 @@ public class GroupDataBinderImpl extends AbstractAnyDataBinder implements
GroupD
         }
 
         // attributes and resources
-        propByRes.merge(fill(group, groupPatch, anyUtilsFactory.getInstance(AnyTypeKind.GROUP),
scce));
+        propByRes.merge(fill(group, groupPatch, anyUtils, scce));
 
         // check if some connObjectKey was changed by the update above
-        Map<String, String> newConnObjectKeys = getConnObjectKeys(group);
+        Map<String, String> newConnObjectKeys = getConnObjectKeys(group, anyUtils);
         oldConnObjectKeys.entrySet().stream().
                 filter(entry -> newConnObjectKeys.containsKey(entry.getKey())
                 && !entry.getValue().equals(newConnObjectKeys.get(entry.getKey()))).
                 forEach(entry -> {
-
                     propByRes.addOldConnObjectKey(entry.getKey(), entry.getValue());
                     propByRes.add(ResourceOperation.UPDATE, entry.getKey());
                 });

http://git-wip-us.apache.org/repos/asf/syncope/blob/93b84e7e/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java
b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java
index 9950dd4..d1ce405 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java
@@ -296,10 +296,12 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements
UserDat
 
         SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
 
+        AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.USER);
+
         Collection<String> currentResources = userDAO.findAllResourceKeys(user.getKey());
 
         // fetch connObjectKeys before update
-        Map<String, String> oldConnObjectKeys = getConnObjectKeys(user);
+        Map<String, String> oldConnObjectKeys = getConnObjectKeys(user, anyUtils);
 
         // realm
         setRealm(user, userPatch);
@@ -369,7 +371,6 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements
UserDat
             }
         }
 
-        AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.USER);
         // attributes and resources
         propByRes.merge(fill(user, userPatch, anyUtils, scce));
 
@@ -519,12 +520,11 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements
UserDat
         }
 
         // check if some connObjectKey was changed by the update above
-        Map<String, String> newcCnnObjectKeys = getConnObjectKeys(user);
+        Map<String, String> newcCnnObjectKeys = getConnObjectKeys(user, anyUtils);
         oldConnObjectKeys.entrySet().stream().
                 filter(entry -> newcCnnObjectKeys.containsKey(entry.getKey())
                 && !entry.getValue().equals(newcCnnObjectKeys.get(entry.getKey()))).
                 forEach(entry -> {
-
                     propByRes.addOldConnObjectKey(entry.getKey(), entry.getValue());
                     propByRes.add(ResourceOperation.UPDATE, entry.getKey());
                 });

http://git-wip-us.apache.org/repos/asf/syncope/blob/93b84e7e/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserWorkflowServiceImpl.java
----------------------------------------------------------------------
diff --git a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserWorkflowServiceImpl.java
b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserWorkflowServiceImpl.java
index a3e6040..c24d66f 100644
--- a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserWorkflowServiceImpl.java
+++ b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserWorkflowServiceImpl.java
@@ -30,30 +30,30 @@ import org.springframework.stereotype.Service;
 public class UserWorkflowServiceImpl implements UserWorkflowService {
 
     @Autowired
-    private UserWorkflowLogic lofic;
+    private UserWorkflowLogic logic;
 
     @Override
     public WorkflowFormTO claimForm(final String taskId) {
-        return lofic.claimForm(taskId);
+        return logic.claimForm(taskId);
     }
 
     @Override
     public UserTO executeTask(final String taskId, final UserTO userTO) {
-        return lofic.executeWorkflowTask(userTO, taskId);
+        return logic.executeWorkflowTask(userTO, taskId);
     }
 
     @Override
     public WorkflowFormTO getFormForUser(final String userKey) {
-        return lofic.getFormForUser(userKey);
+        return logic.getFormForUser(userKey);
     }
 
     @Override
     public List<WorkflowFormTO> getForms() {
-        return lofic.getForms();
+        return logic.getForms();
     }
 
     @Override
     public UserTO submitForm(final WorkflowFormTO form) {
-        return lofic.submitForm(form);
+        return logic.submitForm(form);
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/93b84e7e/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/FlowableUserWorkflowAdapter.java
----------------------------------------------------------------------
diff --git a/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/FlowableUserWorkflowAdapter.java
b/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/FlowableUserWorkflowAdapter.java
index 0b32990..4cc0139 100644
--- a/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/FlowableUserWorkflowAdapter.java
+++ b/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/FlowableUserWorkflowAdapter.java
@@ -198,14 +198,33 @@ public class FlowableUserWorkflowAdapter extends AbstractUserWorkflowAdapter
{
     protected void saveForFormSubmit(final User user, final String password, final PropagationByResource
propByRes) {
         String formTaskId = getFormTask(user);
         if (formTaskId != null) {
+            UserTO userTO = engine.getRuntimeService().getVariable(user.getWorkflowId(),
USER_TO, UserTO.class);
+            if (userTO != null) {
+                userTO.setKey(user.getKey());
+                userTO.setCreationDate(user.getCreationDate());
+                userTO.setLastChangeDate(user.getLastChangeDate());
+                if (password == null) {
+                    String encryptedPwd = engine.getRuntimeService().
+                            getVariable(user.getWorkflowId(), ENCRYPTED_PWD, String.class);
+                    if (encryptedPwd != null) {
+                        userTO.setPassword(decrypt(encryptedPwd));
+                    }
+                } else {
+                    userTO.setPassword(password);
+                }
+
+                engine.getRuntimeService().setVariable(user.getWorkflowId(), USER_TO, userTO);
+            }
+
             // SYNCOPE-238: This is needed to simplify the task query in this.getForms()
             engine.getTaskService().setVariableLocal(formTaskId, TASK_IS_FORM, Boolean.TRUE);
+
             engine.getRuntimeService().setVariable(user.getWorkflowId(), PROP_BY_RESOURCE,
propByRes);
             if (propByRes != null) {
                 propByRes.clear();
             }
 
-            if (StringUtils.isNotBlank(password)) {
+            if (password != null) {
                 engine.getRuntimeService().setVariable(user.getWorkflowId(), ENCRYPTED_PWD,
encrypt(password));
             }
         }
@@ -433,13 +452,18 @@ public class FlowableUserWorkflowAdapter extends AbstractUserWorkflowAdapter
{
     public WorkflowResult<String> execute(final UserTO userTO, final String taskId)
{
         User user = userDAO.authFind(userTO.getKey());
 
-        final Map<String, Object> variables = new HashMap<>();
+        Map<String, Object> variables = new HashMap<>();
         variables.put(USER_TO, userTO);
 
         Set<String> performedTasks = doExecuteTask(user, taskId, variables);
         updateStatus(user);
         User updated = userDAO.save(user);
 
+        PropagationByResource propByRes = engine.getRuntimeService().getVariable(
+                user.getWorkflowId(), PROP_BY_RESOURCE, PropagationByResource.class);
+
+        saveForFormSubmit(updated, userTO.getPassword(), propByRes);
+
         return new WorkflowResult<>(updated.getKey(), null, performedTasks);
     }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/93b84e7e/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/task/AutoActivate.java
----------------------------------------------------------------------
diff --git a/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/task/AutoActivate.java
b/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/task/AutoActivate.java
index 8aeb9f9..02ee77f 100644
--- a/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/task/AutoActivate.java
+++ b/core/workflow-flowable/src/main/java/org/apache/syncope/core/workflow/flowable/task/AutoActivate.java
@@ -18,14 +18,43 @@
  */
 package org.apache.syncope.core.workflow.flowable.task;
 
+import org.apache.syncope.common.lib.AnyOperations;
+import org.apache.syncope.common.lib.patch.UserPatch;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.apache.syncope.core.provisioning.api.data.UserDataBinder;
 import org.apache.syncope.core.workflow.flowable.FlowableUserWorkflowAdapter;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 @Component
 public class AutoActivate extends AbstractFlowableServiceTask {
 
+    @Autowired
+    private UserDataBinder dataBinder;
+
+    @Autowired
+    private UserDAO userDAO;
+
     @Override
     protected void doExecute(final String executionId) {
+        User user = engine.getRuntimeService().
+                getVariable(executionId, FlowableUserWorkflowAdapter.USER, User.class);
+        UserTO userTO = engine.getRuntimeService().
+                getVariable(executionId, FlowableUserWorkflowAdapter.USER_TO, UserTO.class);
+        if (userTO != null && userTO.getKey() != null && user.getKey() !=
null) {
+            user = userDAO.save(user);
+
+            UserPatch userPatch = AnyOperations.diff(userTO, dataBinder.getUserTO(user, true),
false);
+            // don't mess with password, as the cleartext values was already properly saved
+            userPatch.setPassword(null);
+
+            dataBinder.update(user, userPatch);
+
+            engine.getRuntimeService().setVariable(executionId, FlowableUserWorkflowAdapter.USER,
user);
+        }
+
         engine.getRuntimeService().setVariable(executionId, FlowableUserWorkflowAdapter.PROPAGATE_ENABLE,
Boolean.TRUE);
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/93b84e7e/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserWorkflowITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserWorkflowITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserWorkflowITCase.java
index 76b9fa0..d8a7431 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserWorkflowITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserWorkflowITCase.java
@@ -29,6 +29,7 @@ import static org.junit.Assert.fail;
 
 import java.util.Collections;
 import java.util.List;
+import java.util.UUID;
 import javax.sql.DataSource;
 import javax.ws.rs.core.Response;
 import org.apache.syncope.client.lib.SyncopeClient;
@@ -180,21 +181,33 @@ public class UserWorkflowITCase extends AbstractITCase {
         assertNotNull(forms);
         assertEquals(preForms + 1, forms.size());
 
+        // 3. as admin, request for changes: still pending approval
+        String updatedUsername = "changed-" + UUID.randomUUID().toString();
+        userTO.setUsername(updatedUsername);
+        userWorkflowService.executeTask("default", userTO);
+
         WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey());
         assertNotNull(form);
         assertNotNull(form.getTaskId());
+        assertNotNull(form.getUserTO());
+        assertEquals(updatedUsername, form.getUserTO().getUsername());
+        assertNull(form.getUserPatch());
         assertNull(form.getOwner());
 
-        // 4. claim task (from admin)
+        // 4. claim task (as admin)
         form = userWorkflowService.claimForm(form.getTaskId());
         assertNotNull(form);
         assertNotNull(form.getTaskId());
+        assertNotNull(form.getUserTO());
+        assertEquals(updatedUsername, form.getUserTO().getUsername());
+        assertNull(form.getUserPatch());
         assertNotNull(form.getOwner());
 
         // 5. approve user (and verify that propagation occurred)
         form.getProperty("approve").get().setValue(Boolean.TRUE.toString());
         userTO = userWorkflowService.submitForm(form);
         assertNotNull(userTO);
+        assertEquals(updatedUsername, userTO.getUsername());
         assertEquals("active", userTO.getStatus());
         assertEquals(Collections.singleton(RESOURCE_NAME_TESTDB), userTO.getResources());
 


Mime
View raw message