Complex classes like UserService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UserService, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
62 | class UserService implements UserServiceInterface |
||
63 | { |
||
64 | /** @var \eZ\Publish\API\Repository\Repository */ |
||
65 | protected $repository; |
||
66 | |||
67 | /** @var \eZ\Publish\SPI\Persistence\User\Handler */ |
||
68 | protected $userHandler; |
||
69 | |||
70 | /** @var \eZ\Publish\SPI\Persistence\Content\Location\Handler */ |
||
71 | private $locationHandler; |
||
72 | |||
73 | /** @var array */ |
||
74 | protected $settings; |
||
75 | |||
76 | /** @var \Psr\Log\LoggerInterface|null */ |
||
77 | protected $logger; |
||
78 | |||
79 | /** @var \eZ\Publish\API\Repository\PermissionResolver */ |
||
80 | private $permissionResolver; |
||
81 | |||
82 | public function setLogger(LoggerInterface $logger = null) |
||
86 | |||
87 | /** |
||
88 | * Setups service with reference to repository object that created it & corresponding handler. |
||
89 | * |
||
90 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
91 | * @param \eZ\Publish\SPI\Persistence\User\Handler $userHandler |
||
92 | * @param \eZ\Publish\SPI\Persistence\Content\Location\Handler $locationHandler |
||
93 | * @param array $settings |
||
94 | */ |
||
95 | public function __construct( |
||
114 | |||
115 | /** |
||
116 | * Creates a new user group using the data provided in the ContentCreateStruct parameter. |
||
117 | * |
||
118 | * In 4.x in the content type parameter in the profile is ignored |
||
119 | * - the content type is determined via configuration and can be set to null. |
||
120 | * The returned version is published. |
||
121 | * |
||
122 | * @param \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct $userGroupCreateStruct a structure for setting all necessary data to create this user group |
||
123 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $parentGroup |
||
124 | * |
||
125 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup |
||
126 | * |
||
127 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a user group |
||
128 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the input structure has invalid data |
||
129 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userGroupCreateStruct is not valid |
||
130 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or set to an empty value |
||
131 | */ |
||
132 | public function createUserGroup(APIUserGroupCreateStruct $userGroupCreateStruct, APIUserGroup $parentGroup) |
||
165 | |||
166 | /** |
||
167 | * Loads a user group for the given id. |
||
168 | * |
||
169 | * @param mixed $id |
||
170 | * @param string[] $prioritizedLanguages Used as prioritized language code on translated properties of returned object. |
||
171 | * |
||
172 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup |
||
173 | * |
||
174 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a user group |
||
175 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the user group with the given id was not found |
||
176 | */ |
||
177 | public function loadUserGroup($id, array $prioritizedLanguages = []) |
||
183 | |||
184 | /** |
||
185 | * Loads the sub groups of a user group. |
||
186 | * |
||
187 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
188 | * @param int $offset the start offset for paging |
||
189 | * @param int $limit the number of user groups returned |
||
190 | * @param string[] $prioritizedLanguages Used as prioritized language code on translated properties of returned object. |
||
191 | * |
||
192 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup[] |
||
193 | * |
||
194 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read the user group |
||
195 | */ |
||
196 | public function loadSubUserGroups(APIUserGroup $userGroup, $offset = 0, $limit = 25, array $prioritizedLanguages = []) |
||
230 | |||
231 | /** |
||
232 | * Returns (searches) subgroups of a user group described by its main location. |
||
233 | * |
||
234 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
235 | * @param int $offset |
||
236 | * @param int $limit |
||
237 | * |
||
238 | * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult |
||
239 | */ |
||
240 | protected function searchSubGroups(Location $location, $offset = 0, $limit = 25) |
||
256 | |||
257 | /** |
||
258 | * Removes a user group. |
||
259 | * |
||
260 | * the users which are not assigned to other groups will be deleted. |
||
261 | * |
||
262 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
263 | * |
||
264 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a user group |
||
265 | */ |
||
266 | public function deleteUserGroup(APIUserGroup $userGroup) |
||
282 | |||
283 | /** |
||
284 | * Moves the user group to another parent. |
||
285 | * |
||
286 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
287 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $newParent |
||
288 | * |
||
289 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group |
||
290 | */ |
||
291 | public function moveUserGroup(APIUserGroup $userGroup, APIUserGroup $newParent) |
||
322 | |||
323 | /** |
||
324 | * Updates the group profile with fields and meta data. |
||
325 | * |
||
326 | * 4.x: If the versionUpdateStruct is set in $userGroupUpdateStruct, this method internally creates a content draft, updates ts with the provided data |
||
327 | * and publishes the draft. If a draft is explicitly required, the user group can be updated via the content service methods. |
||
328 | * |
||
329 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
330 | * @param \eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct $userGroupUpdateStruct |
||
331 | * |
||
332 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup |
||
333 | * |
||
334 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update the user group |
||
335 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userGroupUpdateStruct is not valid |
||
336 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set empty |
||
337 | */ |
||
338 | public function updateUserGroup(APIUserGroup $userGroup, UserGroupUpdateStruct $userGroupUpdateStruct) |
||
379 | |||
380 | /** |
||
381 | * Create a new user. The created user is published by this method. |
||
382 | * |
||
383 | * @param \eZ\Publish\API\Repository\Values\User\UserCreateStruct $userCreateStruct the data used for creating the user |
||
384 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup[] $parentGroups the groups which are assigned to the user after creation |
||
385 | * |
||
386 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
387 | * |
||
388 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group |
||
389 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userCreateStruct is not valid |
||
390 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or set to an empty value |
||
391 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a user with provided login already exists |
||
392 | */ |
||
393 | public function createUser(APIUserCreateStruct $userCreateStruct, array $parentGroups) |
||
525 | |||
526 | /** |
||
527 | * Loads a user. |
||
528 | * |
||
529 | * @param mixed $userId |
||
530 | * @param string[] $prioritizedLanguages Used as prioritized language code on translated properties of returned object. |
||
531 | * |
||
532 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
533 | * |
||
534 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user with the given id was not found |
||
535 | */ |
||
536 | public function loadUser($userId, array $prioritizedLanguages = []) |
||
567 | |||
568 | /** |
||
569 | * Loads anonymous user. |
||
570 | * |
||
571 | * @deprecated since 5.3, use loadUser( $anonymousUserId ) instead |
||
572 | * |
||
573 | * @uses ::loadUser() |
||
574 | * |
||
575 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
576 | */ |
||
577 | public function loadAnonymousUser() |
||
581 | |||
582 | /** |
||
583 | * Loads a user for the given login and password. |
||
584 | * |
||
585 | * If the password hash type differs from that configured for the service, it will be updated to the configured one. |
||
586 | * |
||
587 | * {@inheritdoc} |
||
588 | * |
||
589 | * @param string $login |
||
590 | * @param string $password the plain password |
||
591 | * @param string[] $prioritizedLanguages Used as prioritized language code on translated properties of returned object. |
||
592 | * |
||
593 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
594 | * |
||
595 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if credentials are invalid |
||
596 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user with the given credentials was not found |
||
597 | */ |
||
598 | public function loadUserByCredentials($login, $password, array $prioritizedLanguages = []) |
||
618 | |||
619 | /** |
||
620 | * Update password hash to the type configured for the service, if they differ. |
||
621 | * |
||
622 | * @param string $login User login |
||
623 | * @param string $password User password |
||
624 | * @param \eZ\Publish\SPI\Persistence\User $spiUser |
||
625 | * |
||
626 | * @throws \eZ\Publish\Core\Base\Exceptions\BadStateException if the password is not correctly saved, in which case the update is reverted |
||
627 | */ |
||
628 | private function updatePasswordHash($login, $password, SPIUser $spiUser) |
||
656 | |||
657 | /** |
||
658 | * Loads a user for the given login. |
||
659 | * |
||
660 | * {@inheritdoc} |
||
661 | * |
||
662 | * @param string $login |
||
663 | * @param string[] $prioritizedLanguages Used as prioritized language code on translated properties of returned object. |
||
664 | * |
||
665 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
666 | * |
||
667 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user with the given credentials was not found |
||
668 | */ |
||
669 | public function loadUserByLogin($login, array $prioritizedLanguages = []) |
||
679 | |||
680 | /** |
||
681 | * Loads a user for the given email. |
||
682 | * |
||
683 | * {@inheritdoc} |
||
684 | * |
||
685 | * @param string $email |
||
686 | * @param string[] $prioritizedLanguages Used as prioritized language code on translated properties of returned object. |
||
687 | * |
||
688 | * @return \eZ\Publish\API\Repository\Values\User\User[] |
||
689 | */ |
||
690 | public function loadUsersByEmail($email, array $prioritizedLanguages = []) |
||
703 | |||
704 | /** |
||
705 | * Loads a user for the given token. |
||
706 | * |
||
707 | * {@inheritdoc} |
||
708 | * |
||
709 | * @param string $hash |
||
710 | * @param string[] $prioritizedLanguages Used as prioritized language code on translated properties of returned object. |
||
711 | * |
||
712 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
713 | * |
||
714 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
715 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue |
||
716 | */ |
||
717 | public function loadUserByToken($hash, array $prioritizedLanguages = []) |
||
727 | |||
728 | /** |
||
729 | * This method deletes a user. |
||
730 | * |
||
731 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
732 | * |
||
733 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete the user |
||
734 | */ |
||
735 | public function deleteUser(APIUser $user) |
||
751 | |||
752 | /** |
||
753 | * Updates a user. |
||
754 | * |
||
755 | * 4.x: If the versionUpdateStruct is set in the user update structure, this method internally creates a content draft, updates ts with the provided data |
||
756 | * and publishes the draft. If a draft is explicitly required, the user group can be updated via the content service methods. |
||
757 | * |
||
758 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
759 | * @param \eZ\Publish\API\Repository\Values\User\UserUpdateStruct $userUpdateStruct |
||
760 | * |
||
761 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userUpdateStruct is not valid |
||
762 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set empty |
||
763 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update the user |
||
764 | * |
||
765 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
766 | */ |
||
767 | public function updateUser(APIUser $user, UserUpdateStruct $userUpdateStruct) |
||
892 | |||
893 | /** |
||
894 | * Update the user token information specified by the user token struct. |
||
895 | * |
||
896 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
897 | * @param \eZ\Publish\API\Repository\Values\User\UserTokenUpdateStruct $userTokenUpdateStruct |
||
898 | * |
||
899 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue |
||
900 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
901 | * @throws \RuntimeException |
||
902 | * @throws \Exception |
||
903 | * |
||
904 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
905 | */ |
||
906 | public function updateUserToken(APIUser $user, UserTokenUpdateStruct $userTokenUpdateStruct) |
||
937 | |||
938 | /** |
||
939 | * Expires user token with user hash. |
||
940 | * |
||
941 | * @param string $hash |
||
942 | */ |
||
943 | public function expireUserToken($hash) |
||
954 | |||
955 | /** |
||
956 | * Assigns a new user group to the user. |
||
957 | * |
||
958 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
959 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
960 | * |
||
961 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign the user group to the user |
||
962 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is already in the given user group |
||
963 | */ |
||
964 | public function assignUserToUserGroup(APIUser $user, APIUserGroup $userGroup) |
||
1001 | |||
1002 | /** |
||
1003 | * Removes a user group from the user. |
||
1004 | * |
||
1005 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
1006 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
1007 | * |
||
1008 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove the user group from the user |
||
1009 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is not in the given user group |
||
1010 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If $userGroup is the last assigned user group |
||
1011 | */ |
||
1012 | public function unAssignUserFromUserGroup(APIUser $user, APIUserGroup $userGroup) |
||
1049 | |||
1050 | /** |
||
1051 | * Loads the user groups the user belongs to. |
||
1052 | * |
||
1053 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed read the user or user group |
||
1054 | * |
||
1055 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
1056 | * @param int $offset the start offset for paging |
||
1057 | * @param int $limit the number of user groups returned |
||
1058 | * @param string[] $prioritizedLanguages Used as prioritized language code on translated properties of returned object. |
||
1059 | * |
||
1060 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup[] |
||
1061 | */ |
||
1062 | public function loadUserGroupsOfUser(APIUser $user, $offset = 0, $limit = 25, array $prioritizedLanguages = []) |
||
1108 | |||
1109 | /** |
||
1110 | * Loads the users of a user group. |
||
1111 | * |
||
1112 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read the users or user group |
||
1113 | * |
||
1114 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
1115 | * @param int $offset the start offset for paging |
||
1116 | * @param int $limit the number of users returned |
||
1117 | * @param string[] $prioritizedLanguages Used as prioritized language code on translated properties of returned object. |
||
1118 | * |
||
1119 | * @return \eZ\Publish\API\Repository\Values\User\User[] |
||
1120 | */ |
||
1121 | public function loadUsersOfUserGroup( |
||
1166 | |||
1167 | /** |
||
1168 | * {@inheritdoc} |
||
1169 | */ |
||
1170 | public function isUser(APIContent $content): bool |
||
1187 | |||
1188 | /** |
||
1189 | * {@inheritdoc} |
||
1190 | */ |
||
1191 | public function isUserGroup(APIContent $content): bool |
||
1195 | |||
1196 | /** |
||
1197 | * Instantiate a user create class. |
||
1198 | * |
||
1199 | * @param string $login the login of the new user |
||
1200 | * @param string $email the email of the new user |
||
1201 | * @param string $password the plain password of the new user |
||
1202 | * @param string $mainLanguageCode the main language for the underlying content object |
||
1203 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType 5.x the content type for the underlying content object. In 4.x it is ignored and taken from the configuration |
||
1204 | * |
||
1205 | * @return \eZ\Publish\API\Repository\Values\User\UserCreateStruct |
||
1206 | */ |
||
1207 | public function newUserCreateStruct($login, $email, $password, $mainLanguageCode, $contentType = null) |
||
1227 | |||
1228 | /** |
||
1229 | * Instantiate a user group create class. |
||
1230 | * |
||
1231 | * @param string $mainLanguageCode The main language for the underlying content object |
||
1232 | * @param null|\eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType 5.x the content type for the underlying content object. In 4.x it is ignored and taken from the configuration |
||
1233 | * |
||
1234 | * @return \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct |
||
1235 | */ |
||
1236 | public function newUserGroupCreateStruct($mainLanguageCode, $contentType = null) |
||
1252 | |||
1253 | /** |
||
1254 | * Instantiate a new user update struct. |
||
1255 | * |
||
1256 | * @return \eZ\Publish\API\Repository\Values\User\UserUpdateStruct |
||
1257 | */ |
||
1258 | public function newUserUpdateStruct() |
||
1262 | |||
1263 | /** |
||
1264 | * Instantiate a new user group update struct. |
||
1265 | * |
||
1266 | * @return \eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct |
||
1267 | */ |
||
1268 | public function newUserGroupUpdateStruct() |
||
1272 | |||
1273 | /** |
||
1274 | * {@inheritdoc} |
||
1275 | */ |
||
1276 | public function validatePassword(string $password, PasswordValidationContext $context = null): array |
||
1321 | |||
1322 | /** |
||
1323 | * Builds the domain UserGroup object from provided Content object. |
||
1324 | * |
||
1325 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
1326 | * |
||
1327 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup |
||
1328 | */ |
||
1329 | protected function buildDomainUserGroupObject(APIContent $content) |
||
1347 | |||
1348 | /** |
||
1349 | * Builds the domain user object from provided persistence user object. |
||
1350 | * |
||
1351 | * @param \eZ\Publish\SPI\Persistence\User $spiUser |
||
1352 | * @param \eZ\Publish\API\Repository\Values\Content\Content|null $content |
||
1353 | * @param string[] $prioritizedLanguages Used as prioritized language code on translated properties of returned object. |
||
1354 | * |
||
1355 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
1356 | */ |
||
1357 | protected function buildDomainUserObject( |
||
1382 | |||
1383 | public function getPasswordInfo(APIUser $user): PasswordInfo |
||
1414 | |||
1415 | private function getUserFieldDefinition(ContentType $contentType): ?FieldDefinition |
||
1425 | |||
1426 | /** |
||
1427 | * Verifies if the provided login and password are valid for eZ\Publish\SPI\Persistence\User. |
||
1428 | * |
||
1429 | * @param string $login User login |
||
1430 | * @param string $password User password |
||
1431 | * @param \eZ\Publish\SPI\Persistence\User $spiUser Loaded user handler |
||
1432 | * |
||
1433 | * @return bool return true if the login and password are sucessfully validated and false, if not. |
||
1434 | */ |
||
1435 | protected function comparePasswordHashForSPIUser(string $login, string $password, SPIUser $spiUser): bool |
||
1436 | { |
||
1437 | return $this->comparePasswordHashes($login, $password, $spiUser->passwordHash, $spiUser->hashAlgorithm); |
||
1438 | } |
||
1439 | |||
1440 | /** |
||
1441 | * Verifies if the provided login and password are valid for eZ\Publish\API\Repository\Values\User\User. |
||
1442 | * |
||
1443 | * @param string $login User login |
||
1444 | * @param string $password User password |
||
1445 | * @param \eZ\Publish\API\Repository\Values\User\User $apiUser Loaded user |
||
1446 | * |
||
1447 | * @return bool return true if the login and password are sucessfully validated and false, if not. |
||
1448 | */ |
||
1449 | protected function comparePasswordHashForAPIUser(string $login, string $password, APIUser $apiUser): bool |
||
1450 | { |
||
1451 | return $this->comparePasswordHashes($login, $password, $apiUser->passwordHash, $apiUser->hashAlgorithm); |
||
1452 | } |
||
1453 | |||
1454 | /** |
||
1455 | * Verifies if the provided login and password are valid. |
||
1456 | * |
||
1457 | * @deprecated since v7.5.5 in favour of verifyPasswordForSPIUser |
||
1458 | * |
||
1459 | * @param string $login User login |
||
1460 | * @param string $password User password |
||
1461 | * @param \eZ\Publish\SPI\Persistence\User $spiUser Loaded user handler |
||
1462 | * |
||
1463 | * @return bool return true if the login and password are sucessfully |
||
1464 | * validate and false, if not. |
||
1465 | */ |
||
1466 | protected function verifyPassword($login, $password, $spiUser) |
||
1470 | |||
1471 | /** |
||
1472 | * Verifies if the provided login and password are valid against given password hash and hash type. |
||
1473 | * |
||
1474 | * @param string $login User login |
||
1475 | * @param string $plainPassword User password |
||
1476 | * @param string $passwordHash User password hash |
||
1477 | * @param int $hashAlgorithm Hash type |
||
1478 | * |
||
1479 | * @return bool return true if the login and password are sucessfully validated and false, if not. |
||
1480 | */ |
||
1481 | private function comparePasswordHashes( |
||
1482 | string $login, |
||
1483 | string $plainPassword, |
||
1484 | string $passwordHash, |
||
1485 | int $hashAlgorithm |
||
1486 | ): bool { |
||
1487 | // In case of bcrypt let php's password functionality do it's magic |
||
1488 | if ($hashAlgorithm === APIUser::PASSWORD_HASH_BCRYPT || |
||
1489 | $hashAlgorithm === APIUser::PASSWORD_HASH_PHP_DEFAULT |
||
1490 | ) { |
||
1491 | return password_verify($plainPassword, $passwordHash); |
||
1492 | } |
||
1493 | |||
1494 | // Randomize login time to protect against timing attacks |
||
1495 | usleep(random_int(0, 30000)); |
||
1496 | |||
1497 | return $passwordHash === $this->createPasswordHash( |
||
1498 | $login, |
||
1499 | $plainPassword, |
||
1500 | $this->settings['siteName'], |
||
1501 | $hashAlgorithm |
||
1502 | ); |
||
1503 | } |
||
1504 | |||
1505 | /** |
||
1506 | * Returns password hash based on user data and site settings. |
||
1507 | * |
||
1508 | * @param string $login User login |
||
1509 | * @param string $password User password |
||
1510 | * @param string $site The name of the site |
||
1511 | * @param int $type Type of password to generate |
||
1512 | * |
||
1513 | * @return string Generated password hash |
||
1514 | * |
||
1515 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the type is not recognized |
||
1516 | */ |
||
1517 | protected function createPasswordHash($login, $password, $site, $type) |
||
1552 | |||
1553 | /** |
||
1554 | * Return true if any of the UserUpdateStruct properties refers to User Profile (Content) update. |
||
1555 | * |
||
1556 | * @param UserUpdateStruct $userUpdateStruct |
||
1557 | * |
||
1558 | * @return bool |
||
1559 | */ |
||
1560 | private function isUserProfileUpdateRequested(UserUpdateStruct $userUpdateStruct) |
||
1569 | |||
1570 | private function getDateTime(?int $timestamp): ?DateTimeInterface |
||
1582 | } |
||
1583 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.