Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Access 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 Access, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 45 | class Access extends LDAPUtility implements user\IUserTools { |
||
| 46 | /** |
||
| 47 | * @var \OCA\user_ldap\lib\Connection |
||
| 48 | */ |
||
| 49 | public $connection; |
||
| 50 | public $userManager; |
||
| 51 | //never ever check this var directly, always use getPagedSearchResultState |
||
| 52 | protected $pagedSearchedSuccessful; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string[] $cookies an array of returned Paged Result cookies |
||
| 56 | */ |
||
| 57 | protected $cookies = array(); |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string $lastCookie the last cookie returned from a Paged Results |
||
| 61 | * operation, defaults to an empty string |
||
| 62 | */ |
||
| 63 | protected $lastCookie = ''; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var AbstractMapping $userMapper |
||
| 67 | */ |
||
| 68 | protected $userMapper; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var AbstractMapping $userMapper |
||
| 72 | */ |
||
| 73 | protected $groupMapper; |
||
| 74 | |||
| 75 | 91 | public function __construct(Connection $connection, ILDAPWrapper $ldap, |
|
| 82 | |||
| 83 | /** |
||
| 84 | * sets the User Mapper |
||
| 85 | * @param AbstractMapping $mapper |
||
| 86 | */ |
||
| 87 | 1 | public function setUserMapper(AbstractMapping $mapper) { |
|
| 90 | |||
| 91 | /** |
||
| 92 | * returns the User Mapper |
||
| 93 | * @throws \Exception |
||
| 94 | * @return AbstractMapping |
||
| 95 | */ |
||
| 96 | 1 | public function getUserMapper() { |
|
| 102 | |||
| 103 | /** |
||
| 104 | * sets the Group Mapper |
||
| 105 | * @param AbstractMapping $mapper |
||
| 106 | */ |
||
| 107 | public function setGroupMapper(AbstractMapping $mapper) { |
||
| 110 | |||
| 111 | /** |
||
| 112 | * returns the Group Mapper |
||
| 113 | * @throws \Exception |
||
| 114 | * @return AbstractMapping |
||
| 115 | */ |
||
| 116 | public function getGroupMapper() { |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @return bool |
||
| 125 | */ |
||
| 126 | 4 | private function checkConnection() { |
|
| 129 | |||
| 130 | /** |
||
| 131 | * returns the Connection instance |
||
| 132 | * @return \OCA\user_ldap\lib\Connection |
||
| 133 | */ |
||
| 134 | 46 | public function getConnection() { |
|
| 137 | |||
| 138 | /** |
||
| 139 | * reads a given attribute for an LDAP record identified by a DN |
||
| 140 | * @param string $dn the record in question |
||
| 141 | * @param string $attr the attribute that shall be retrieved |
||
| 142 | * if empty, just check the record's existence |
||
| 143 | * @param string $filter |
||
| 144 | * @return array|false an array of values on success or an empty |
||
| 145 | * array if $attr is empty, false otherwise |
||
| 146 | */ |
||
| 147 | 4 | public function readAttribute($dn, $attr, $filter = 'objectClass=*') { |
|
| 210 | |||
| 211 | /** |
||
| 212 | * checks whether the given attributes value is probably a DN |
||
| 213 | * @param string $attr the attribute in question |
||
| 214 | * @return boolean if so true, otherwise false |
||
| 215 | */ |
||
| 216 | 4 | private function resemblesDN($attr) { |
|
| 226 | |||
| 227 | /** |
||
| 228 | * checks whether the given string is probably a DN |
||
| 229 | * @param string $string |
||
| 230 | * @return boolean |
||
| 231 | */ |
||
| 232 | 2 | public function stringResemblesDN($string) { |
|
| 238 | |||
| 239 | /** |
||
| 240 | * sanitizes a DN received from the LDAP server |
||
| 241 | * @param array $dn the DN in question |
||
| 242 | * @return array the sanitized DN |
||
| 243 | */ |
||
| 244 | 4 | private function sanitizeDN($dn) { |
|
| 281 | |||
| 282 | /** |
||
| 283 | * returns a DN-string that is cleaned from not domain parts, e.g. |
||
| 284 | * cn=foo,cn=bar,dc=foobar,dc=server,dc=org |
||
| 285 | * becomes dc=foobar,dc=server,dc=org |
||
| 286 | * @param string $dn |
||
| 287 | * @return string |
||
| 288 | */ |
||
| 289 | 2 | public function getDomainDNFromDN($dn) { |
|
| 308 | |||
| 309 | /** |
||
| 310 | * returns the LDAP DN for the given internal ownCloud name of the group |
||
| 311 | * @param string $name the ownCloud name in question |
||
| 312 | * @return string|false LDAP DN on success, otherwise false |
||
| 313 | */ |
||
| 314 | public function groupname2dn($name) { |
||
| 317 | |||
| 318 | /** |
||
| 319 | * returns the LDAP DN for the given internal ownCloud name of the user |
||
| 320 | * @param string $name the ownCloud name in question |
||
| 321 | * @return string|false with the LDAP DN on success, otherwise false |
||
| 322 | */ |
||
| 323 | public function username2dn($name) { |
||
| 334 | |||
| 335 | /** |
||
| 336 | public function ocname2dn($name, $isUser) { |
||
| 337 | * returns the internal ownCloud name for the given LDAP DN of the group, false on DN outside of search DN or failure |
||
| 338 | * @param string $fdn the dn of the group object |
||
| 339 | * @param string $ldapName optional, the display name of the object |
||
| 340 | * @return string|false with the name to use in ownCloud, false on DN outside of search DN |
||
| 341 | */ |
||
| 342 | View Code Duplication | public function dn2groupname($fdn, $ldapName = null) { |
|
| 352 | |||
| 353 | /** |
||
| 354 | * accepts an array of group DNs and tests whether they match the user |
||
| 355 | * filter by doing read operations against the group entries. Returns an |
||
| 356 | * array of DNs that match the filter. |
||
| 357 | * |
||
| 358 | * @param string[] $groupDNs |
||
| 359 | * @return string[] |
||
| 360 | */ |
||
| 361 | public function groupsMatchFilter($groupDNs) { |
||
| 390 | |||
| 391 | /** |
||
| 392 | * returns the internal ownCloud name for the given LDAP DN of the user, false on DN outside of search DN or failure |
||
| 393 | * @param string $dn the dn of the user object |
||
| 394 | * @param string $ldapName optional, the display name of the object |
||
| 395 | * @return string|false with with the name to use in ownCloud |
||
| 396 | */ |
||
| 397 | View Code Duplication | public function dn2username($fdn, $ldapName = null) { |
|
| 407 | |||
| 408 | /** |
||
| 409 | * returns an internal ownCloud name for the given LDAP DN, false on DN outside of search DN |
||
| 410 | * @param string $dn the dn of the user object |
||
| 411 | * @param string $ldapName optional, the display name of the object |
||
| 412 | * @param bool $isUser optional, whether it is a user object (otherwise group assumed) |
||
| 413 | * @return string|false with with the name to use in ownCloud |
||
| 414 | */ |
||
| 415 | 1 | public function dn2ocname($fdn, $ldapName = null, $isUser = true) { |
|
| 490 | |||
| 491 | /** |
||
| 492 | * gives back the user names as they are used ownClod internally |
||
| 493 | * @param array $ldapUsers as returned by fetchList() |
||
| 494 | * @return array an array with the user names to use in ownCloud |
||
| 495 | * |
||
| 496 | * gives back the user names as they are used ownClod internally |
||
| 497 | */ |
||
| 498 | public function ownCloudUserNames($ldapUsers) { |
||
| 501 | |||
| 502 | /** |
||
| 503 | * gives back the group names as they are used ownClod internally |
||
| 504 | * @param array $ldapGroups as returned by fetchList() |
||
| 505 | * @return array an array with the group names to use in ownCloud |
||
| 506 | * |
||
| 507 | * gives back the group names as they are used ownClod internally |
||
| 508 | */ |
||
| 509 | public function ownCloudGroupNames($ldapGroups) { |
||
| 512 | |||
| 513 | /** |
||
| 514 | * @param array $ldapObjects as returned by fetchList() |
||
| 515 | * @param bool $isUsers |
||
| 516 | * @return array |
||
| 517 | */ |
||
| 518 | private function ldap2ownCloudNames($ldapObjects, $isUsers) { |
||
| 552 | |||
| 553 | /** |
||
| 554 | * caches the user display name |
||
| 555 | * @param string $ocName the internal ownCloud username |
||
| 556 | * @param string|false $home the home directory path |
||
| 557 | */ |
||
| 558 | 1 | public function cacheUserHome($ocName, $home) { |
|
| 562 | |||
| 563 | /** |
||
| 564 | * caches a user as existing |
||
| 565 | * @param string $ocName the internal ownCloud username |
||
| 566 | */ |
||
| 567 | 1 | public function cacheUserExists($ocName) { |
|
| 570 | |||
| 571 | /** |
||
| 572 | * caches the user display name |
||
| 573 | * @param string $ocName the internal ownCloud username |
||
| 574 | * @param string $displayName the display name |
||
| 575 | */ |
||
| 576 | public function cacheUserDisplayName($ocName, $displayName) { |
||
| 580 | |||
| 581 | /** |
||
| 582 | * creates a unique name for internal ownCloud use for users. Don't call it directly. |
||
| 583 | * @param string $name the display name of the object |
||
| 584 | * @return string|false with with the name to use in ownCloud or false if unsuccessful |
||
| 585 | * |
||
| 586 | * Instead of using this method directly, call |
||
| 587 | * createAltInternalOwnCloudName($name, true) |
||
| 588 | */ |
||
| 589 | private function _createAltInternalOwnCloudNameForUsers($name) { |
||
| 602 | |||
| 603 | /** |
||
| 604 | * creates a unique name for internal ownCloud use for groups. Don't call it directly. |
||
| 605 | * @param string $name the display name of the object |
||
| 606 | * @return string|false with with the name to use in ownCloud or false if unsuccessful. |
||
| 607 | * |
||
| 608 | * Instead of using this method directly, call |
||
| 609 | * createAltInternalOwnCloudName($name, false) |
||
| 610 | * |
||
| 611 | * Group names are also used as display names, so we do a sequential |
||
| 612 | * numbering, e.g. Developers_42 when there are 41 other groups called |
||
| 613 | * "Developers" |
||
| 614 | */ |
||
| 615 | private function _createAltInternalOwnCloudNameForGroups($name) { |
||
| 640 | |||
| 641 | /** |
||
| 642 | * creates a unique name for internal ownCloud use. |
||
| 643 | * @param string $name the display name of the object |
||
| 644 | * @param boolean $isUser whether name should be created for a user (true) or a group (false) |
||
| 645 | * @return string|false with with the name to use in ownCloud or false if unsuccessful |
||
| 646 | */ |
||
| 647 | private function createAltInternalOwnCloudName($name, $isUser) { |
||
| 659 | |||
| 660 | /** |
||
| 661 | * fetches a list of users according to a provided loginName and utilizing |
||
| 662 | * the login filter. |
||
| 663 | * |
||
| 664 | * @param string $loginName |
||
| 665 | * @param array $attributes optional, list of attributes to read |
||
| 666 | * @return array |
||
| 667 | */ |
||
| 668 | View Code Duplication | public function fetchUsersByLoginName($loginName, $attributes = array('dn')) { |
|
| 674 | |||
| 675 | /** |
||
| 676 | * counts the number of users according to a provided loginName and |
||
| 677 | * utilizing the login filter. |
||
| 678 | * |
||
| 679 | * @param string $loginName |
||
| 680 | * @return array |
||
| 681 | */ |
||
| 682 | View Code Duplication | public function countUsersByLoginName($loginName) { |
|
| 683 | $loginName = $this->escapeFilterPart($loginName); |
||
| 684 | $filter = str_replace('%uid', $loginName, $this->connection->ldapLoginFilter); |
||
| 685 | $users = $this->countUsers($filter); |
||
| 686 | return $users; |
||
| 687 | } |
||
| 688 | |||
| 689 | /** |
||
| 690 | * @param string $filter |
||
| 691 | * @param string|string[] $attr |
||
| 692 | * @param int $limit |
||
| 693 | * @param int $offset |
||
| 694 | * @return array |
||
| 695 | */ |
||
| 696 | public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null) { |
||
| 701 | |||
| 702 | /** |
||
| 703 | * provided with an array of LDAP user records the method will fetch the |
||
| 704 | * user object and requests it to process the freshly fetched attributes and |
||
| 705 | * and their values |
||
| 706 | * @param array $ldapRecords |
||
| 707 | */ |
||
| 708 | 1 | public function batchApplyUserAttributes(array $ldapRecords){ |
|
| 709 | 1 | foreach($ldapRecords as $userRecord) { |
|
| 710 | 1 | $ocName = $this->dn2ocname($userRecord['dn'][0]); |
|
| 711 | 1 | $this->cacheUserExists($ocName); |
|
| 712 | 1 | $user = $this->userManager->get($ocName); |
|
| 713 | 1 | if($user instanceof OfflineUser) { |
|
| 714 | $user->unmark(); |
||
| 715 | $user = $this->userManager->get($ocName); |
||
| 716 | } |
||
| 717 | 1 | $user->processAttributes($userRecord); |
|
| 718 | 1 | } |
|
| 719 | 1 | } |
|
| 720 | |||
| 721 | /** |
||
| 722 | * @param string $filter |
||
| 723 | * @param string|string[] $attr |
||
| 724 | * @param int $limit |
||
| 725 | * @param int $offset |
||
| 726 | * @return array |
||
| 727 | */ |
||
| 728 | public function fetchListOfGroups($filter, $attr, $limit = null, $offset = null) { |
||
| 731 | |||
| 732 | /** |
||
| 733 | * @param array $list |
||
| 734 | * @param bool $manyAttributes |
||
| 735 | * @return array |
||
| 736 | */ |
||
| 737 | private function fetchList($list, $manyAttributes) { |
||
| 754 | |||
| 755 | /** |
||
| 756 | * executes an LDAP search, optimized for Users |
||
| 757 | * @param string $filter the LDAP filter for the search |
||
| 758 | * @param string|string[] $attr optional, when a certain attribute shall be filtered out |
||
| 759 | * @param integer $limit |
||
| 760 | * @param integer $offset |
||
| 761 | * @return array with the search result |
||
| 762 | * |
||
| 763 | * Executes an LDAP search |
||
| 764 | */ |
||
| 765 | public function searchUsers($filter, $attr = null, $limit = null, $offset = null) { |
||
| 768 | |||
| 769 | /** |
||
| 770 | * @param string $filter |
||
| 771 | * @param string|string[] $attr |
||
| 772 | * @param int $limit |
||
| 773 | * @param int $offset |
||
| 774 | * @return false|int |
||
| 775 | */ |
||
| 776 | public function countUsers($filter, $attr = array('dn'), $limit = null, $offset = null) { |
||
| 779 | |||
| 780 | /** |
||
| 781 | * executes an LDAP search, optimized for Groups |
||
| 782 | * @param string $filter the LDAP filter for the search |
||
| 783 | * @param string|string[] $attr optional, when a certain attribute shall be filtered out |
||
| 784 | * @param integer $limit |
||
| 785 | * @param integer $offset |
||
| 786 | * @return array with the search result |
||
| 787 | * |
||
| 788 | * Executes an LDAP search |
||
| 789 | */ |
||
| 790 | public function searchGroups($filter, $attr = null, $limit = null, $offset = null) { |
||
| 793 | |||
| 794 | /** |
||
| 795 | * returns the number of available groups |
||
| 796 | * @param string $filter the LDAP search filter |
||
| 797 | * @param string[] $attr optional |
||
| 798 | * @param int|null $limit |
||
| 799 | * @param int|null $offset |
||
| 800 | * @return int|bool |
||
| 801 | */ |
||
| 802 | public function countGroups($filter, $attr = array('dn'), $limit = null, $offset = null) { |
||
| 805 | |||
| 806 | /** |
||
| 807 | * returns the number of available objects on the base DN |
||
| 808 | * |
||
| 809 | * @param int|null $limit |
||
| 810 | * @param int|null $offset |
||
| 811 | * @return int|bool |
||
| 812 | */ |
||
| 813 | public function countObjects($limit = null, $offset = null) { |
||
| 816 | |||
| 817 | /** |
||
| 818 | * retrieved. Results will according to the order in the array. |
||
| 819 | * @param int $limit optional, maximum results to be counted |
||
| 820 | * @param int $offset optional, a starting point |
||
| 821 | * @return array|false array with the search result as first value and pagedSearchOK as |
||
| 822 | * second | false if not successful |
||
| 823 | */ |
||
| 824 | private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) { |
||
| 855 | |||
| 856 | /** |
||
| 857 | * processes an LDAP paged search operation |
||
| 858 | * @param array $sr the array containing the LDAP search resources |
||
| 859 | * @param string $filter the LDAP filter for the search |
||
| 860 | * @param array $base an array containing the LDAP subtree(s) that shall be searched |
||
| 861 | * @param int $iFoundItems number of results in the search operation |
||
| 862 | * @param int $limit maximum results to be counted |
||
| 863 | * @param int $offset a starting point |
||
| 864 | * @param bool $pagedSearchOK whether a paged search has been executed |
||
| 865 | * @param bool $skipHandling required for paged search when cookies to |
||
| 866 | * prior results need to be gained |
||
| 867 | * @return array|false array with the search result as first value and pagedSearchOK as |
||
| 868 | * second | false if not successful |
||
| 869 | */ |
||
| 870 | private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) { |
||
| 896 | |||
| 897 | /** |
||
| 898 | * executes an LDAP search, but counts the results only |
||
| 899 | * @param string $filter the LDAP filter for the search |
||
| 900 | * @param array $base an array containing the LDAP subtree(s) that shall be searched |
||
| 901 | * @param string|string[] $attr optional, array, one or more attributes that shall be |
||
| 902 | * retrieved. Results will according to the order in the array. |
||
| 903 | * @param int $limit optional, maximum results to be counted |
||
| 904 | * @param int $offset optional, a starting point |
||
| 905 | * @param bool $skipHandling indicates whether the pages search operation is |
||
| 906 | * completed |
||
| 907 | * @return int|false Integer or false if the search could not be initialized |
||
| 908 | * |
||
| 909 | */ |
||
| 910 | private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
||
| 941 | |||
| 942 | /** |
||
| 943 | * @param array $searchResults |
||
| 944 | * @param int $limit |
||
| 945 | * @param bool $hasHitLimit |
||
| 946 | * @return int |
||
| 947 | */ |
||
| 948 | private function countEntriesInSearchResults($searchResults, $limit, &$hasHitLimit) { |
||
| 962 | |||
| 963 | /** |
||
| 964 | * Executes an LDAP search |
||
| 965 | * @param string $filter the LDAP filter for the search |
||
| 966 | * @param array $base an array containing the LDAP subtree(s) that shall be searched |
||
| 967 | * @param string|string[] $attr optional, array, one or more attributes that shall be |
||
| 968 | * @param int $limit |
||
| 969 | * @param int $offset |
||
| 970 | * @param bool $skipHandling |
||
| 971 | * @return array with the search result |
||
| 972 | */ |
||
| 973 | private function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
||
| 1059 | |||
| 1060 | /** |
||
| 1061 | * @param string $name |
||
| 1062 | * @return bool|mixed|string |
||
| 1063 | */ |
||
| 1064 | public function sanitizeUsername($name) { |
||
| 1081 | |||
| 1082 | /** |
||
| 1083 | * escapes (user provided) parts for LDAP filter |
||
| 1084 | * @param string $input, the provided value |
||
| 1085 | * @param bool $allowAsterisk whether in * at the beginning should be preserved |
||
| 1086 | * @return string the escaped string |
||
| 1087 | */ |
||
| 1088 | 3 | public function escapeFilterPart($input, $allowAsterisk = false) { |
|
| 1098 | |||
| 1099 | /** |
||
| 1100 | * combines the input filters with AND |
||
| 1101 | * @param string[] $filters the filters to connect |
||
| 1102 | * @return string the combined filter |
||
| 1103 | */ |
||
| 1104 | public function combineFilterWithAnd($filters) { |
||
| 1107 | |||
| 1108 | /** |
||
| 1109 | * combines the input filters with OR |
||
| 1110 | * @param string[] $filters the filters to connect |
||
| 1111 | * @return string the combined filter |
||
| 1112 | * Combines Filter arguments with OR |
||
| 1113 | */ |
||
| 1114 | public function combineFilterWithOr($filters) { |
||
| 1117 | |||
| 1118 | /** |
||
| 1119 | * combines the input filters with given operator |
||
| 1120 | * @param string[] $filters the filters to connect |
||
| 1121 | * @param string $operator either & or | |
||
| 1122 | * @return string the combined filter |
||
| 1123 | */ |
||
| 1124 | private function combineFilter($filters, $operator) { |
||
| 1135 | |||
| 1136 | /** |
||
| 1137 | * creates a filter part for to perform search for users |
||
| 1138 | * @param string $search the search term |
||
| 1139 | * @return string the final filter part to use in LDAP searches |
||
| 1140 | */ |
||
| 1141 | public function getFilterPartForUserSearch($search) { |
||
| 1146 | |||
| 1147 | /** |
||
| 1148 | * creates a filter part for to perform search for groups |
||
| 1149 | * @param string $search the search term |
||
| 1150 | * @return string the final filter part to use in LDAP searches |
||
| 1151 | */ |
||
| 1152 | public function getFilterPartForGroupSearch($search) { |
||
| 1157 | |||
| 1158 | /** |
||
| 1159 | * creates a filter part for searches by splitting up the given search |
||
| 1160 | * string into single words |
||
| 1161 | * @param string $search the search term |
||
| 1162 | * @param string[] $searchAttributes needs to have at least two attributes, |
||
| 1163 | * otherwise it does not make sense :) |
||
| 1164 | * @return string the final filter part to use in LDAP searches |
||
| 1165 | * @throws \Exception |
||
| 1166 | */ |
||
| 1167 | private function getAdvancedFilterPartForSearch($search, $searchAttributes) { |
||
| 1184 | |||
| 1185 | /** |
||
| 1186 | * creates a filter part for searches |
||
| 1187 | * @param string $search the search term |
||
| 1188 | * @param string[]|null $searchAttributes |
||
| 1189 | * @param string $fallbackAttribute a fallback attribute in case the user |
||
| 1190 | * did not define search attributes. Typically the display name attribute. |
||
| 1191 | * @return string the final filter part to use in LDAP searches |
||
| 1192 | */ |
||
| 1193 | private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) { |
||
| 1223 | |||
| 1224 | /** |
||
| 1225 | * returns the filter used for counting users |
||
| 1226 | * @return string |
||
| 1227 | */ |
||
| 1228 | public function getFilterForUserCount() { |
||
| 1236 | |||
| 1237 | /** |
||
| 1238 | * @param string $name |
||
| 1239 | * @param string $password |
||
| 1240 | * @return bool |
||
| 1241 | */ |
||
| 1242 | public function areCredentialsValid($name, $password) { |
||
| 1256 | |||
| 1257 | /** |
||
| 1258 | * reverse lookup of a DN given a known UUID |
||
| 1259 | * |
||
| 1260 | * @param string $uuid |
||
| 1261 | * @return string |
||
| 1262 | * @throws \Exception |
||
| 1263 | */ |
||
| 1264 | public function getUserDnByUuid($uuid) { |
||
| 1304 | |||
| 1305 | /** |
||
| 1306 | * auto-detects the directory's UUID attribute |
||
| 1307 | * @param string $dn a known DN used to check against |
||
| 1308 | * @param bool $isUser |
||
| 1309 | * @param bool $force the detection should be run, even if it is not set to auto |
||
| 1310 | * @return bool true on success, false otherwise |
||
| 1311 | */ |
||
| 1312 | private function detectUuidAttribute($dn, $isUser = true, $force = false) { |
||
| 1349 | |||
| 1350 | /** |
||
| 1351 | * @param string $dn |
||
| 1352 | * @param bool $isUser |
||
| 1353 | * @return string|bool |
||
| 1354 | */ |
||
| 1355 | public function getUUID($dn, $isUser = true) { |
||
| 1380 | |||
| 1381 | /** |
||
| 1382 | * converts a binary ObjectGUID into a string representation |
||
| 1383 | * @param string $oguid the ObjectGUID in it's binary form as retrieved from AD |
||
| 1384 | * @return string |
||
| 1385 | * @link http://www.php.net/manual/en/function.ldap-get-values-len.php#73198 |
||
| 1386 | */ |
||
| 1387 | private function convertObjectGUID2Str($oguid) { |
||
| 1406 | |||
| 1407 | /** |
||
| 1408 | * the first three blocks of the string-converted GUID happen to be in |
||
| 1409 | * reverse order. In order to use it in a filter, this needs to be |
||
| 1410 | * corrected. Furthermore the dashes need to be replaced and \\ preprended |
||
| 1411 | * to every two hax figures. |
||
| 1412 | * |
||
| 1413 | * If an invalid string is passed, it will be returned without change. |
||
| 1414 | * |
||
| 1415 | * @param string $guid |
||
| 1416 | * @return string |
||
| 1417 | */ |
||
| 1418 | public function formatGuid2ForFilterUser($guid) { |
||
| 1453 | |||
| 1454 | /** |
||
| 1455 | * gets a SID of the domain of the given dn |
||
| 1456 | * @param string $dn |
||
| 1457 | * @return string|bool |
||
| 1458 | */ |
||
| 1459 | public function getSID($dn) { |
||
| 1476 | |||
| 1477 | /** |
||
| 1478 | * converts a binary SID into a string representation |
||
| 1479 | * @param string $sid |
||
| 1480 | * @return string |
||
| 1481 | */ |
||
| 1482 | 3 | public function convertSID2Str($sid) { |
|
| 1514 | |||
| 1515 | /** |
||
| 1516 | * converts a stored DN so it can be used as base parameter for LDAP queries, internally we store them for usage in LDAP filters |
||
| 1517 | * @param string $dn the DN |
||
| 1518 | * @return string |
||
| 1519 | */ |
||
| 1520 | 4 | private function DNasBaseParameter($dn) { |
|
| 1523 | |||
| 1524 | /** |
||
| 1525 | * checks if the given DN is part of the given base DN(s) |
||
| 1526 | * @param string $dn the DN |
||
| 1527 | * @param string[] $bases array containing the allowed base DN or DNs |
||
| 1528 | * @return bool |
||
| 1529 | */ |
||
| 1530 | public function isDNPartOfBase($dn, $bases) { |
||
| 1545 | |||
| 1546 | /** |
||
| 1547 | * resets a running Paged Search operation |
||
| 1548 | */ |
||
| 1549 | 4 | private function abandonPagedSearch() { |
|
| 1558 | |||
| 1559 | /** |
||
| 1560 | * get a cookie for the next LDAP paged search |
||
| 1561 | * @param string $base a string with the base DN for the search |
||
| 1562 | * @param string $filter the search filter to identify the correct search |
||
| 1563 | * @param int $limit the limit (or 'pageSize'), to identify the correct search well |
||
| 1564 | * @param int $offset the offset for the new search to identify the correct search really good |
||
| 1565 | * @return string containing the key or empty if none is cached |
||
| 1566 | */ |
||
| 1567 | private function getPagedResultCookie($base, $filter, $limit, $offset) { |
||
| 1583 | |||
| 1584 | /** |
||
| 1585 | * checks whether an LDAP paged search operation has more pages that can be |
||
| 1586 | * retrieved, typically when offset and limit are provided. |
||
| 1587 | * |
||
| 1588 | * Be very careful to use it: the last cookie value, which is inspected, can |
||
| 1589 | * be reset by other operations. Best, call it immediately after a search(), |
||
| 1590 | * searchUsers() or searchGroups() call. count-methods are probably safe as |
||
| 1591 | * well. Don't rely on it with any fetchList-method. |
||
| 1592 | * @return bool |
||
| 1593 | */ |
||
| 1594 | public function hasMoreResults() { |
||
| 1607 | |||
| 1608 | /** |
||
| 1609 | * set a cookie for LDAP paged search run |
||
| 1610 | * @param string $base a string with the base DN for the search |
||
| 1611 | * @param string $filter the search filter to identify the correct search |
||
| 1612 | * @param int $limit the limit (or 'pageSize'), to identify the correct search well |
||
| 1613 | * @param int $offset the offset for the run search to identify the correct search really good |
||
| 1614 | * @param string $cookie string containing the cookie returned by ldap_control_paged_result_response |
||
| 1615 | * @return void |
||
| 1616 | */ |
||
| 1617 | private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) { |
||
| 1625 | |||
| 1626 | /** |
||
| 1627 | * Check whether the most recent paged search was successful. It flushed the state var. Use it always after a possible paged search. |
||
| 1628 | * @return boolean|null true on success, null or false otherwise |
||
| 1629 | */ |
||
| 1630 | public function getPagedSearchResultState() { |
||
| 1635 | |||
| 1636 | /** |
||
| 1637 | * Prepares a paged search, if possible |
||
| 1638 | * @param string $filter the LDAP filter for the search |
||
| 1639 | * @param string[] $bases an array containing the LDAP subtree(s) that shall be searched |
||
| 1640 | * @param string[] $attr optional, when a certain attribute shall be filtered outside |
||
| 1641 | * @param int $limit |
||
| 1642 | * @param int $offset |
||
| 1643 | * @return bool|true |
||
| 1644 | */ |
||
| 1645 | 4 | private function initPagedSearch($filter, $bases, $attr, $limit, $offset) { |
|
| 1707 | |||
| 1708 | } |
||
| 1709 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: