1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.efaps.bpm.identity;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.UUID;
27
28 import org.efaps.admin.EFapsSystemConfiguration;
29 import org.efaps.admin.KernelSettings;
30 import org.efaps.admin.user.Person;
31 import org.efaps.admin.user.Role;
32 import org.efaps.util.EFapsException;
33 import org.kie.api.task.UserGroupCallback;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37
38
39
40
41
42
43
44 public class UserGroupCallbackImpl
45 implements UserGroupCallback
46 {
47
48
49
50
51 private static final Logger LOG = LoggerFactory.getLogger(UserGroupCallbackImpl.class);
52
53
54
55
56
57 public UserGroupCallbackImpl()
58 {
59 try {
60 if (!EFapsSystemConfiguration.get().getAttributeValueAsBoolean(KernelSettings.REQUIRE_PERSON_UUID)) {
61 UserGroupCallbackImpl.LOG.warn("BPM is activated but the UUID for Persons is not required. "
62 + "That might leed to serious problems in the future!!!!!!");
63 }
64 } catch (final EFapsException e) {
65 UserGroupCallbackImpl.LOG.error("Could not read SystemConfiguration.", e);
66 }
67 }
68
69
70
71
72
73
74
75
76
77
78
79
80 @Override
81 public boolean existsUser(final String _userId)
82 {
83 UserGroupCallbackImpl.LOG.debug("checking for existence of User: '{}'", _userId);
84 boolean ret = false;
85 if ("Administrator".equals(_userId)) {
86 ret = true;
87 } else {
88 try {
89 final Person pers = org.efaps.admin.user.Person.get(UUID.fromString(_userId));
90 ret = pers != null;
91 } catch (final EFapsException e) {
92 UserGroupCallbackImpl.LOG.error("error while checkin for existence of User: '{}'", _userId);
93 }
94 }
95 UserGroupCallbackImpl.LOG.debug("result for existence check for User: '{}' is: {}", _userId, ret);
96 return ret;
97 }
98
99
100
101
102
103
104
105 @Override
106 public boolean existsGroup(final String _groupId)
107 {
108 UserGroupCallbackImpl.LOG.debug("checking for existence of Group: {}", _groupId);
109 boolean ret = false;
110 if ("Administrators".equals(_groupId)) {
111 ret = true;
112 } else {
113 try {
114 final Role role = org.efaps.admin.user.Role.get(UUID.fromString(_groupId));
115 ret = role != null;
116 } catch (final EFapsException e) {
117 UserGroupCallbackImpl.LOG.error("error while checkin for existence of Group: '{}'", _groupId);
118 }
119 }
120 UserGroupCallbackImpl.LOG.debug("result for existence check for Group: '{}' is: {}", _groupId, ret);
121 return ret;
122 }
123
124
125
126
127
128
129
130
131
132 @Override
133 public List<String> getGroupsForUser(final String _userId,
134 final List<String> _groupIds,
135 final List<String> _allExistingGroupIds)
136 {
137 UserGroupCallbackImpl.LOG.debug(
138 "getting Groups for User: '{}'. Assigned Groups: {}. Currently known Groups: {}.", _userId,
139 _groupIds, _allExistingGroupIds);
140 final List<String> ret = new ArrayList<String>();
141 try {
142 final Person pers;
143 if ("Administrator".equals(_userId)) {
144 pers = org.efaps.admin.user.Person.get(_userId);
145 } else {
146 pers = org.efaps.admin.user.Person.get(UUID.fromString(_userId));
147 }
148 if (pers != null) {
149 for (final Long roleId : pers.getRoles()) {
150 final Role role = org.efaps.admin.user.Role.get(roleId);
151 ret.add(role.getUUID().toString());
152 }
153 }
154 } catch (final EFapsException e) {
155 UserGroupCallbackImpl.LOG.error("error while checkin for existence of User: '{}'", _userId);
156 }
157 UserGroupCallbackImpl.LOG.debug("found Groups for User: '{}': {}", _userId, ret);
158 return ret;
159 }
160
161 }