|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jabe\Engine\Impl; |
|
4
|
|
|
|
|
5
|
|
|
use Jabe\Engine\{ |
|
6
|
|
|
BadUserRequestException, |
|
7
|
|
|
IdentityService, |
|
8
|
|
|
ProcessEngineException |
|
9
|
|
|
}; |
|
10
|
|
|
use Jabe\Engine\Identity\{ |
|
11
|
|
|
PasswordPolicyResultInterface, |
|
12
|
|
|
GroupInterface, |
|
13
|
|
|
GroupQueryInterface, |
|
14
|
|
|
NativeUserQueryInterface, |
|
15
|
|
|
PasswordPolicyInterface, |
|
16
|
|
|
PasswordPolicyRuleInterface, |
|
17
|
|
|
Picture, |
|
18
|
|
|
TenantInterface, |
|
19
|
|
|
TenantQueryInterface, |
|
20
|
|
|
UserInterface, |
|
21
|
|
|
UserQueryInterface |
|
22
|
|
|
}; |
|
23
|
|
|
use Jabe\Engine\Impl\Cmd\{ |
|
24
|
|
|
CheckPassword, |
|
25
|
|
|
GetPasswordPolicyCmd, |
|
26
|
|
|
CreateGroupCmd, |
|
27
|
|
|
CreateGroupQueryCmd, |
|
28
|
|
|
CreateMembershipCmd, |
|
29
|
|
|
CreateNativeUserQueryCmd, |
|
30
|
|
|
CreateTenantCmd, |
|
31
|
|
|
CreateTenantGroupMembershipCmd, |
|
32
|
|
|
CreateTenantQueryCmd, |
|
33
|
|
|
CreateTenantUserMembershipCmd, |
|
34
|
|
|
CreateUserCmd, |
|
35
|
|
|
CreateUserQueryCmd, |
|
36
|
|
|
DeleteGroupCmd, |
|
37
|
|
|
DeleteMembershipCmd, |
|
38
|
|
|
DeleteTenantCmd, |
|
39
|
|
|
DeleteTenantGroupMembershipCmd, |
|
40
|
|
|
DeleteTenantUserMembershipCmd, |
|
41
|
|
|
DeleteUserCmd, |
|
42
|
|
|
DeleteUserInfoCmd, |
|
43
|
|
|
DeleteUserPictureCmd, |
|
44
|
|
|
GetUserAccountCmd, |
|
45
|
|
|
GetUserInfoCmd, |
|
46
|
|
|
GetUserInfoKeysCmd, |
|
47
|
|
|
GetUserPictureCmd, |
|
48
|
|
|
IsIdentityServiceReadOnlyCmd, |
|
49
|
|
|
SaveGroupCmd, |
|
50
|
|
|
SaveTenantCmd, |
|
51
|
|
|
SaveUserCmd, |
|
52
|
|
|
SetUserInfoCmd, |
|
53
|
|
|
SetUserPictureCmd, |
|
54
|
|
|
UnlockUserCmd |
|
55
|
|
|
}; |
|
56
|
|
|
use Jabe\Engine\Impl\Identity\{ |
|
57
|
|
|
AccountInterface, |
|
58
|
|
|
Authentication, |
|
59
|
|
|
PasswordPolicyResultImpl |
|
60
|
|
|
}; |
|
61
|
|
|
use Jabe\Engine\Impl\Persistence\Entity\IdentityInfoEntity; |
|
62
|
|
|
use Jabe\Engine\Impl\Util\{ |
|
63
|
|
|
EnsureUtil, |
|
64
|
|
|
ExceptionUtil |
|
65
|
|
|
}; |
|
66
|
|
|
|
|
67
|
|
|
class IdentityServiceImpl extends ServiceImpl implements IdentityServiceInterface |
|
68
|
|
|
{ |
|
69
|
|
|
/** thread local holding the current authentication */ |
|
70
|
|
|
private $currentAuthentication; |
|
71
|
|
|
|
|
72
|
|
|
public function isReadOnly(): bool |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->commandExecutor->execute(new IsIdentityServiceReadOnlyCmd()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function newGroup(string $groupId): GroupInterface |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->commandExecutor->execute(new CreateGroupCmd($groupId)); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function newUser(string $userId): UserInterface |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->commandExecutor->execute(new CreateUserCmd($userId)); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function newTenant(string $tenantId): TenantInterface |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->commandExecutor->execute(new CreateTenantCmd($tenantId)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function saveGroup(GroupInterface $group): void |
|
93
|
|
|
{ |
|
94
|
|
|
try { |
|
95
|
|
|
$this->commandExecutor->execute(new SaveGroupCmd($group)); |
|
96
|
|
|
} catch (\Exception $ex) { |
|
97
|
|
|
if (ExceptionUtil::checkConstraintViolationException($ex)) { |
|
98
|
|
|
throw new BadUserRequestException("The group already exists", $ex); |
|
99
|
|
|
} |
|
100
|
|
|
throw $ex; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function saveUser(UserInterface $user, bool $skipPasswordPolicy = false): void |
|
105
|
|
|
{ |
|
106
|
|
|
try { |
|
107
|
|
|
$this->commandExecutor->execute(new SaveUserCmd($user, $skipPasswordPolicy)); |
|
108
|
|
|
} catch (\Exception $ex) { |
|
109
|
|
|
if (ExceptionUtil::checkConstraintViolationException($ex)) { |
|
110
|
|
|
throw new BadUserRequestException("The user already exists", $ex); |
|
111
|
|
|
} |
|
112
|
|
|
throw $ex; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function saveTenant(TenantInterface $tenant): void |
|
117
|
|
|
{ |
|
118
|
|
|
try { |
|
119
|
|
|
$this->commandExecutor->execute(new SaveTenantCmd($tenant)); |
|
120
|
|
|
} catch (\Exception $ex) { |
|
121
|
|
|
if (ExceptionUtil::checkConstraintViolationException($ex)) { |
|
122
|
|
|
throw new BadUserRequestException("The tenant already exists", $ex); |
|
123
|
|
|
} |
|
124
|
|
|
throw $ex; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function createUserQuery(): UserQueryInterface |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->commandExecutor->execute(new CreateUserQueryCmd()); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function createNativeUserQuery(): NativeUserQueryInterface |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->commandExecutor->execute(new CreateNativeUserQueryCmd()); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function createGroupQuery(): GroupQueryInterface |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->commandExecutor->execute(new CreateGroupQueryCmd()); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function createTenantQuery(): TenantQueryInterface |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->commandExecutor->execute(new CreateTenantQueryCmd()); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function createMembership(string $userId, string $groupId): void |
|
149
|
|
|
{ |
|
150
|
|
|
$this->commandExecutor->execute(new CreateMembershipCmd($userId, $groupId)); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function deleteGroup(string $groupId): void |
|
154
|
|
|
{ |
|
155
|
|
|
$this->commandExecutor->execute(new DeleteGroupCmd($groupId)); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function deleteMembership(string $userId, string $groupId): void |
|
159
|
|
|
{ |
|
160
|
|
|
$this->commandExecutor->execute(new DeleteMembershipCmd($userId, $groupId)); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function checkPassword(string $userId, string $password): bool |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->commandExecutor->execute(new CheckPassword($userId, $password)); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
public function checkPasswordAgainstPolicy( |
|
169
|
|
|
?PasswordPolicyResultInterface $policy, |
|
170
|
|
|
string $candidatePassword, |
|
171
|
|
|
?UserInterface $user |
|
172
|
|
|
): PasswordPolicyResultInterface { |
|
173
|
|
|
$policy = $policy ?? $this->getPasswordPolicy(); |
|
174
|
|
|
EnsureUtil::ensureNotNull("policy", "policy", $policy); |
|
175
|
|
|
EnsureUtil::ensureNotNull("password", "candidatePassword", $candidatePassword); |
|
176
|
|
|
|
|
177
|
|
|
$violatedRules = []; |
|
178
|
|
|
$fulfilledRules = []; |
|
179
|
|
|
|
|
180
|
|
|
foreach ($policy->getRules() as $rule) { |
|
|
|
|
|
|
181
|
|
|
if ($rule->execute($candidatePassword, $user)) { |
|
182
|
|
|
$fulfilledRules[] = $rule; |
|
183
|
|
|
} else { |
|
184
|
|
|
$violatedRules[] = $rule; |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
return new PasswordPolicyResultImpl($violatedRules, $fulfilledRules); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public function getPasswordPolicy(): PasswordPolicyInterface |
|
191
|
|
|
{ |
|
192
|
|
|
return $this->commandExecutor->execute(new GetPasswordPolicyCmd()); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public function unlockUser(string $userId): void |
|
196
|
|
|
{ |
|
197
|
|
|
$this->commandExecutor->execute(new UnlockUserCmd($userId)); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
public function deleteUser(string $userId): void |
|
201
|
|
|
{ |
|
202
|
|
|
$this->commandExecutor->execute(new DeleteUserCmd($userId)); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
public function deleteTenant(string $tenantId): void |
|
206
|
|
|
{ |
|
207
|
|
|
$this->commandExecutor->execute(new DeleteTenantCmd($tenantId)); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
public function setUserPicture(string $userId, Picture $picture): void |
|
211
|
|
|
{ |
|
212
|
|
|
$this->commandExecutor->execute(new SetUserPictureCmd($userId, $picture)); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
public function getUserPicture(string $userId): Picture |
|
216
|
|
|
{ |
|
217
|
|
|
return $this->commandExecutor->execute(new GetUserPictureCmd($userId)); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
public function deleteUserPicture(string $userId): void |
|
221
|
|
|
{ |
|
222
|
|
|
$this->commandExecutor->execute(new DeleteUserPictureCmd($userId)); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
public function setAuthenticatedUserId(string $authenticatedUserId): void |
|
226
|
|
|
{ |
|
227
|
|
|
$this->setAuthentication(new Authentication($authenticatedUserId, null)); |
|
|
|
|
|
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
public function setAuthentication(string $userId, array $groups, ?array $tenantIds = null): void |
|
231
|
|
|
{ |
|
232
|
|
|
$this->currentAuthentication = new Authentication($userId, $groups, $tenantIds); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
public function clearAuthentication(): void |
|
236
|
|
|
{ |
|
237
|
|
|
$this->currentAuthentication = null; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
public function getCurrentAuthentication(): ?Authentication |
|
241
|
|
|
{ |
|
242
|
|
|
return $this->currentAuthentication; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
public function getUserInfo(string $userId, string $key): string |
|
246
|
|
|
{ |
|
247
|
|
|
return $this->commandExecutor->execute(new GetUserInfoCmd($userId, $key)); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
public function getUserInfoKeys(string $userId): array |
|
251
|
|
|
{ |
|
252
|
|
|
return $this->commandExecutor->execute(new GetUserInfoKeysCmd($userId, IdentityInfoEntity::TYPE_USERINFO)); |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
public function getUserAccountNames(string $userId): array |
|
256
|
|
|
{ |
|
257
|
|
|
return $this->commandExecutor->execute(new GetUserInfoKeysCmd($userId, IdentityInfoEntity::TYPE_USERACCOUNT)); |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
public function setUserInfo(string $userId, string $key, string $value): void |
|
261
|
|
|
{ |
|
262
|
|
|
$this->commandExecutor->execute(new SetUserInfoCmd($userId, $key, $value)); |
|
|
|
|
|
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
public function deleteUserInfo(string $userId, string $key): void |
|
266
|
|
|
{ |
|
267
|
|
|
$this->commandExecutor->execute(new DeleteUserInfoCmd($userId, $key)); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
public function deleteUserAccount(string $userId, string $accountName): void |
|
271
|
|
|
{ |
|
272
|
|
|
$this->commandExecutor->execute(new DeleteUserInfoCmd($userId, $accountName)); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
public function getUserAccount(string $userId, string $userPassword, string $accountName): ?AccountInterface |
|
276
|
|
|
{ |
|
277
|
|
|
return $this->commandExecutor->execute(new GetUserAccountCmd($userId, $userPassword, $accountName)); |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
public function setUserAccount(string $userId, string $userPassword, string $accountName, string $accountUsername, string $accountPassword, array $accountDetails): void |
|
281
|
|
|
{ |
|
282
|
|
|
$this->commandExecutor->execute(new SetUserInfoCmd($userId, $userPassword, $accountName, $accountUsername, $accountPassword, $accountDetails)); |
|
|
|
|
|
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
public function createTenantUserMembership(string $tenantId, string $userId): void |
|
286
|
|
|
{ |
|
287
|
|
|
$this->commandExecutor->execute(new CreateTenantUserMembershipCmd($tenantId, $userId)); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
public function createTenantGroupMembership(string $tenantId, string $groupId): void |
|
291
|
|
|
{ |
|
292
|
|
|
$this->commandExecutor->execute(new CreateTenantGroupMembershipCmd($tenantId, $groupId)); |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
public function deleteTenantUserMembership(string $tenantId, string $userId): void |
|
296
|
|
|
{ |
|
297
|
|
|
$this->commandExecutor->execute(new DeleteTenantUserMembershipCmd($tenantId, $userId)); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
public function deleteTenantGroupMembership(string $tenantId, string $groupId): void |
|
301
|
|
|
{ |
|
302
|
|
|
$this->commandExecutor->execute(new DeleteTenantGroupMembershipCmd($tenantId, $groupId)); |
|
303
|
|
|
} |
|
304
|
|
|
} |
|
305
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.