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 |
||
62 | class Access extends LDAPUtility implements IUserTools { |
||
63 | const UUID_ATTRIBUTES = ['entryuuid', 'nsuniqueid', 'objectguid', 'guid', 'ipauniqueid']; |
||
64 | |||
65 | /** @var \OCA\User_LDAP\Connection */ |
||
66 | public $connection; |
||
67 | /** @var Manager */ |
||
68 | public $userManager; |
||
69 | //never ever check this var directly, always use getPagedSearchResultState |
||
70 | protected $pagedSearchedSuccessful; |
||
71 | |||
72 | /** |
||
73 | * @var string[] $cookies an array of returned Paged Result cookies |
||
74 | */ |
||
75 | protected $cookies = array(); |
||
76 | |||
77 | /** |
||
78 | * @var string $lastCookie the last cookie returned from a Paged Results |
||
79 | * operation, defaults to an empty string |
||
80 | */ |
||
81 | protected $lastCookie = ''; |
||
82 | |||
83 | /** |
||
84 | * @var AbstractMapping $userMapper |
||
85 | */ |
||
86 | protected $userMapper; |
||
87 | |||
88 | /** |
||
89 | * @var AbstractMapping $userMapper |
||
90 | */ |
||
91 | protected $groupMapper; |
||
92 | |||
93 | /** |
||
94 | * @var \OCA\User_LDAP\Helper |
||
95 | */ |
||
96 | private $helper; |
||
97 | /** @var IConfig */ |
||
98 | private $config; |
||
99 | /** @var IUserManager */ |
||
100 | private $ncUserManager; |
||
101 | |||
102 | public function __construct( |
||
118 | |||
119 | /** |
||
120 | * sets the User Mapper |
||
121 | * @param AbstractMapping $mapper |
||
122 | */ |
||
123 | public function setUserMapper(AbstractMapping $mapper) { |
||
126 | |||
127 | /** |
||
128 | * returns the User Mapper |
||
129 | * @throws \Exception |
||
130 | * @return AbstractMapping |
||
131 | */ |
||
132 | public function getUserMapper() { |
||
138 | |||
139 | /** |
||
140 | * sets the Group Mapper |
||
141 | * @param AbstractMapping $mapper |
||
142 | */ |
||
143 | public function setGroupMapper(AbstractMapping $mapper) { |
||
146 | |||
147 | /** |
||
148 | * returns the Group Mapper |
||
149 | * @throws \Exception |
||
150 | * @return AbstractMapping |
||
151 | */ |
||
152 | public function getGroupMapper() { |
||
158 | |||
159 | /** |
||
160 | * @return bool |
||
161 | */ |
||
162 | private function checkConnection() { |
||
165 | |||
166 | /** |
||
167 | * returns the Connection instance |
||
168 | * @return \OCA\User_LDAP\Connection |
||
169 | */ |
||
170 | public function getConnection() { |
||
173 | |||
174 | /** |
||
175 | * reads a given attribute for an LDAP record identified by a DN |
||
176 | * |
||
177 | * @param string $dn the record in question |
||
178 | * @param string $attr the attribute that shall be retrieved |
||
179 | * if empty, just check the record's existence |
||
180 | * @param string $filter |
||
181 | * @return array|false an array of values on success or an empty |
||
182 | * array if $attr is empty, false otherwise |
||
183 | * @throws ServerNotAvailableException |
||
184 | */ |
||
185 | public function readAttribute($dn, $attr, $filter = 'objectClass=*') { |
||
253 | |||
254 | /** |
||
255 | * Runs an read operation against LDAP |
||
256 | * |
||
257 | * @param resource $cr the LDAP connection |
||
258 | * @param string $dn |
||
259 | * @param string $attribute |
||
260 | * @param string $filter |
||
261 | * @param int $maxResults |
||
262 | * @return array|bool false if there was any error, true if an exists check |
||
263 | * was performed and the requested DN found, array with the |
||
264 | * returned data on a successful usual operation |
||
265 | * @throws ServerNotAvailableException |
||
266 | */ |
||
267 | public function executeRead($cr, $dn, $attribute, $filter, $maxResults) { |
||
268 | $this->initPagedSearch($filter, array($dn), array($attribute), $maxResults, 0); |
||
269 | $dn = $this->helper->DNasBaseParameter($dn); |
||
270 | $rr = @$this->invokeLDAPMethod('read', $cr, $dn, $filter, array($attribute)); |
||
271 | View Code Duplication | if (!$this->ldap->isResource($rr)) { |
|
272 | if ($attribute !== '') { |
||
273 | //do not throw this message on userExists check, irritates |
||
274 | \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, ILogger::DEBUG); |
||
275 | } |
||
276 | //in case an error occurs , e.g. object does not exist |
||
277 | return false; |
||
278 | } |
||
279 | if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) { |
||
280 | \OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', ILogger::DEBUG); |
||
281 | return true; |
||
282 | } |
||
283 | $er = $this->invokeLDAPMethod('firstEntry', $cr, $rr); |
||
284 | if (!$this->ldap->isResource($er)) { |
||
285 | //did not match the filter, return false |
||
286 | return false; |
||
287 | } |
||
288 | //LDAP attributes are not case sensitive |
||
289 | $result = \OCP\Util::mb_array_change_key_case( |
||
290 | $this->invokeLDAPMethod('getAttributes', $cr, $er), MB_CASE_LOWER, 'UTF-8'); |
||
291 | |||
292 | return $result; |
||
293 | } |
||
294 | |||
295 | /** |
||
296 | * Normalizes a result grom getAttributes(), i.e. handles DNs and binary |
||
297 | * data if present. |
||
298 | * |
||
299 | * @param array $result from ILDAPWrapper::getAttributes() |
||
300 | * @param string $attribute the attribute name that was read |
||
301 | * @return string[] |
||
302 | */ |
||
303 | public function extractAttributeValuesFromResult($result, $attribute) { |
||
319 | |||
320 | /** |
||
321 | * Attempts to find ranged data in a getAttribute results and extracts the |
||
322 | * returned values as well as information on the range and full attribute |
||
323 | * name for further processing. |
||
324 | * |
||
325 | * @param array $result from ILDAPWrapper::getAttributes() |
||
326 | * @param string $attribute the attribute name that was read. Without ";range=…" |
||
327 | * @return array If a range was detected with keys 'values', 'attributeName', |
||
328 | * 'attributeFull' and 'rangeHigh', otherwise empty. |
||
329 | */ |
||
330 | public function extractRangeData($result, $attribute) { |
||
349 | |||
350 | /** |
||
351 | * Set password for an LDAP user identified by a DN |
||
352 | * |
||
353 | * @param string $userDN the user in question |
||
354 | * @param string $password the new password |
||
355 | * @return bool |
||
356 | * @throws HintException |
||
357 | * @throws \Exception |
||
358 | */ |
||
359 | public function setPassword($userDN, $password) { |
||
375 | |||
376 | /** |
||
377 | * checks whether the given attributes value is probably a DN |
||
378 | * @param string $attr the attribute in question |
||
379 | * @return boolean if so true, otherwise false |
||
380 | */ |
||
381 | private function resemblesDN($attr) { |
||
391 | |||
392 | /** |
||
393 | * checks whether the given string is probably a DN |
||
394 | * @param string $string |
||
395 | * @return boolean |
||
396 | */ |
||
397 | public function stringResemblesDN($string) { |
||
403 | |||
404 | /** |
||
405 | * returns a DN-string that is cleaned from not domain parts, e.g. |
||
406 | * cn=foo,cn=bar,dc=foobar,dc=server,dc=org |
||
407 | * becomes dc=foobar,dc=server,dc=org |
||
408 | * @param string $dn |
||
409 | * @return string |
||
410 | */ |
||
411 | public function getDomainDNFromDN($dn) { |
||
429 | |||
430 | /** |
||
431 | * returns the LDAP DN for the given internal Nextcloud name of the group |
||
432 | * @param string $name the Nextcloud name in question |
||
433 | * @return string|false LDAP DN on success, otherwise false |
||
434 | */ |
||
435 | public function groupname2dn($name) { |
||
438 | |||
439 | /** |
||
440 | * returns the LDAP DN for the given internal Nextcloud name of the user |
||
441 | * @param string $name the Nextcloud name in question |
||
442 | * @return string|false with the LDAP DN on success, otherwise false |
||
443 | */ |
||
444 | public function username2dn($name) { |
||
455 | |||
456 | /** |
||
457 | * returns the internal Nextcloud name for the given LDAP DN of the group, false on DN outside of search DN or failure |
||
458 | * @param string $fdn the dn of the group object |
||
459 | * @param string $ldapName optional, the display name of the object |
||
460 | * @return string|false with the name to use in Nextcloud, false on DN outside of search DN |
||
461 | */ |
||
462 | View Code Duplication | public function dn2groupname($fdn, $ldapName = null) { |
|
472 | |||
473 | /** |
||
474 | * accepts an array of group DNs and tests whether they match the user |
||
475 | * filter by doing read operations against the group entries. Returns an |
||
476 | * array of DNs that match the filter. |
||
477 | * |
||
478 | * @param string[] $groupDNs |
||
479 | * @return string[] |
||
480 | * @throws ServerNotAvailableException |
||
481 | */ |
||
482 | public function groupsMatchFilter($groupDNs) { |
||
512 | |||
513 | /** |
||
514 | * returns the internal Nextcloud name for the given LDAP DN of the user, false on DN outside of search DN or failure |
||
515 | * @param string $dn the dn of the user object |
||
516 | * @param string $ldapName optional, the display name of the object |
||
517 | * @return string|false with with the name to use in Nextcloud |
||
518 | */ |
||
519 | View Code Duplication | public function dn2username($fdn, $ldapName = null) { |
|
529 | |||
530 | /** |
||
531 | * returns an internal Nextcloud name for the given LDAP DN, false on DN outside of search DN |
||
532 | * |
||
533 | * @param string $fdn the dn of the user object |
||
534 | * @param string|null $ldapName optional, the display name of the object |
||
535 | * @param bool $isUser optional, whether it is a user object (otherwise group assumed) |
||
536 | * @param bool|null $newlyMapped |
||
537 | * @param array|null $record |
||
538 | * @return false|string with with the name to use in Nextcloud |
||
539 | * @throws \Exception |
||
540 | */ |
||
541 | public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) { |
||
639 | |||
640 | /** |
||
641 | * gives back the user names as they are used ownClod internally |
||
642 | * @param array $ldapUsers as returned by fetchList() |
||
643 | * @return array an array with the user names to use in Nextcloud |
||
644 | * |
||
645 | * gives back the user names as they are used ownClod internally |
||
646 | */ |
||
647 | public function nextcloudUserNames($ldapUsers) { |
||
650 | |||
651 | /** |
||
652 | * gives back the group names as they are used ownClod internally |
||
653 | * @param array $ldapGroups as returned by fetchList() |
||
654 | * @return array an array with the group names to use in Nextcloud |
||
655 | * |
||
656 | * gives back the group names as they are used ownClod internally |
||
657 | */ |
||
658 | public function nextcloudGroupNames($ldapGroups) { |
||
661 | |||
662 | /** |
||
663 | * @param array $ldapObjects as returned by fetchList() |
||
664 | * @param bool $isUsers |
||
665 | * @return array |
||
666 | * @throws \Exception |
||
667 | */ |
||
668 | private function ldap2NextcloudNames($ldapObjects, $isUsers) { |
||
705 | |||
706 | /** |
||
707 | * removes the deleted-flag of a user if it was set |
||
708 | * |
||
709 | * @param string $ncname |
||
710 | * @throws \Exception |
||
711 | */ |
||
712 | public function updateUserState($ncname) { |
||
718 | |||
719 | /** |
||
720 | * caches the user display name |
||
721 | * @param string $ocName the internal Nextcloud username |
||
722 | * @param string|false $home the home directory path |
||
723 | */ |
||
724 | public function cacheUserHome($ocName, $home) { |
||
728 | |||
729 | /** |
||
730 | * caches a user as existing |
||
731 | * @param string $ocName the internal Nextcloud username |
||
732 | */ |
||
733 | public function cacheUserExists($ocName) { |
||
736 | |||
737 | /** |
||
738 | * caches the user display name |
||
739 | * @param string $ocName the internal Nextcloud username |
||
740 | * @param string $displayName the display name |
||
741 | * @param string $displayName2 the second display name |
||
742 | */ |
||
743 | public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') { |
||
752 | |||
753 | /** |
||
754 | * creates a unique name for internal Nextcloud use for users. Don't call it directly. |
||
755 | * @param string $name the display name of the object |
||
756 | * @return string|false with with the name to use in Nextcloud or false if unsuccessful |
||
757 | * |
||
758 | * Instead of using this method directly, call |
||
759 | * createAltInternalOwnCloudName($name, true) |
||
760 | */ |
||
761 | private function _createAltInternalOwnCloudNameForUsers($name) { |
||
774 | |||
775 | /** |
||
776 | * creates a unique name for internal Nextcloud use for groups. Don't call it directly. |
||
777 | * @param string $name the display name of the object |
||
778 | * @return string|false with with the name to use in Nextcloud or false if unsuccessful. |
||
779 | * |
||
780 | * Instead of using this method directly, call |
||
781 | * createAltInternalOwnCloudName($name, false) |
||
782 | * |
||
783 | * Group names are also used as display names, so we do a sequential |
||
784 | * numbering, e.g. Developers_42 when there are 41 other groups called |
||
785 | * "Developers" |
||
786 | */ |
||
787 | private function _createAltInternalOwnCloudNameForGroups($name) { |
||
812 | |||
813 | /** |
||
814 | * creates a unique name for internal Nextcloud use. |
||
815 | * @param string $name the display name of the object |
||
816 | * @param boolean $isUser whether name should be created for a user (true) or a group (false) |
||
817 | * @return string|false with with the name to use in Nextcloud or false if unsuccessful |
||
818 | */ |
||
819 | private function createAltInternalOwnCloudName($name, $isUser) { |
||
831 | |||
832 | /** |
||
833 | * fetches a list of users according to a provided loginName and utilizing |
||
834 | * the login filter. |
||
835 | * |
||
836 | * @param string $loginName |
||
837 | * @param array $attributes optional, list of attributes to read |
||
838 | * @return array |
||
839 | */ |
||
840 | public function fetchUsersByLoginName($loginName, $attributes = array('dn')) { |
||
845 | |||
846 | /** |
||
847 | * counts the number of users according to a provided loginName and |
||
848 | * utilizing the login filter. |
||
849 | * |
||
850 | * @param string $loginName |
||
851 | * @return int |
||
852 | */ |
||
853 | public function countUsersByLoginName($loginName) { |
||
858 | |||
859 | /** |
||
860 | * @param string $filter |
||
861 | * @param string|string[] $attr |
||
862 | * @param int $limit |
||
863 | * @param int $offset |
||
864 | * @param bool $forceApplyAttributes |
||
865 | * @return array |
||
866 | */ |
||
867 | public function fetchListOfUsers($filter, $attr, $limit = null, $offset = null, $forceApplyAttributes = false) { |
||
885 | |||
886 | /** |
||
887 | * provided with an array of LDAP user records the method will fetch the |
||
888 | * user object and requests it to process the freshly fetched attributes and |
||
889 | * and their values |
||
890 | * |
||
891 | * @param array $ldapRecords |
||
892 | * @throws \Exception |
||
893 | */ |
||
894 | public function batchApplyUserAttributes(array $ldapRecords){ |
||
917 | |||
918 | /** |
||
919 | * @param string $filter |
||
920 | * @param string|string[] $attr |
||
921 | * @param int $limit |
||
922 | * @param int $offset |
||
923 | * @return array |
||
924 | */ |
||
925 | public function fetchListOfGroups($filter, $attr, $limit = null, $offset = null) { |
||
928 | |||
929 | /** |
||
930 | * @param array $list |
||
931 | * @param bool $manyAttributes |
||
932 | * @return array |
||
933 | */ |
||
934 | private function fetchList($list, $manyAttributes) { |
||
951 | |||
952 | /** |
||
953 | * executes an LDAP search, optimized for Users |
||
954 | * @param string $filter the LDAP filter for the search |
||
955 | * @param string|string[] $attr optional, when a certain attribute shall be filtered out |
||
956 | * @param integer $limit |
||
957 | * @param integer $offset |
||
958 | * @return array with the search result |
||
959 | * |
||
960 | * Executes an LDAP search |
||
961 | */ |
||
962 | public function searchUsers($filter, $attr = null, $limit = null, $offset = null) { |
||
965 | |||
966 | /** |
||
967 | * @param string $filter |
||
968 | * @param string|string[] $attr |
||
969 | * @param int $limit |
||
970 | * @param int $offset |
||
971 | * @return false|int |
||
972 | */ |
||
973 | public function countUsers($filter, $attr = array('dn'), $limit = null, $offset = null) { |
||
976 | |||
977 | /** |
||
978 | * executes an LDAP search, optimized for Groups |
||
979 | * @param string $filter the LDAP filter for the search |
||
980 | * @param string|string[] $attr optional, when a certain attribute shall be filtered out |
||
981 | * @param integer $limit |
||
982 | * @param integer $offset |
||
983 | * @return array with the search result |
||
984 | * |
||
985 | * Executes an LDAP search |
||
986 | */ |
||
987 | public function searchGroups($filter, $attr = null, $limit = null, $offset = null) { |
||
990 | |||
991 | /** |
||
992 | * returns the number of available groups |
||
993 | * @param string $filter the LDAP search filter |
||
994 | * @param string[] $attr optional |
||
995 | * @param int|null $limit |
||
996 | * @param int|null $offset |
||
997 | * @return int|bool |
||
998 | */ |
||
999 | public function countGroups($filter, $attr = array('dn'), $limit = null, $offset = null) { |
||
1002 | |||
1003 | /** |
||
1004 | * returns the number of available objects on the base DN |
||
1005 | * |
||
1006 | * @param int|null $limit |
||
1007 | * @param int|null $offset |
||
1008 | * @return int|bool |
||
1009 | */ |
||
1010 | public function countObjects($limit = null, $offset = null) { |
||
1013 | |||
1014 | /** |
||
1015 | * Returns the LDAP handler |
||
1016 | * @throws \OC\ServerNotAvailableException |
||
1017 | */ |
||
1018 | |||
1019 | /** |
||
1020 | * @return mixed |
||
1021 | * @throws \OC\ServerNotAvailableException |
||
1022 | */ |
||
1023 | private function invokeLDAPMethod() { |
||
1063 | |||
1064 | /** |
||
1065 | * retrieved. Results will according to the order in the array. |
||
1066 | * |
||
1067 | * @param $filter |
||
1068 | * @param $base |
||
1069 | * @param string[]|string|null $attr |
||
1070 | * @param int $limit optional, maximum results to be counted |
||
1071 | * @param int $offset optional, a starting point |
||
1072 | * @return array|false array with the search result as first value and pagedSearchOK as |
||
1073 | * second | false if not successful |
||
1074 | * @throws ServerNotAvailableException |
||
1075 | */ |
||
1076 | private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) { |
||
1104 | |||
1105 | /** |
||
1106 | * processes an LDAP paged search operation |
||
1107 | * @param array $sr the array containing the LDAP search resources |
||
1108 | * @param string $filter the LDAP filter for the search |
||
1109 | * @param array $base an array containing the LDAP subtree(s) that shall be searched |
||
1110 | * @param int $iFoundItems number of results in the single search operation |
||
1111 | * @param int $limit maximum results to be counted |
||
1112 | * @param int $offset a starting point |
||
1113 | * @param bool $pagedSearchOK whether a paged search has been executed |
||
1114 | * @param bool $skipHandling required for paged search when cookies to |
||
1115 | * prior results need to be gained |
||
1116 | * @return bool cookie validity, true if we have more pages, false otherwise. |
||
1117 | */ |
||
1118 | private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) { |
||
1153 | |||
1154 | /** |
||
1155 | * executes an LDAP search, but counts the results only |
||
1156 | * |
||
1157 | * @param string $filter the LDAP filter for the search |
||
1158 | * @param array $base an array containing the LDAP subtree(s) that shall be searched |
||
1159 | * @param string|string[] $attr optional, array, one or more attributes that shall be |
||
1160 | * retrieved. Results will according to the order in the array. |
||
1161 | * @param int $limit optional, maximum results to be counted |
||
1162 | * @param int $offset optional, a starting point |
||
1163 | * @param bool $skipHandling indicates whether the pages search operation is |
||
1164 | * completed |
||
1165 | * @return int|false Integer or false if the search could not be initialized |
||
1166 | * @throws ServerNotAvailableException |
||
1167 | */ |
||
1168 | private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
||
1205 | |||
1206 | /** |
||
1207 | * @param array $searchResults |
||
1208 | * @return int |
||
1209 | */ |
||
1210 | private function countEntriesInSearchResults($searchResults) { |
||
1220 | |||
1221 | /** |
||
1222 | * Executes an LDAP search |
||
1223 | * |
||
1224 | * @param string $filter the LDAP filter for the search |
||
1225 | * @param array $base an array containing the LDAP subtree(s) that shall be searched |
||
1226 | * @param string|string[] $attr optional, array, one or more attributes that shall be |
||
1227 | * @param int $limit |
||
1228 | * @param int $offset |
||
1229 | * @param bool $skipHandling |
||
1230 | * @return array with the search result |
||
1231 | * @throws ServerNotAvailableException |
||
1232 | */ |
||
1233 | public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
||
1331 | |||
1332 | /** |
||
1333 | * @param string $name |
||
1334 | * @return string |
||
1335 | * @throws \InvalidArgumentException |
||
1336 | */ |
||
1337 | public function sanitizeUsername($name) { |
||
1363 | |||
1364 | /** |
||
1365 | * escapes (user provided) parts for LDAP filter |
||
1366 | * @param string $input, the provided value |
||
1367 | * @param bool $allowAsterisk whether in * at the beginning should be preserved |
||
1368 | * @return string the escaped string |
||
1369 | */ |
||
1370 | public function escapeFilterPart($input, $allowAsterisk = false) { |
||
1380 | |||
1381 | /** |
||
1382 | * combines the input filters with AND |
||
1383 | * @param string[] $filters the filters to connect |
||
1384 | * @return string the combined filter |
||
1385 | */ |
||
1386 | public function combineFilterWithAnd($filters) { |
||
1389 | |||
1390 | /** |
||
1391 | * combines the input filters with OR |
||
1392 | * @param string[] $filters the filters to connect |
||
1393 | * @return string the combined filter |
||
1394 | * Combines Filter arguments with OR |
||
1395 | */ |
||
1396 | public function combineFilterWithOr($filters) { |
||
1399 | |||
1400 | /** |
||
1401 | * combines the input filters with given operator |
||
1402 | * @param string[] $filters the filters to connect |
||
1403 | * @param string $operator either & or | |
||
1404 | * @return string the combined filter |
||
1405 | */ |
||
1406 | private function combineFilter($filters, $operator) { |
||
1417 | |||
1418 | /** |
||
1419 | * creates a filter part for to perform search for users |
||
1420 | * @param string $search the search term |
||
1421 | * @return string the final filter part to use in LDAP searches |
||
1422 | */ |
||
1423 | public function getFilterPartForUserSearch($search) { |
||
1428 | |||
1429 | /** |
||
1430 | * creates a filter part for to perform search for groups |
||
1431 | * @param string $search the search term |
||
1432 | * @return string the final filter part to use in LDAP searches |
||
1433 | */ |
||
1434 | public function getFilterPartForGroupSearch($search) { |
||
1439 | |||
1440 | /** |
||
1441 | * creates a filter part for searches by splitting up the given search |
||
1442 | * string into single words |
||
1443 | * @param string $search the search term |
||
1444 | * @param string[] $searchAttributes needs to have at least two attributes, |
||
1445 | * otherwise it does not make sense :) |
||
1446 | * @return string the final filter part to use in LDAP searches |
||
1447 | * @throws \Exception |
||
1448 | */ |
||
1449 | private function getAdvancedFilterPartForSearch($search, $searchAttributes) { |
||
1466 | |||
1467 | /** |
||
1468 | * creates a filter part for searches |
||
1469 | * @param string $search the search term |
||
1470 | * @param string[]|null $searchAttributes |
||
1471 | * @param string $fallbackAttribute a fallback attribute in case the user |
||
1472 | * did not define search attributes. Typically the display name attribute. |
||
1473 | * @return string the final filter part to use in LDAP searches |
||
1474 | */ |
||
1475 | private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) { |
||
1506 | |||
1507 | /** |
||
1508 | * returns the search term depending on whether we are allowed |
||
1509 | * list users found by ldap with the current input appended by |
||
1510 | * a * |
||
1511 | * @return string |
||
1512 | */ |
||
1513 | private function prepareSearchTerm($term) { |
||
1526 | |||
1527 | /** |
||
1528 | * returns the filter used for counting users |
||
1529 | * @return string |
||
1530 | */ |
||
1531 | public function getFilterForUserCount() { |
||
1539 | |||
1540 | /** |
||
1541 | * @param string $name |
||
1542 | * @param string $password |
||
1543 | * @return bool |
||
1544 | */ |
||
1545 | public function areCredentialsValid($name, $password) { |
||
1557 | |||
1558 | /** |
||
1559 | * reverse lookup of a DN given a known UUID |
||
1560 | * |
||
1561 | * @param string $uuid |
||
1562 | * @return string |
||
1563 | * @throws \Exception |
||
1564 | */ |
||
1565 | public function getUserDnByUuid($uuid) { |
||
1605 | |||
1606 | /** |
||
1607 | * auto-detects the directory's UUID attribute |
||
1608 | * |
||
1609 | * @param string $dn a known DN used to check against |
||
1610 | * @param bool $isUser |
||
1611 | * @param bool $force the detection should be run, even if it is not set to auto |
||
1612 | * @param array|null $ldapRecord |
||
1613 | * @return bool true on success, false otherwise |
||
1614 | */ |
||
1615 | private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) { |
||
1663 | |||
1664 | /** |
||
1665 | * @param string $dn |
||
1666 | * @param bool $isUser |
||
1667 | * @param null $ldapRecord |
||
1668 | * @return bool|string |
||
1669 | */ |
||
1670 | public function getUUID($dn, $isUser = true, $ldapRecord = null) { |
||
1698 | |||
1699 | /** |
||
1700 | * converts a binary ObjectGUID into a string representation |
||
1701 | * @param string $oguid the ObjectGUID in it's binary form as retrieved from AD |
||
1702 | * @return string |
||
1703 | * @link http://www.php.net/manual/en/function.ldap-get-values-len.php#73198 |
||
1704 | */ |
||
1705 | private function convertObjectGUID2Str($oguid) { |
||
1724 | |||
1725 | /** |
||
1726 | * the first three blocks of the string-converted GUID happen to be in |
||
1727 | * reverse order. In order to use it in a filter, this needs to be |
||
1728 | * corrected. Furthermore the dashes need to be replaced and \\ preprended |
||
1729 | * to every two hax figures. |
||
1730 | * |
||
1731 | * If an invalid string is passed, it will be returned without change. |
||
1732 | * |
||
1733 | * @param string $guid |
||
1734 | * @return string |
||
1735 | */ |
||
1736 | public function formatGuid2ForFilterUser($guid) { |
||
1771 | |||
1772 | /** |
||
1773 | * gets a SID of the domain of the given dn |
||
1774 | * @param string $dn |
||
1775 | * @return string|bool |
||
1776 | */ |
||
1777 | public function getSID($dn) { |
||
1795 | |||
1796 | /** |
||
1797 | * converts a binary SID into a string representation |
||
1798 | * @param string $sid |
||
1799 | * @return string |
||
1800 | */ |
||
1801 | public function convertSID2Str($sid) { |
||
1833 | |||
1834 | /** |
||
1835 | * checks if the given DN is part of the given base DN(s) |
||
1836 | * @param string $dn the DN |
||
1837 | * @param string[] $bases array containing the allowed base DN or DNs |
||
1838 | * @return bool |
||
1839 | */ |
||
1840 | public function isDNPartOfBase($dn, $bases) { |
||
1855 | |||
1856 | /** |
||
1857 | * resets a running Paged Search operation |
||
1858 | */ |
||
1859 | private function abandonPagedSearch() { |
||
1868 | |||
1869 | /** |
||
1870 | * get a cookie for the next LDAP paged search |
||
1871 | * @param string $base a string with the base DN for the search |
||
1872 | * @param string $filter the search filter to identify the correct search |
||
1873 | * @param int $limit the limit (or 'pageSize'), to identify the correct search well |
||
1874 | * @param int $offset the offset for the new search to identify the correct search really good |
||
1875 | * @return string containing the key or empty if none is cached |
||
1876 | */ |
||
1877 | private function getPagedResultCookie($base, $filter, $limit, $offset) { |
||
1893 | |||
1894 | /** |
||
1895 | * checks whether an LDAP paged search operation has more pages that can be |
||
1896 | * retrieved, typically when offset and limit are provided. |
||
1897 | * |
||
1898 | * Be very careful to use it: the last cookie value, which is inspected, can |
||
1899 | * be reset by other operations. Best, call it immediately after a search(), |
||
1900 | * searchUsers() or searchGroups() call. count-methods are probably safe as |
||
1901 | * well. Don't rely on it with any fetchList-method. |
||
1902 | * @return bool |
||
1903 | */ |
||
1904 | public function hasMoreResults() { |
||
1917 | |||
1918 | /** |
||
1919 | * set a cookie for LDAP paged search run |
||
1920 | * @param string $base a string with the base DN for the search |
||
1921 | * @param string $filter the search filter to identify the correct search |
||
1922 | * @param int $limit the limit (or 'pageSize'), to identify the correct search well |
||
1923 | * @param int $offset the offset for the run search to identify the correct search really good |
||
1924 | * @param string $cookie string containing the cookie returned by ldap_control_paged_result_response |
||
1925 | * @return void |
||
1926 | */ |
||
1927 | private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) { |
||
1935 | |||
1936 | /** |
||
1937 | * Check whether the most recent paged search was successful. It flushed the state var. Use it always after a possible paged search. |
||
1938 | * @return boolean|null true on success, null or false otherwise |
||
1939 | */ |
||
1940 | public function getPagedSearchResultState() { |
||
1945 | |||
1946 | /** |
||
1947 | * Prepares a paged search, if possible |
||
1948 | * @param string $filter the LDAP filter for the search |
||
1949 | * @param string[] $bases an array containing the LDAP subtree(s) that shall be searched |
||
1950 | * @param string[] $attr optional, when a certain attribute shall be filtered outside |
||
1951 | * @param int $limit |
||
1952 | * @param int $offset |
||
1953 | * @return bool|true |
||
1954 | */ |
||
1955 | private function initPagedSearch($filter, $bases, $attr, $limit, $offset) { |
||
2018 | |||
2019 | } |
||
2020 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.