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 2020/12/08 06:32:22 UTC

[syncope] branch 2_1_X updated: Align UserRequestService#submitForm with UserService#update

This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/2_1_X by this push:
     new b62177c  Align UserRequestService#submitForm with UserService#update
b62177c is described below

commit b62177ce9eead5ee646a1488229f25a331c6d9ed
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Tue Dec 8 07:32:06 2020 +0100

    Align UserRequestService#submitForm with UserService#update
---
 .../syncope/core/logic/UserRequestLogic.java       | 13 +++++++--
 .../rest/api/service/UserRequestService.java       | 34 ++++++++++++++++++++--
 .../rest/cxf/service/UserRequestServiceImpl.java   |  7 +++--
 .../syncope/fit/core/AuthenticationITCase.java     |  4 ++-
 .../apache/syncope/fit/core/UserRequestITCase.java |  8 +++--
 .../apache/syncope/fit/core/UserSelfITCase.java    | 18 +++++++-----
 6 files changed, 66 insertions(+), 18 deletions(-)

diff --git a/ext/flowable/logic/src/main/java/org/apache/syncope/core/logic/UserRequestLogic.java b/ext/flowable/logic/src/main/java/org/apache/syncope/core/logic/UserRequestLogic.java
index 28fd0fa..507b5d9 100644
--- a/ext/flowable/logic/src/main/java/org/apache/syncope/core/logic/UserRequestLogic.java
+++ b/ext/flowable/logic/src/main/java/org/apache/syncope/core/logic/UserRequestLogic.java
@@ -25,6 +25,7 @@ import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.common.lib.SyncopeClientException;
 import org.apache.syncope.common.lib.patch.UserPatch;
 import org.apache.syncope.common.lib.to.EntityTO;
+import org.apache.syncope.common.lib.to.ProvisioningResult;
 import org.apache.syncope.common.lib.to.UserRequest;
 import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.syncope.common.lib.to.UserRequestForm;
@@ -42,6 +43,7 @@ import org.apache.syncope.core.provisioning.api.data.UserDataBinder;
 import org.apache.syncope.core.flowable.api.UserRequestHandler;
 import org.apache.syncope.core.persistence.api.dao.NotFoundException;
 import org.apache.syncope.core.provisioning.api.UserWorkflowResult;
+import org.apache.syncope.core.provisioning.api.propagation.PropagationReporter;
 import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskInfo;
 import org.apache.syncope.core.spring.security.AuthContextUtils;
 import org.flowable.engine.runtime.ProcessInstance;
@@ -199,7 +201,7 @@ public class UserRequestLogic extends AbstractTransactionalLogic<EntityTO> {
     }
 
     @PreAuthorize("isAuthenticated()")
-    public UserTO submitForm(final UserRequestForm form) {
+    public ProvisioningResult<UserTO> submitForm(final UserRequestForm form, final boolean nullPriorityAsync) {
         if (form.getUsername() == null) {
             securityChecks(null,
                     FlowableEntitlement.USER_REQUEST_FORM_SUBMIT,
@@ -210,6 +212,8 @@ public class UserRequestLogic extends AbstractTransactionalLogic<EntityTO> {
                     "Submitting forms for user" + form.getUsername() + " not allowed");
         }
 
+        ProvisioningResult<UserTO> result = new ProvisioningResult<>();
+
         UserWorkflowResult<UserPatch> wfResult = userRequestHandler.submitForm(form);
 
         // propByRes can be made empty by the workflow definition if no propagation should occur 
@@ -222,7 +226,8 @@ public class UserRequestLogic extends AbstractTransactionalLogic<EntityTO> {
                             wfResult.getPropByLinkedAccount(),
                             wfResult.getPerformedTasks()));
 
-            taskExecutor.execute(taskInfos, false);
+            PropagationReporter propagationReporter = taskExecutor.execute(taskInfos, nullPriorityAsync);
+            result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
         }
 
         UserTO userTO;
@@ -232,7 +237,9 @@ public class UserRequestLogic extends AbstractTransactionalLogic<EntityTO> {
         } else {
             userTO = binder.getUserTO(wfResult.getResult().getKey());
         }
-        return userTO;
+        result.setEntity(binder.returnUserTO(userTO));
+
+        return result;
     }
 
     @Override
diff --git a/ext/flowable/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/UserRequestService.java b/ext/flowable/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/UserRequestService.java
index 812e55c..348647c 100644
--- a/ext/flowable/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/UserRequestService.java
+++ b/ext/flowable/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/UserRequestService.java
@@ -18,6 +18,11 @@
  */
 package org.apache.syncope.common.rest.api.service;
 
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.enums.ParameterIn;
+import io.swagger.v3.oas.annotations.headers.Header;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
 import io.swagger.v3.oas.annotations.responses.ApiResponse;
 import io.swagger.v3.oas.annotations.responses.ApiResponses;
 import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -34,9 +39,10 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
 import org.apache.syncope.common.lib.to.PagedResult;
+import org.apache.syncope.common.lib.to.ProvisioningResult;
 import org.apache.syncope.common.lib.to.UserRequest;
-import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.syncope.common.lib.to.UserRequestForm;
 import org.apache.syncope.common.lib.to.WorkflowTaskExecInput;
 import org.apache.syncope.common.rest.api.RESTHeaders;
@@ -144,11 +150,33 @@ public interface UserRequestService extends JAXRSService {
      * Submits a user request form.
      *
      * @param form user request form.
-     * @return updated user
+     * @return Response object featuring the updated user enriched with propagation status information
      */
+    @Parameter(
+            name = RESTHeaders.PREFER, in = ParameterIn.HEADER,
+            description = "Allows client to specify a preference for the result to be returned from the server",
+            allowEmptyValue = true, schema =
+            @Schema(defaultValue = "return-content", allowableValues = { "return-content", "return-no-content" }))
+    @Parameter(name = RESTHeaders.NULL_PRIORITY_ASYNC, in = ParameterIn.HEADER,
+            description = "If 'true', instructs the propagation process not to wait for completion when communicating"
+            + " with External Resources with no priority set",
+            allowEmptyValue = true, schema =
+            @Schema(type = "boolean", defaultValue = "false"))
+    @ApiResponses({
+        @ApiResponse(responseCode = "200",
+                description = "User successfully updated enriched with propagation status information, as Entity",
+                content =
+                @Content(schema =
+                        @Schema(implementation = ProvisioningResult.class))),
+        @ApiResponse(responseCode = "204",
+                description = "No content if 'Prefer: return-no-content' was specified", headers =
+                @Header(name = RESTHeaders.PREFERENCE_APPLIED, schema =
+                        @Schema(type = "string"),
+                        description = "Allows the server to inform the "
+                        + "client about the fact that a specified preference was applied")) })
     @POST
     @Path("forms")
     @Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
     @Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML, MediaType.APPLICATION_XML })
-    UserTO submitForm(@NotNull UserRequestForm form);
+    Response submitForm(@NotNull UserRequestForm form);
 }
diff --git a/ext/flowable/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserRequestServiceImpl.java b/ext/flowable/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserRequestServiceImpl.java
index 23ff8c5..6c422de 100644
--- a/ext/flowable/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserRequestServiceImpl.java
+++ b/ext/flowable/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/UserRequestServiceImpl.java
@@ -20,8 +20,10 @@ package org.apache.syncope.core.rest.cxf.service;
 
 import java.util.List;
 import java.util.Optional;
+import javax.ws.rs.core.Response;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.common.lib.to.PagedResult;
+import org.apache.syncope.common.lib.to.ProvisioningResult;
 import org.apache.syncope.common.lib.to.UserRequest;
 import org.apache.syncope.common.lib.to.UserTO;
 import org.apache.syncope.common.lib.to.UserRequestForm;
@@ -94,7 +96,8 @@ public class UserRequestServiceImpl extends AbstractServiceImpl implements UserR
     }
 
     @Override
-    public UserTO submitForm(final UserRequestForm form) {
-        return logic.submitForm(form);
+    public Response submitForm(final UserRequestForm form) {
+        ProvisioningResult<UserTO> submitted = logic.submitForm(form, isNullPriorityAsync());
+        return modificationResponse(submitted);
     }
 }
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java
index 69b5052..59b9db3 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java
@@ -26,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.fail;
 import static org.junit.jupiter.api.Assumptions.assumeFalse;
 import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
+import com.fasterxml.jackson.core.type.TypeReference;
 import java.security.AccessControlException;
 import java.util.Map;
 import java.util.Set;
@@ -503,7 +504,8 @@ public class AuthenticationITCase extends AbstractITCase {
                 new UserRequestQuery.Builder().user(userTO.getKey()).build()).getResult().get(0);
         form = userRequestService.claimForm(form.getTaskId());
         form.getProperty("approveCreate").get().setValue(Boolean.TRUE.toString());
-        userTO = userRequestService.submitForm(form);
+        userTO = userRequestService.submitForm(form).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
+        }).getEntity();
         assertNotNull(userTO);
         assertEquals("active", userTO.getStatus());
 
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserRequestITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserRequestITCase.java
index 9bdabe1..43cabe1 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserRequestITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserRequestITCase.java
@@ -27,6 +27,7 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 import java.io.IOException;
 import java.util.List;
+import javax.ws.rs.core.GenericType;
 import javax.ws.rs.core.MediaType;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.client.WebClient;
@@ -34,6 +35,7 @@ import org.apache.syncope.client.lib.SyncopeClient;
 import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
 import org.apache.syncope.common.lib.SyncopeClientException;
 import org.apache.syncope.common.lib.to.PagedResult;
+import org.apache.syncope.common.lib.to.ProvisioningResult;
 import org.apache.syncope.common.lib.to.RelationshipTO;
 import org.apache.syncope.common.lib.to.UserRequestForm;
 import org.apache.syncope.common.lib.to.UserRequest;
@@ -118,7 +120,8 @@ public class UserRequestITCase extends AbstractITCase {
                 new UserRequestQuery.Builder().user(user.getKey()).build()).getResult().get(0);
         form = userRequestService.claimForm(form.getTaskId());
         form.getProperty("secondLevelApprove").get().setValue(Boolean.FALSE.toString());
-        user = userRequestService.submitForm(form);
+        user = userRequestService.submitForm(form).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
+        }).getEntity();
 
         // no more forms, group not assigned
         assertTrue(userRequestService.listForms(
@@ -141,7 +144,8 @@ public class UserRequestITCase extends AbstractITCase {
                 new UserRequestQuery.Builder().user(user.getKey()).build()).getResult().get(0);
         form = userRequestService.claimForm(form.getTaskId());
         form.getProperty("secondLevelApprove").get().setValue(Boolean.TRUE.toString());
-        user = userRequestService.submitForm(form);
+        user = userRequestService.submitForm(form).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
+        }).getEntity();
 
         // check that the director group was effectively assigned
         assertTrue(user.getMembership("ebf97068-aa4b-4a85-9f01-680e8c4cf227").isPresent());
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserSelfITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserSelfITCase.java
index 7e9a1e0..af8c1d3 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserSelfITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/UserSelfITCase.java
@@ -138,7 +138,8 @@ public class UserSelfITCase extends AbstractITCase {
                 new UserRequestQuery.Builder().user(userTO.getKey()).build()).getResult().get(0);
         form = userRequestService.claimForm(form.getTaskId());
         form.getProperty("approveCreate").get().setValue(Boolean.TRUE.toString());
-        userTO = userRequestService.submitForm(form);
+        userTO = userRequestService.submitForm(form).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
+        }).getEntity();
         assertNotNull(userTO);
         assertEquals("active", userTO.getStatus());
         assertNotNull(resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userTO.getKey()));
@@ -189,7 +190,8 @@ public class UserSelfITCase extends AbstractITCase {
                 new UserRequestQuery.Builder().user(userTO.getKey()).build()).getResult().get(0);
         form = userRequestService.claimForm(form.getTaskId());
         form.getProperty("approveCreate").get().setValue(Boolean.TRUE.toString());
-        userTO = userRequestService.submitForm(form);
+        userTO = userRequestService.submitForm(form).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
+        }).getEntity();
         assertNotNull(userTO);
         assertEquals("active", userTO.getStatus());
         assertNotNull(resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userTO.getKey()));
@@ -289,7 +291,8 @@ public class UserSelfITCase extends AbstractITCase {
                 new UserRequestQuery.Builder().user(updated.getKey()).build()).getResult().get(0);
         form = userRequestService.claimForm(form.getTaskId());
         form.getProperty("approveUpdate").get().setValue(Boolean.TRUE.toString());
-        updated = userRequestService.submitForm(form);
+        updated = userRequestService.submitForm(form).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
+        }).getEntity();
         assertNotNull(updated);
         assertEquals("active", updated.getStatus());
         assertTrue(updated.getUsername().endsWith("XX"));
@@ -528,7 +531,8 @@ public class UserSelfITCase extends AbstractITCase {
         // 5. reject user
         form.getProperty("approveCreate").get().setValue(Boolean.FALSE.toString());
         form.getProperty("rejectReason").get().setValue("I don't like him.");
-        userTO = userService3.submitForm(form);
+        userTO = userService3.submitForm(form).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
+        }).getEntity();
         assertNotNull(userTO);
         assertEquals("rejected", userTO.getStatus());
 
@@ -613,7 +617,8 @@ public class UserSelfITCase extends AbstractITCase {
 
         // 5. approve user (and verify that propagation occurred)
         form.getProperty("approveCreate").get().setValue(Boolean.TRUE.toString());
-        userTO = userRequestService.submitForm(form);
+        userTO = userRequestService.submitForm(form).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
+        }).getEntity();
         assertNotNull(userTO);
         assertEquals(updatedUsername, userTO.getUsername());
         assertEquals("active", userTO.getStatus());
@@ -763,8 +768,7 @@ public class UserSelfITCase extends AbstractITCase {
         form.getProperty("approveCreate").get().setValue(Boolean.TRUE.toString());
 
         // 6. submit approve
-        userTO = userRequestService.submitForm(form);
-        assertNotNull(userTO);
+        userRequestService.submitForm(form);
         assertEquals(preForms,
                 userRequestService.listForms(new UserRequestQuery.Builder().build()).getTotalCount());
         assertTrue(userRequestService.listForms(