View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.logic;
20  
21  import java.lang.reflect.Method;
22  import java.util.List;
23  import org.apache.commons.lang3.tuple.Pair;
24  import org.apache.syncope.common.lib.request.UserUR;
25  import org.apache.syncope.common.lib.to.EntityTO;
26  import org.apache.syncope.common.lib.to.UserTO;
27  import org.apache.syncope.common.lib.to.WorkflowTask;
28  import org.apache.syncope.common.lib.to.WorkflowTaskExecInput;
29  import org.apache.syncope.common.lib.types.FlowableEntitlement;
30  import org.apache.syncope.common.lib.types.IdRepoEntitlement;
31  import org.apache.syncope.core.flowable.api.WorkflowTaskManager;
32  import org.apache.syncope.core.persistence.api.dao.UserDAO;
33  import org.apache.syncope.core.persistence.api.entity.user.User;
34  import org.apache.syncope.core.provisioning.api.UserWorkflowResult;
35  import org.apache.syncope.core.provisioning.api.data.UserDataBinder;
36  import org.apache.syncope.core.provisioning.api.propagation.PropagationManager;
37  import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor;
38  import org.apache.syncope.core.provisioning.api.propagation.PropagationTaskInfo;
39  import org.apache.syncope.core.spring.security.AuthContextUtils;
40  import org.springframework.security.access.prepost.PreAuthorize;
41  
42  public class UserWorkflowTaskLogic extends AbstractTransactionalLogic<EntityTO> {
43  
44      protected final WorkflowTaskManager wfTaskManager;
45  
46      protected final PropagationManager propagationManager;
47  
48      protected final PropagationTaskExecutor taskExecutor;
49  
50      protected final UserDataBinder binder;
51  
52      protected final UserDAO userDAO;
53  
54      public UserWorkflowTaskLogic(
55              final WorkflowTaskManager wfTaskManager,
56              final PropagationManager propagationManager,
57              final PropagationTaskExecutor taskExecutor,
58              final UserDataBinder binder,
59              final UserDAO userDAO) {
60  
61          this.wfTaskManager = wfTaskManager;
62          this.propagationManager = propagationManager;
63          this.taskExecutor = taskExecutor;
64          this.binder = binder;
65          this.userDAO = userDAO;
66      }
67  
68      @PreAuthorize("hasRole('" + FlowableEntitlement.WORKFLOW_TASK_LIST + "') "
69              + "and hasRole('" + IdRepoEntitlement.USER_READ + "')")
70      public List<WorkflowTask> getAvailableTasks(final String key) {
71          User user = userDAO.authFind(key);
72          return wfTaskManager.getAvailableTasks(user.getKey());
73      }
74  
75      @PreAuthorize("hasRole('" + IdRepoEntitlement.USER_UPDATE + "')")
76      public UserTO executeNextTask(final WorkflowTaskExecInput workflowTaskExecInput) {
77          UserWorkflowResult<String> updated = wfTaskManager.executeNextTask(workflowTaskExecInput);
78  
79          UserUR userUR = new UserUR.Builder(updated.getResult()).build();
80  
81          List<PropagationTaskInfo> taskInfos = propagationManager.getUserUpdateTasks(
82                  new UserWorkflowResult<>(
83                          Pair.<UserUR, Boolean>of(userUR, null),
84                          updated.getPropByRes(),
85                          updated.getPropByLinkedAccount(),
86                          updated.getPerformedTasks()));
87          taskExecutor.execute(taskInfos, false, AuthContextUtils.getUsername());
88  
89          return binder.getUserTO(updated.getResult());
90      }
91  
92      @Override
93      protected EntityTO resolveReference(final Method method, final Object... args)
94              throws UnresolvedReferenceException {
95  
96          throw new UnresolvedReferenceException();
97      }
98  }