1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.flowable.task;
20
21 import org.apache.commons.lang3.tuple.Pair;
22 import org.apache.syncope.common.lib.request.PasswordPatch;
23 import org.apache.syncope.common.lib.request.UserUR;
24 import org.apache.syncope.core.flowable.impl.FlowableRuntimeUtils;
25 import org.apache.syncope.core.persistence.api.dao.UserDAO;
26 import org.apache.syncope.core.persistence.api.entity.user.User;
27 import org.apache.syncope.core.provisioning.api.PropagationByResource;
28 import org.apache.syncope.core.provisioning.api.data.UserDataBinder;
29 import org.apache.syncope.core.workflow.api.WorkflowException;
30 import org.flowable.engine.delegate.DelegateExecution;
31
32 public class PasswordReset extends FlowableServiceTask {
33
34 protected final UserDataBinder dataBinder;
35
36 protected final UserDAO userDAO;
37
38 public PasswordReset(final UserDataBinder dataBinder, final UserDAO userDAO) {
39 this.dataBinder = dataBinder;
40 this.userDAO = userDAO;
41 }
42
43 @Override
44 protected void doExecute(final DelegateExecution execution) {
45 User user = execution.getVariable(FlowableRuntimeUtils.USER, User.class);
46 String token = execution.getVariable(FlowableRuntimeUtils.TOKEN, String.class);
47 String password = execution.getVariable(FlowableRuntimeUtils.PASSWORD, String.class);
48
49 if (!user.checkToken(token)) {
50 throw new WorkflowException(new IllegalArgumentException("Wrong token: " + token + " for " + user));
51 }
52
53 user.removeToken();
54
55 UserUR req = new UserUR.Builder(user.getKey()).
56 password(new PasswordPatch.Builder().
57 onSyncope(true).
58 resources(userDAO.findAllResourceKeys(user.getKey())).
59 value(password).build()).
60 build();
61
62 Pair<PropagationByResource<String>, PropagationByResource<Pair<String, String>>> propInfo =
63 dataBinder.update(user, req);
64
65
66 execution.setVariable(FlowableRuntimeUtils.USER, user);
67 execution.setVariable(FlowableRuntimeUtils.USER_UR, req);
68 execution.setVariable(FlowableRuntimeUtils.PROP_BY_RESOURCE, propInfo.getLeft());
69 execution.setVariable(FlowableRuntimeUtils.PROP_BY_LINKEDACCOUNT, propInfo.getRight());
70 }
71 }