formatting

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2020-04-17 16:02:04 +02:00
parent ab550d682f
commit 4babdc082b
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
8 changed files with 254 additions and 144 deletions

View File

@ -61,6 +61,7 @@ use OCP\IUserManager;
/** /**
* Class Access * Class Access
*
* @package OCA\User_LDAP * @package OCA\User_LDAP
*/ */
class Access extends LDAPUtility { class Access extends LDAPUtility {
@ -75,6 +76,7 @@ class Access extends LDAPUtility {
/** /**
* protected $cookies = []; * protected $cookies = [];
*
* @var AbstractMapping $userMapper * @var AbstractMapping $userMapper
*/ */
protected $userMapper; protected $userMapper;
@ -114,6 +116,7 @@ class Access extends LDAPUtility {
/** /**
* sets the User Mapper * sets the User Mapper
*
* @param AbstractMapping $mapper * @param AbstractMapping $mapper
*/ */
public function setUserMapper(AbstractMapping $mapper) { public function setUserMapper(AbstractMapping $mapper) {
@ -122,8 +125,9 @@ class Access extends LDAPUtility {
/** /**
* returns the User Mapper * returns the User Mapper
* @throws \Exception *
* @return AbstractMapping * @return AbstractMapping
* @throws \Exception
*/ */
public function getUserMapper() { public function getUserMapper() {
if (is_null($this->userMapper)) { if (is_null($this->userMapper)) {
@ -134,6 +138,7 @@ class Access extends LDAPUtility {
/** /**
* sets the Group Mapper * sets the Group Mapper
*
* @param AbstractMapping $mapper * @param AbstractMapping $mapper
*/ */
public function setGroupMapper(AbstractMapping $mapper) { public function setGroupMapper(AbstractMapping $mapper) {
@ -142,8 +147,9 @@ class Access extends LDAPUtility {
/** /**
* returns the Group Mapper * returns the Group Mapper
* @throws \Exception *
* @return AbstractMapping * @return AbstractMapping
* @throws \Exception
*/ */
public function getGroupMapper() { public function getGroupMapper() {
if (is_null($this->groupMapper)) { if (is_null($this->groupMapper)) {
@ -161,6 +167,7 @@ class Access extends LDAPUtility {
/** /**
* returns the Connection instance * returns the Connection instance
*
* @return \OCA\User_LDAP\Connection * @return \OCA\User_LDAP\Connection
*/ */
public function getConnection() { public function getConnection() {
@ -226,7 +233,7 @@ class Access extends LDAPUtility {
$result = $this->extractRangeData($result, $attr); $result = $this->extractRangeData($result, $attr);
if (!empty($result)) { if (!empty($result)) {
$normalizedResult = $this->extractAttributeValuesFromResult( $normalizedResult = $this->extractAttributeValuesFromResult(
[ $attr => $result['values'] ], [$attr => $result['values']],
$attr $attr
); );
$values = array_merge($values, $normalizedResult); $values = array_merge($values, $normalizedResult);
@ -236,14 +243,14 @@ class Access extends LDAPUtility {
// no more results left // no more results left
return $values; return $values;
} else { } else {
$low = $result['rangeHigh'] + 1; $low = $result['rangeHigh'] + 1;
$attrToRead = $result['attributeName'] . ';range=' . $low . '-*'; $attrToRead = $result['attributeName'] . ';range=' . $low . '-*';
$isRangeRequest = true; $isRangeRequest = true;
} }
} }
} while ($isRangeRequest); } while ($isRangeRequest);
\OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, ILogger::DEBUG); \OCP\Util::writeLog('user_ldap', 'Requested attribute ' . $attr . ' not found for ' . $dn, ILogger::DEBUG);
return false; return false;
} }
@ -300,7 +307,7 @@ class Access extends LDAPUtility {
$values = []; $values = [];
if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) { if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
$lowercaseAttribute = strtolower($attribute); $lowercaseAttribute = strtolower($attribute);
for ($i=0;$i<$result[$attribute]['count'];$i++) { for ($i = 0; $i < $result[$attribute]['count']; $i++) {
if ($this->resemblesDN($attribute)) { if ($this->resemblesDN($attribute)) {
$values[] = $this->helper->sanitizeDN($result[$attribute][$i]); $values[] = $this->helper->sanitizeDN($result[$attribute][$i]);
} elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { } elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
@ -365,14 +372,15 @@ class Access extends LDAPUtility {
try { try {
// try PASSWD extended operation first // try PASSWD extended operation first
return @$this->invokeLDAPMethod('exopPasswd', $cr, $userDN, '', $password) || return @$this->invokeLDAPMethod('exopPasswd', $cr, $userDN, '', $password) ||
@$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password); @$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password);
} catch (ConstraintViolationException $e) { } catch (ConstraintViolationException $e) {
throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode()); throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ') . $e->getMessage(), $e->getCode());
} }
} }
/** /**
* checks whether the given attributes value is probably a DN * checks whether the given attributes value is probably a DN
*
* @param string $attr the attribute in question * @param string $attr the attribute in question
* @return boolean if so true, otherwise false * @return boolean if so true, otherwise false
*/ */
@ -389,6 +397,7 @@ class Access extends LDAPUtility {
/** /**
* checks whether the given string is probably a DN * checks whether the given string is probably a DN
*
* @param string $string * @param string $string
* @return boolean * @return boolean
*/ */
@ -403,6 +412,7 @@ class Access extends LDAPUtility {
* returns a DN-string that is cleaned from not domain parts, e.g. * returns a DN-string that is cleaned from not domain parts, e.g.
* cn=foo,cn=bar,dc=foobar,dc=server,dc=org * cn=foo,cn=bar,dc=foobar,dc=server,dc=org
* becomes dc=foobar,dc=server,dc=org * becomes dc=foobar,dc=server,dc=org
*
* @param string $dn * @param string $dn
* @return string * @return string
*/ */
@ -427,6 +437,7 @@ class Access extends LDAPUtility {
/** /**
* returns the LDAP DN for the given internal Nextcloud name of the group * returns the LDAP DN for the given internal Nextcloud name of the group
*
* @param string $name the Nextcloud name in question * @param string $name the Nextcloud name in question
* @return string|false LDAP DN on success, otherwise false * @return string|false LDAP DN on success, otherwise false
*/ */
@ -436,6 +447,7 @@ class Access extends LDAPUtility {
/** /**
* returns the LDAP DN for the given internal Nextcloud name of the user * returns the LDAP DN for the given internal Nextcloud name of the user
*
* @param string $name the Nextcloud name in question * @param string $name the Nextcloud name in question
* @return string|false with the LDAP DN on success, otherwise false * @return string|false with the LDAP DN on success, otherwise false
*/ */
@ -528,14 +540,14 @@ class Access extends LDAPUtility {
} }
} else { } else {
//If the UUID can't be detected something is foul. //If the UUID can't be detected something is foul.
\OCP\Util::writeLog('user_ldap', 'Cannot determine UUID for '.$fdn.'. Skipping.', ILogger::INFO); \OCP\Util::writeLog('user_ldap', 'Cannot determine UUID for ' . $fdn . '. Skipping.', ILogger::INFO);
return false; return false;
} }
if (is_null($ldapName)) { if (is_null($ldapName)) {
$ldapName = $this->readAttribute($fdn, $nameAttribute, $filter); $ldapName = $this->readAttribute($fdn, $nameAttribute, $filter);
if (!isset($ldapName[0]) && empty($ldapName[0])) { if (!isset($ldapName[0]) && empty($ldapName[0])) {
\OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.' with filter '.$filter.'.', ILogger::INFO); \OCP\Util::writeLog('user_ldap', 'No or empty name for ' . $fdn . ' with filter ' . $filter . '.', ILogger::INFO);
return false; return false;
} }
$ldapName = $ldapName[0]; $ldapName = $ldapName[0];
@ -594,7 +606,7 @@ class Access extends LDAPUtility {
} }
//if everything else did not help.. //if everything else did not help..
\OCP\Util::writeLog('user_ldap', 'Could not create unique name for '.$fdn.'.', ILogger::INFO); \OCP\Util::writeLog('user_ldap', 'Could not create unique name for ' . $fdn . '.', ILogger::INFO);
return false; return false;
} }
@ -604,7 +616,7 @@ class Access extends LDAPUtility {
string $name, string $name,
string $uuid, string $uuid,
bool $isUser bool $isUser
) :bool { ): bool {
if ($mapper->map($fdn, $name, $uuid)) { if ($mapper->map($fdn, $name, $uuid)) {
if ($this->ncUserManager instanceof PublicEmitter && $isUser) { if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
$this->cacheUserExists($name); $this->cacheUserExists($name);
@ -652,7 +664,7 @@ class Access extends LDAPUtility {
private function ldap2NextcloudNames($ldapObjects, $isUsers) { private function ldap2NextcloudNames($ldapObjects, $isUsers) {
if ($isUsers) { if ($isUsers) {
$nameAttribute = $this->connection->ldapUserDisplayName; $nameAttribute = $this->connection->ldapUserDisplayName;
$sndAttribute = $this->connection->ldapUserDisplayName2; $sndAttribute = $this->connection->ldapUserDisplayName2;
} else { } else {
$nameAttribute = $this->connection->ldapGroupDisplayName; $nameAttribute = $this->connection->ldapGroupDisplayName;
} }
@ -704,27 +716,29 @@ class Access extends LDAPUtility {
/** /**
* caches the user display name * caches the user display name
*
* @param string $ocName the internal Nextcloud username * @param string $ocName the internal Nextcloud username
* @param string|false $home the home directory path * @param string|false $home the home directory path
*/ */
public function cacheUserHome($ocName, $home) { public function cacheUserHome($ocName, $home) {
$cacheKey = 'getHome'.$ocName; $cacheKey = 'getHome' . $ocName;
$this->connection->writeToCache($cacheKey, $home); $this->connection->writeToCache($cacheKey, $home);
} }
/** /**
* caches a user as existing * caches a user as existing
*
* @param string $ocName the internal Nextcloud username * @param string $ocName the internal Nextcloud username
*/ */
public function cacheUserExists($ocName) { public function cacheUserExists($ocName) {
$this->connection->writeToCache('userExists'.$ocName, true); $this->connection->writeToCache('userExists' . $ocName, true);
} }
/** /**
* caches a group as existing * caches a group as existing
*/ */
public function cacheGroupExists(string $gid): void { public function cacheGroupExists(string $gid): void {
$this->connection->writeToCache('groupExists'.$gid, true); $this->connection->writeToCache('groupExists' . $gid, true);
} }
/** /**
@ -742,7 +756,7 @@ class Access extends LDAPUtility {
} }
$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2); $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
$cacheKeyTrunk = 'getDisplayName'; $cacheKeyTrunk = 'getDisplayName';
$this->connection->writeToCache($cacheKeyTrunk.$ocName, $displayName); $this->connection->writeToCache($cacheKeyTrunk . $ocName, $displayName);
} }
public function cacheGroupDisplayName(string $ncName, string $displayName): void { public function cacheGroupDisplayName(string $ncName, string $displayName): void {
@ -752,6 +766,7 @@ class Access extends LDAPUtility {
/** /**
* creates a unique name for internal Nextcloud use for users. Don't call it directly. * creates a unique name for internal Nextcloud use for users. Don't call it directly.
*
* @param string $name the display name of the object * @param string $name the display name of the object
* @return string|false with with the name to use in Nextcloud or false if unsuccessful * @return string|false with with the name to use in Nextcloud or false if unsuccessful
* *
@ -763,7 +778,7 @@ class Access extends LDAPUtility {
//while loop is just a precaution. If a name is not generated within //while loop is just a precaution. If a name is not generated within
//20 attempts, something else is very wrong. Avoids infinite loop. //20 attempts, something else is very wrong. Avoids infinite loop.
while ($attempts < 20) { while ($attempts < 20) {
$altName = $name . '_' . rand(1000,9999); $altName = $name . '_' . rand(1000, 9999);
if (!$this->ncUserManager->userExists($altName)) { if (!$this->ncUserManager->userExists($altName)) {
return $altName; return $altName;
} }
@ -774,6 +789,7 @@ class Access extends LDAPUtility {
/** /**
* creates a unique name for internal Nextcloud use for groups. Don't call it directly. * creates a unique name for internal Nextcloud use for groups. Don't call it directly.
*
* @param string $name the display name of the object * @param string $name the display name of the object
* @return string|false with with the name to use in Nextcloud or false if unsuccessful. * @return string|false with with the name to use in Nextcloud or false if unsuccessful.
* *
@ -793,7 +809,7 @@ class Access extends LDAPUtility {
$lastName = array_pop($usedNames); $lastName = array_pop($usedNames);
$lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1); $lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1);
} }
$altName = $name.'_'. (string)($lastNo+1); $altName = $name . '_' . (string)($lastNo + 1);
unset($usedNames); unset($usedNames);
$attempts = 1; $attempts = 1;
@ -812,6 +828,7 @@ class Access extends LDAPUtility {
/** /**
* creates a unique name for internal Nextcloud use. * creates a unique name for internal Nextcloud use.
*
* @param string $name the display name of the object * @param string $name the display name of the object
* @param boolean $isUser whether name should be created for a user (true) or a group (false) * @param boolean $isUser whether name should be created for a user (true) or a group (false)
* @return string|false with with the name to use in Nextcloud or false if unsuccessful * @return string|false with with the name to use in Nextcloud or false if unsuccessful
@ -876,10 +893,10 @@ class Access extends LDAPUtility {
return $listOfDNs; return $listOfDNs;
}, []); }, []);
$idsByDn = $this->userMapper->getListOfIdsByDn($listOfDNs); $idsByDn = $this->userMapper->getListOfIdsByDn($listOfDNs);
$recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax, $idsByDn) { $recordsToUpdate = array_filter($ldapRecords, function ($record) use ($isBackgroundJobModeAjax, $idsByDn) {
$newlyMapped = false; $newlyMapped = false;
$uid = $idsByDn[$record['dn'][0]] ?? null; $uid = $idsByDn[$record['dn'][0]] ?? null;
if($uid === null) { if ($uid === null) {
$uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record); $uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record);
} }
if (is_string($uid)) { if (is_string($uid)) {
@ -907,7 +924,7 @@ class Access extends LDAPUtility {
// displayName is obligatory // displayName is obligatory
continue; continue;
} }
$ocName = $this->dn2ocname($userRecord['dn'][0], null, true); $ocName = $this->dn2ocname($userRecord['dn'][0], null, true);
if ($ocName === false) { if ($ocName === false) {
continue; continue;
} }
@ -918,7 +935,7 @@ class Access extends LDAPUtility {
} else { } else {
\OC::$server->getLogger()->debug( \OC::$server->getLogger()->debug(
"The ldap user manager returned null for $ocName", "The ldap user manager returned null for $ocName",
['app'=>'user_ldap'] ['app' => 'user_ldap']
); );
} }
} }
@ -936,14 +953,14 @@ class Access extends LDAPUtility {
$listOfDNs = array_reduce($groupRecords, function ($listOfDNs, $entry) { $listOfDNs = array_reduce($groupRecords, function ($listOfDNs, $entry) {
$listOfDNs[] = $entry['dn'][0]; $listOfDNs[] = $entry['dn'][0];
return$listOfDNs; return $listOfDNs;
}, []); }, []);
$idsByDn = $this->groupMapper->getListOfIdsByDn($listOfDNs); $idsByDn = $this->groupMapper->getListOfIdsByDn($listOfDNs);
array_walk($groupRecords, function($record) use ($idsByDn) { array_walk($groupRecords, function ($record) use ($idsByDn) {
$newlyMapped = false; $newlyMapped = false;
$gid = $uidsByDn[$record['dn'][0]] ?? null; $gid = $uidsByDn[$record['dn'][0]] ?? null;
if($gid === null) { if ($gid === null) {
$gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record); $gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record);
} }
if (!$newlyMapped && is_string($gid)) { if (!$newlyMapped && is_string($gid)) {
@ -1071,6 +1088,7 @@ class Access extends LDAPUtility {
/** /**
* Returns the LDAP handler * Returns the LDAP handler
*
* @throws \OC\ServerNotAvailableException * @throws \OC\ServerNotAvailableException
*/ */
@ -1154,7 +1172,7 @@ class Access extends LDAPUtility {
// cannot use $cr anymore, might have changed in the previous call! // cannot use $cr anymore, might have changed in the previous call!
$error = $this->ldap->errno($this->connection->getConnectionResource()); $error = $this->ldap->errno($this->connection->getConnectionResource());
if (!$this->ldap->isResource($sr) || $error !== 0) { if (!$this->ldap->isResource($sr) || $error !== 0) {
\OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), ILogger::ERROR); \OCP\Util::writeLog('user_ldap', 'Attempt for Paging? ' . print_r($pagedSearchOK, true), ILogger::ERROR);
return false; return false;
} }
@ -1201,7 +1219,7 @@ class Access extends LDAPUtility {
if (!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) { if (!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) {
\OC::$server->getLogger()->debug( \OC::$server->getLogger()->debug(
'Paged search was not available', 'Paged search was not available',
[ 'app' => 'user_ldap' ] ['app' => 'user_ldap']
); );
} }
} }
@ -1388,7 +1406,7 @@ class Access extends LDAPUtility {
//a) paged search unsuccessful, though attempted //a) paged search unsuccessful, though attempted
//b) no paged search, but limit set //b) no paged search, but limit set
if ((!$this->getPagedSearchResultState() if ((!$this->getPagedSearchResultState()
&& $pagedSearchOK) && $pagedSearchOK)
|| ( || (
!$pagedSearchOK !$pagedSearchOK
&& !is_null($limit) && !is_null($limit)
@ -1433,7 +1451,8 @@ class Access extends LDAPUtility {
/** /**
* escapes (user provided) parts for LDAP filter * escapes (user provided) parts for LDAP filter
* @param string $input, the provided value *
* @param string $input , the provided value
* @param bool $allowAsterisk whether in * at the beginning should be preserved * @param bool $allowAsterisk whether in * at the beginning should be preserved
* @return string the escaped string * @return string the escaped string
*/ */
@ -1443,13 +1462,14 @@ class Access extends LDAPUtility {
$asterisk = '*'; $asterisk = '*';
$input = mb_substr($input, 1, null, 'UTF-8'); $input = mb_substr($input, 1, null, 'UTF-8');
} }
$search = ['*', '\\', '(', ')']; $search = ['*', '\\', '(', ')'];
$replace = ['\\*', '\\\\', '\\(', '\\)']; $replace = ['\\*', '\\\\', '\\(', '\\)'];
return $asterisk . str_replace($search, $replace, $input); return $asterisk . str_replace($search, $replace, $input);
} }
/** /**
* combines the input filters with AND * combines the input filters with AND
*
* @param string[] $filters the filters to connect * @param string[] $filters the filters to connect
* @return string the combined filter * @return string the combined filter
*/ */
@ -1459,6 +1479,7 @@ class Access extends LDAPUtility {
/** /**
* combines the input filters with OR * combines the input filters with OR
*
* @param string[] $filters the filters to connect * @param string[] $filters the filters to connect
* @return string the combined filter * @return string the combined filter
* Combines Filter arguments with OR * Combines Filter arguments with OR
@ -1469,24 +1490,26 @@ class Access extends LDAPUtility {
/** /**
* combines the input filters with given operator * combines the input filters with given operator
*
* @param string[] $filters the filters to connect * @param string[] $filters the filters to connect
* @param string $operator either & or | * @param string $operator either & or |
* @return string the combined filter * @return string the combined filter
*/ */
private function combineFilter($filters, $operator) { private function combineFilter($filters, $operator) {
$combinedFilter = '('.$operator; $combinedFilter = '(' . $operator;
foreach ($filters as $filter) { foreach ($filters as $filter) {
if ($filter !== '' && $filter[0] !== '(') { if ($filter !== '' && $filter[0] !== '(') {
$filter = '('.$filter.')'; $filter = '(' . $filter . ')';
} }
$combinedFilter.=$filter; $combinedFilter .= $filter;
} }
$combinedFilter.=')'; $combinedFilter .= ')';
return $combinedFilter; return $combinedFilter;
} }
/** /**
* creates a filter part for to perform search for users * creates a filter part for to perform search for users
*
* @param string $search the search term * @param string $search the search term
* @return string the final filter part to use in LDAP searches * @return string the final filter part to use in LDAP searches
*/ */
@ -1498,6 +1521,7 @@ class Access extends LDAPUtility {
/** /**
* creates a filter part for to perform search for groups * creates a filter part for to perform search for groups
*
* @param string $search the search term * @param string $search the search term
* @return string the final filter part to use in LDAP searches * @return string the final filter part to use in LDAP searches
*/ */
@ -1510,6 +1534,7 @@ class Access extends LDAPUtility {
/** /**
* creates a filter part for searches by splitting up the given search * creates a filter part for searches by splitting up the given search
* string into single words * string into single words
*
* @param string $search the search term * @param string $search the search term
* @param string[] $searchAttributes needs to have at least two attributes, * @param string[] $searchAttributes needs to have at least two attributes,
* otherwise it does not make sense :) * otherwise it does not make sense :)
@ -1536,6 +1561,7 @@ class Access extends LDAPUtility {
/** /**
* creates a filter part for searches * creates a filter part for searches
*
* @param string $search the search term * @param string $search the search term
* @param string[]|null $searchAttributes * @param string[]|null $searchAttributes
* @param string $fallbackAttribute a fallback attribute in case the user * @param string $fallbackAttribute a fallback attribute in case the user
@ -1569,7 +1595,7 @@ class Access extends LDAPUtility {
} }
} }
if (count($filter) === 1) { if (count($filter) === 1) {
return '('.$filter[0].')'; return '(' . $filter[0] . ')';
} }
return $this->combineFilterWithOr($filter); return $this->combineFilterWithOr($filter);
} }
@ -1578,6 +1604,7 @@ class Access extends LDAPUtility {
* returns the search term depending on whether we are allowed * returns the search term depending on whether we are allowed
* list users found by ldap with the current input appended by * list users found by ldap with the current input appended by
* a * * a *
*
* @return string * @return string
*/ */
private function prepareSearchTerm($term) { private function prepareSearchTerm($term) {
@ -1596,6 +1623,7 @@ class Access extends LDAPUtility {
/** /**
* returns the filter used for counting users * returns the filter used for counting users
*
* @return string * @return string
*/ */
public function getFilterForUserCount() { public function getFilterForUserCount() {
@ -1634,8 +1662,8 @@ class Access extends LDAPUtility {
*/ */
public function getUserDnByUuid($uuid) { public function getUserDnByUuid($uuid) {
$uuidOverride = $this->connection->ldapExpertUUIDUserAttr; $uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
$filter = $this->connection->ldapUserFilter; $filter = $this->connection->ldapUserFilter;
$bases = $this->connection->ldapBaseUsers; $bases = $this->connection->ldapBaseUsers;
if ($this->connection->ldapUuidUserAttribute === 'auto' && $uuidOverride === '') { if ($this->connection->ldapUuidUserAttribute === 'auto' && $uuidOverride === '') {
// Sacrebleu! The UUID attribute is unknown :( We need first an // Sacrebleu! The UUID attribute is unknown :( We need first an
@ -1690,10 +1718,10 @@ class Access extends LDAPUtility {
*/ */
private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) { private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) {
if ($isUser) { if ($isUser) {
$uuidAttr = 'ldapUuidUserAttribute'; $uuidAttr = 'ldapUuidUserAttribute';
$uuidOverride = $this->connection->ldapExpertUUIDUserAttr; $uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
} else { } else {
$uuidAttr = 'ldapUuidGroupAttribute'; $uuidAttr = 'ldapUuidGroupAttribute';
$uuidOverride = $this->connection->ldapExpertUUIDGroupAttr; $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
} }
@ -1750,10 +1778,10 @@ class Access extends LDAPUtility {
*/ */
public function getUUID($dn, $isUser = true, $ldapRecord = null) { public function getUUID($dn, $isUser = true, $ldapRecord = null) {
if ($isUser) { if ($isUser) {
$uuidAttr = 'ldapUuidUserAttribute'; $uuidAttr = 'ldapUuidUserAttribute';
$uuidOverride = $this->connection->ldapExpertUUIDUserAttr; $uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
} else { } else {
$uuidAttr = 'ldapUuidGroupAttribute'; $uuidAttr = 'ldapUuidGroupAttribute';
$uuidOverride = $this->connection->ldapExpertUUIDGroupAttr; $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
} }
@ -1778,6 +1806,7 @@ class Access extends LDAPUtility {
/** /**
* converts a binary ObjectGUID into a string representation * converts a binary ObjectGUID into a string representation
*
* @param string $oguid the ObjectGUID in it's binary form as retrieved from AD * @param string $oguid the ObjectGUID in it's binary form as retrieved from AD
* @return string * @return string
* @link http://www.php.net/manual/en/function.ldap-get-values-len.php#73198 * @link http://www.php.net/manual/en/function.ldap-get-values-len.php#73198
@ -1833,16 +1862,16 @@ class Access extends LDAPUtility {
\OC::$server->getLogger()->info( \OC::$server->getLogger()->info(
'Passed string does not resemble a valid GUID. Known UUID ' . 'Passed string does not resemble a valid GUID. Known UUID ' .
'({uuid}) probably does not match UUID configuration.', '({uuid}) probably does not match UUID configuration.',
[ 'app' => 'user_ldap', 'uuid' => $guid ] ['app' => 'user_ldap', 'uuid' => $guid]
); );
return $guid; return $guid;
} }
for ($i=0; $i < 3; $i++) { for ($i = 0; $i < 3; $i++) {
$pairs = str_split($blocks[$i], 2); $pairs = str_split($blocks[$i], 2);
$pairs = array_reverse($pairs); $pairs = array_reverse($pairs);
$blocks[$i] = implode('', $pairs); $blocks[$i] = implode('', $pairs);
} }
for ($i=0; $i < 5; $i++) { for ($i = 0; $i < 5; $i++) {
$pairs = str_split($blocks[$i], 2); $pairs = str_split($blocks[$i], 2);
$blocks[$i] = '\\' . implode('\\', $pairs); $blocks[$i] = '\\' . implode('\\', $pairs);
} }
@ -1858,7 +1887,7 @@ class Access extends LDAPUtility {
*/ */
public function getSID($dn) { public function getSID($dn) {
$domainDN = $this->getDomainDNFromDN($dn); $domainDN = $this->getDomainDNFromDN($dn);
$cacheKey = 'getSID-'.$domainDN; $cacheKey = 'getSID-' . $domainDN;
$sid = $this->connection->getFromCache($cacheKey); $sid = $this->connection->getFromCache($cacheKey);
if (!is_null($sid)) { if (!is_null($sid)) {
return $sid; return $sid;
@ -1877,6 +1906,7 @@ class Access extends LDAPUtility {
/** /**
* converts a binary SID into a string representation * converts a binary SID into a string representation
*
* @param string $sid * @param string $sid
* @return string * @return string
*/ */
@ -1915,6 +1945,7 @@ class Access extends LDAPUtility {
/** /**
* checks if the given DN is part of the given base DN(s) * checks if the given DN is part of the given base DN(s)
*
* @param string $dn the DN * @param string $dn the DN
* @param string[] $bases array containing the allowed base DN or DNs * @param string[] $bases array containing the allowed base DN or DNs
* @return bool * @return bool
@ -1925,7 +1956,7 @@ class Access extends LDAPUtility {
foreach ($bases as $base) { foreach ($bases as $base) {
$belongsToBase = true; $belongsToBase = true;
if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) { if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) {
$belongsToBase = false; $belongsToBase = false;
} }
if ($belongsToBase) { if ($belongsToBase) {
@ -1958,6 +1989,7 @@ class Access extends LDAPUtility {
* be reset by other operations. Best, call it immediately after a search(), * be reset by other operations. Best, call it immediately after a search(),
* searchUsers() or searchGroups() call. count-methods are probably safe as * searchUsers() or searchGroups() call. count-methods are probably safe as
* well. Don't rely on it with any fetchList-method. * well. Don't rely on it with any fetchList-method.
*
* @return bool * @return bool
*/ */
public function hasMoreResults() { public function hasMoreResults() {
@ -1972,6 +2004,7 @@ class Access extends LDAPUtility {
/** /**
* Check whether the most recent paged search was successful. It flushed the state var. Use it always after a possible paged search. * Check whether the most recent paged search was successful. It flushed the state var. Use it always after a possible paged search.
*
* @return boolean|null true on success, null or false otherwise * @return boolean|null true on success, null or false otherwise
*/ */
public function getPagedSearchResultState() { public function getPagedSearchResultState() {
@ -2024,10 +2057,10 @@ class Access extends LDAPUtility {
$this->abandonPagedSearch(); $this->abandonPagedSearch();
} }
$pagedSearchOK = true === $this->invokeLDAPMethod( $pagedSearchOK = true === $this->invokeLDAPMethod(
'controlPagedResult', $this->connection->getConnectionResource(), $limit, false 'controlPagedResult', $this->connection->getConnectionResource(), $limit, false
); );
if ($pagedSearchOK) { if ($pagedSearchOK) {
\OC::$server->getLogger()->debug('Ready for a paged search',['app' => 'user_ldap']); \OC::$server->getLogger()->debug('Ready for a paged search', ['app' => 'user_ldap']);
} }
/* ++ Fixing RHDS searches with pages with zero results ++ /* ++ Fixing RHDS searches with pages with zero results ++
* We coudn't get paged searches working with our RHDS for login ($limit = 0), * We coudn't get paged searches working with our RHDS for login ($limit = 0),

View File

@ -85,6 +85,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* is user in group? * is user in group?
*
* @param string $uid uid of the user * @param string $uid uid of the user
* @param string $gid gid of the group * @param string $gid gid of the group
* @return bool * @return bool
@ -95,7 +96,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
if (!$this->enabled) { if (!$this->enabled) {
return false; return false;
} }
$cacheKey = 'inGroup'.$uid.':'.$gid; $cacheKey = 'inGroup' . $uid . ':' . $gid;
$inGroup = $this->access->connection->getFromCache($cacheKey); $inGroup = $this->access->connection->getFromCache($cacheKey);
if (!is_null($inGroup)) { if (!is_null($inGroup)) {
return (bool)$inGroup; return (bool)$inGroup;
@ -108,7 +109,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
return $isInGroup; return $isInGroup;
} }
$cacheKeyMembers = 'inGroup-members:'.$gid; $cacheKeyMembers = 'inGroup-members:' . $gid;
$members = $this->access->connection->getFromCache($cacheKeyMembers); $members = $this->access->connection->getFromCache($cacheKeyMembers);
if (!is_null($members)) { if (!is_null($members)) {
$this->cachedGroupMembers[$gid] = $members; $this->cachedGroupMembers[$gid] = $members;
@ -199,13 +200,13 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
$pos = strpos($memberURLs[0], '('); $pos = strpos($memberURLs[0], '(');
if ($pos !== false) { if ($pos !== false) {
$memberUrlFilter = substr($memberURLs[0], $pos); $memberUrlFilter = substr($memberURLs[0], $pos);
$foundMembers = $this->access->searchUsers($memberUrlFilter,'dn'); $foundMembers = $this->access->searchUsers($memberUrlFilter, 'dn');
$dynamicMembers = []; $dynamicMembers = [];
foreach ($foundMembers as $value) { foreach ($foundMembers as $value) {
$dynamicMembers[$value['dn'][0]] = 1; $dynamicMembers[$value['dn'][0]] = 1;
} }
} else { } else {
\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. \OCP\Util::writeLog('user_ldap', 'No search filter found on member url ' .
'of group ' . $dnGroup, ILogger::DEBUG); 'of group ' . $dnGroup, ILogger::DEBUG);
} }
} }
@ -228,7 +229,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
return []; return [];
} }
// used extensively in cron job, caching makes sense for nested groups // used extensively in cron job, caching makes sense for nested groups
$cacheKey = '_groupMembers'.$dnGroup; $cacheKey = '_groupMembers' . $dnGroup;
$groupMembers = $this->access->connection->getFromCache($cacheKey); $groupMembers = $this->access->connection->getFromCache($cacheKey);
if ($groupMembers !== null) { if ($groupMembers !== null) {
return $groupMembers; return $groupMembers;
@ -284,7 +285,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
* @return array * @return array
*/ */
private function walkNestedGroups(string $dn, \Closure $fetcher, array $list): array { private function walkNestedGroups(string $dn, \Closure $fetcher, array $list): array {
$nesting = (int) $this->access->connection->ldapNestedGroups; $nesting = (int)$this->access->connection->ldapNestedGroups;
// depending on the input, we either have a list of DNs or a list of LDAP records // depending on the input, we either have a list of DNs or a list of LDAP records
// also, the output expects either DNs or records. Testing the first element should suffice. // also, the output expects either DNs or records. Testing the first element should suffice.
$recordMode = is_array($list) && isset($list[0]) && is_array($list[0]) && isset($list[0]['dn'][0]); $recordMode = is_array($list) && isset($list[0]) && is_array($list[0]) && isset($list[0]['dn'][0]);
@ -319,6 +320,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* translates a gidNumber into an ownCloud internal name * translates a gidNumber into an ownCloud internal name
*
* @param string $gid as given by gidNumber on POSIX LDAP * @param string $gid as given by gidNumber on POSIX LDAP
* @param string $dn a DN that belongs to the same domain as the group * @param string $dn a DN that belongs to the same domain as the group
* @return string|bool * @return string|bool
@ -354,6 +356,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* returns the entry's gidNumber * returns the entry's gidNumber
*
* @param string $dn * @param string $dn
* @param string $attribute * @param string $attribute
* @return string|bool * @return string|bool
@ -368,6 +371,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* returns the group's primary ID * returns the group's primary ID
*
* @param string $dn * @param string $dn
* @return string|bool * @return string|bool
*/ */
@ -377,6 +381,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* returns the user's gidNumber * returns the user's gidNumber
*
* @param string $dn * @param string $dn
* @return string|bool * @return string|bool
*/ */
@ -410,7 +415,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
if ($search !== '') { if ($search !== '') {
$filterParts[] = $this->access->getFilterPartForUserSearch($search); $filterParts[] = $this->access->getFilterPartForUserSearch($search);
} }
$filterParts[] = $this->access->connection->ldapGidNumber .'=' . $groupID; $filterParts[] = $this->access->connection->ldapGidNumber . '=' . $groupID;
return $this->access->combineFilterWithAnd($filterParts); return $this->access->combineFilterWithAnd($filterParts);
} }
@ -460,6 +465,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* gets the gidNumber of a user * gets the gidNumber of a user
*
* @param string $dn * @param string $dn
* @return string * @return string
*/ */
@ -477,6 +483,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* translates a primary group ID into an Nextcloud internal name * translates a primary group ID into an Nextcloud internal name
*
* @param string $gid as given by primaryGroupID on AD * @param string $gid as given by primaryGroupID on AD
* @param string $dn a DN that belongs to the same domain as the group * @param string $dn a DN that belongs to the same domain as the group
* @return string|bool * @return string|bool
@ -516,6 +523,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* returns the entry's primary group ID * returns the entry's primary group ID
*
* @param string $dn * @param string $dn
* @param string $attribute * @param string $attribute
* @return string|bool * @return string|bool
@ -530,6 +538,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* returns the group's primary ID * returns the group's primary ID
*
* @param string $dn * @param string $dn
* @return string|bool * @return string|bool
*/ */
@ -539,6 +548,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* returns the user's primary group ID * returns the user's primary group ID
*
* @param string $dn * @param string $dn
* @return string|bool * @return string|bool
*/ */
@ -622,6 +632,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* gets the primary group of a user * gets the primary group of a user
*
* @param string $dn * @param string $dn
* @return string * @return string
*/ */
@ -639,6 +650,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* Get all groups a user belongs to * Get all groups a user belongs to
*
* @param string $uid Name of the user * @param string $uid Name of the user
* @return array with group names * @return array with group names
* *
@ -651,7 +663,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
if (!$this->enabled) { if (!$this->enabled) {
return []; return [];
} }
$cacheKey = 'getUserGroups'.$uid; $cacheKey = 'getUserGroups' . $uid;
$userGroups = $this->access->connection->getFromCache($cacheKey); $userGroups = $this->access->connection->getFromCache($cacheKey);
if (!is_null($userGroups)) { if (!is_null($userGroups)) {
return $userGroups; return $userGroups;
@ -671,14 +683,14 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
if (!empty($dynamicGroupMemberURL)) { if (!empty($dynamicGroupMemberURL)) {
// look through dynamic groups to add them to the result array if needed // look through dynamic groups to add them to the result array if needed
$groupsToMatch = $this->access->fetchListOfGroups( $groupsToMatch = $this->access->fetchListOfGroups(
$this->access->connection->ldapGroupFilter,['dn',$dynamicGroupMemberURL]); $this->access->connection->ldapGroupFilter, ['dn', $dynamicGroupMemberURL]);
foreach ($groupsToMatch as $dynamicGroup) { foreach ($groupsToMatch as $dynamicGroup) {
if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) { if (!array_key_exists($dynamicGroupMemberURL, $dynamicGroup)) {
continue; continue;
} }
$pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '('); $pos = strpos($dynamicGroup[$dynamicGroupMemberURL][0], '(');
if ($pos !== false) { if ($pos !== false) {
$memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0],$pos); $memberUrlFilter = substr($dynamicGroup[$dynamicGroupMemberURL][0], $pos);
// apply filter via ldap search to see if this user is in this // apply filter via ldap search to see if this user is in this
// dynamic group // dynamic group
$userMatch = $this->access->readAttribute( $userMatch = $this->access->readAttribute(
@ -696,7 +708,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
} }
} }
} else { } else {
\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. \OCP\Util::writeLog('user_ldap', 'No search filter found on member url ' .
'of group ' . print_r($dynamicGroup, true), ILogger::DEBUG); 'of group ' . print_r($dynamicGroup, true), ILogger::DEBUG);
} }
} }
@ -708,7 +720,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
if ((int)$this->access->connection->hasMemberOfFilterSupport === 1 if ((int)$this->access->connection->hasMemberOfFilterSupport === 1
&& (int)$this->access->connection->useMemberOfToDetectMembership === 1 && (int)$this->access->connection->useMemberOfToDetectMembership === 1
&& strtolower($this->access->connection->ldapGroupMemberAssocAttr) !== 'memberuid' && strtolower($this->access->connection->ldapGroupMemberAssocAttr) !== 'memberuid'
) { ) {
$groupDNs = $this->_getGroupDNsFromMemberOf($userDN); $groupDNs = $this->_getGroupDNsFromMemberOf($userDN);
if (is_array($groupDNs)) { if (is_array($groupDNs)) {
foreach ($groupDNs as $dn) { foreach ($groupDNs as $dn) {
@ -739,7 +751,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
} elseif (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') { } elseif (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid') {
$result = $this->access->readAttribute($userDN, 'uid'); $result = $this->access->readAttribute($userDN, 'uid');
if ($result === false) { if ($result === false) {
\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '. \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on ' .
$this->access->connection->ldapHost, ILogger::DEBUG); $this->access->connection->ldapHost, ILogger::DEBUG);
$uid = false; $uid = false;
} else { } else {
@ -789,7 +801,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
} }
$allGroups = []; $allGroups = [];
$seen[$dn] = true; $seen[$dn] = true;
$filter = $this->access->connection->ldapGroupMemberAssocAttr.'='.$dn; $filter = $this->access->connection->ldapGroupMemberAssocAttr . '=' . $dn;
$groups = $this->access->fetchListOfGroups($filter, $groups = $this->access->fetchListOfGroups($filter,
[strtolower($this->access->connection->ldapGroupMemberAssocAttr), $this->access->connection->ldapGroupDisplayName, 'dn']); [strtolower($this->access->connection->ldapGroupMemberAssocAttr), $this->access->connection->ldapGroupDisplayName, 'dn']);
if (is_array($groups)) { if (is_array($groups)) {
@ -823,7 +835,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
return []; return [];
} }
$search = $this->access->escapeFilterPart($search, true); $search = $this->access->escapeFilterPart($search, true);
$cacheKey = 'usersInGroup-'.$gid.'-'.$search.'-'.$limit.'-'.$offset; $cacheKey = 'usersInGroup-' . $gid . '-' . $search . '-' . $limit . '-' . $offset;
// check for cache of the exact query // check for cache of the exact query
$groupUsers = $this->access->connection->getFromCache($cacheKey); $groupUsers = $this->access->connection->getFromCache($cacheKey);
if (!is_null($groupUsers)) { if (!is_null($groupUsers)) {
@ -831,7 +843,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
} }
// check for cache of the query without limit and offset // check for cache of the query without limit and offset
$groupUsers = $this->access->connection->getFromCache('usersInGroup-'.$gid.'-'.$search); $groupUsers = $this->access->connection->getFromCache('usersInGroup-' . $gid . '-' . $search);
if (!is_null($groupUsers)) { if (!is_null($groupUsers)) {
$groupUsers = array_slice($groupUsers, $offset, $limit); $groupUsers = array_slice($groupUsers, $offset, $limit);
$this->access->connection->writeToCache($cacheKey, $groupUsers); $this->access->connection->writeToCache($cacheKey, $groupUsers);
@ -907,7 +919,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
$groupUsers = array_unique(array_merge($groupUsers, $primaryUsers, $posixGroupUsers)); $groupUsers = array_unique(array_merge($groupUsers, $primaryUsers, $posixGroupUsers));
natsort($groupUsers); natsort($groupUsers);
$this->access->connection->writeToCache('usersInGroup-'.$gid.'-'.$search, $groupUsers); $this->access->connection->writeToCache('usersInGroup-' . $gid . '-' . $search, $groupUsers);
$groupUsers = array_slice($groupUsers, $offset, $limit); $groupUsers = array_slice($groupUsers, $offset, $limit);
$this->access->connection->writeToCache($cacheKey, $groupUsers); $this->access->connection->writeToCache($cacheKey, $groupUsers);
@ -917,6 +929,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* returns the number of users in a group, who match the search term * returns the number of users in a group, who match the search term
*
* @param string $gid the internal group name * @param string $gid the internal group name
* @param string $search optional, a search string * @param string $search optional, a search string
* @return int|bool * @return int|bool
@ -926,7 +939,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
return $this->groupPluginManager->countUsersInGroup($gid, $search); return $this->groupPluginManager->countUsersInGroup($gid, $search);
} }
$cacheKey = 'countUsersInGroup-'.$gid.'-'.$search; $cacheKey = 'countUsersInGroup-' . $gid . '-' . $search;
if (!$this->enabled || !$this->groupExists($gid)) { if (!$this->enabled || !$this->groupExists($gid)) {
return false; return false;
} }
@ -958,7 +971,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
$search = $this->access->escapeFilterPart($search, true); $search = $this->access->escapeFilterPart($search, true);
$isMemberUid = $isMemberUid =
(strtolower($this->access->connection->ldapGroupMemberAssocAttr) (strtolower($this->access->connection->ldapGroupMemberAssocAttr)
=== 'memberuid'); === 'memberuid');
//we need to apply the search filter //we need to apply the search filter
//alternatives that need to be checked: //alternatives that need to be checked:
@ -1015,10 +1028,10 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
if (!$this->enabled) { if (!$this->enabled) {
return []; return [];
} }
$cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset; $cacheKey = 'getGroups-' . $search . '-' . $limit . '-' . $offset;
//Check cache before driving unnecessary searches //Check cache before driving unnecessary searches
\OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, ILogger::DEBUG); \OCP\Util::writeLog('user_ldap', 'getGroups ' . $cacheKey, ILogger::DEBUG);
$ldap_groups = $this->access->connection->getFromCache($cacheKey); $ldap_groups = $this->access->connection->getFromCache($cacheKey);
if (!is_null($ldap_groups)) { if (!is_null($ldap_groups)) {
return $ldap_groups; return $ldap_groups;
@ -1033,11 +1046,11 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
$this->access->connection->ldapGroupFilter, $this->access->connection->ldapGroupFilter,
$this->access->getFilterPartForGroupSearch($search) $this->access->getFilterPartForGroupSearch($search)
]); ]);
\OCP\Util::writeLog('user_ldap', 'getGroups Filter '.$filter, ILogger::DEBUG); \OCP\Util::writeLog('user_ldap', 'getGroups Filter ' . $filter, ILogger::DEBUG);
$ldap_groups = $this->access->fetchListOfGroups($filter, $ldap_groups = $this->access->fetchListOfGroups($filter,
[$this->access->connection->ldapGroupDisplayName, 'dn'], [$this->access->connection->ldapGroupDisplayName, 'dn'],
$limit, $limit,
$offset); $offset);
$ldap_groups = $this->access->nextcloudGroupNames($ldap_groups); $ldap_groups = $this->access->nextcloudGroupNames($ldap_groups);
$this->access->connection->writeToCache($cacheKey, $ldap_groups); $this->access->connection->writeToCache($cacheKey, $ldap_groups);
@ -1078,7 +1091,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
$chunkLimit = min($pagingSize, $overallLimit - $chunkOffset); $chunkLimit = min($pagingSize, $overallLimit - $chunkOffset);
$ldapGroups = $this->getGroupsChunk($search, $chunkLimit, $chunkOffset); $ldapGroups = $this->getGroupsChunk($search, $chunkLimit, $chunkOffset);
$nread = count($ldapGroups); $nread = count($ldapGroups);
\OCP\Util::writeLog('user_ldap', 'getGroups('.$search.'): read '.$nread.' at offset '.$chunkOffset.' (limit: '.$chunkLimit.')', ILogger::DEBUG); \OCP\Util::writeLog('user_ldap', 'getGroups(' . $search . '): read ' . $nread . ' at offset ' . $chunkOffset . ' (limit: ' . $chunkLimit . ')', ILogger::DEBUG);
if ($nread) { if ($nread) {
$allGroups = array_merge($allGroups, $ldapGroups); $allGroups = array_merge($allGroups, $ldapGroups);
$chunkOffset += $nread; $chunkOffset += $nread;
@ -1100,11 +1113,12 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* check if a group exists * check if a group exists
*
* @param string $gid * @param string $gid
* @return bool * @return bool
*/ */
public function groupExists($gid) { public function groupExists($gid) {
$groupExists = $this->access->connection->getFromCache('groupExists'.$gid); $groupExists = $this->access->connection->getFromCache('groupExists' . $gid);
if (!is_null($groupExists)) { if (!is_null($groupExists)) {
return (bool)$groupExists; return (bool)$groupExists;
} }
@ -1113,34 +1127,34 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
//only, requires more checking. //only, requires more checking.
$dn = $this->access->groupname2dn($gid); $dn = $this->access->groupname2dn($gid);
if (!$dn) { if (!$dn) {
$this->access->connection->writeToCache('groupExists'.$gid, false); $this->access->connection->writeToCache('groupExists' . $gid, false);
return false; return false;
} }
if(!$this->access->isDNPartOfBase($dn, $this->access->connection->ldapBaseGroups)) { if (!$this->access->isDNPartOfBase($dn, $this->access->connection->ldapBaseGroups)) {
$this->access->connection->writeToCache('groupExists'.$gid, false); $this->access->connection->writeToCache('groupExists' . $gid, false);
return false; return false;
} }
//if group really still exists, we will be able to read its objectclass //if group really still exists, we will be able to read its objectclass
if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapGroupFilter))) { if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapGroupFilter))) {
$this->access->connection->writeToCache('groupExists'.$gid, false); $this->access->connection->writeToCache('groupExists' . $gid, false);
return false; return false;
} }
$this->access->connection->writeToCache('groupExists'.$gid, true); $this->access->connection->writeToCache('groupExists' . $gid, true);
return true; return true;
} }
protected function filterValidGroups (array $listOfGroups): array { protected function filterValidGroups(array $listOfGroups): array {
$validGroupDNs = []; $validGroupDNs = [];
foreach($listOfGroups as $key => $item) { foreach ($listOfGroups as $key => $item) {
$dn = is_string($item) ? $item : $item['dn'][0]; $dn = is_string($item) ? $item : $item['dn'][0];
$gid = $this->access->dn2groupname($dn); $gid = $this->access->dn2groupname($dn);
if(!$gid) { if (!$gid) {
continue; continue;
} }
if($this->groupExists($gid)) { if ($this->groupExists($gid)) {
$validGroupDNs[$key] = $item; $validGroupDNs[$key] = $item;
} }
} }
@ -1149,6 +1163,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* Check if backend implements actions * Check if backend implements actions
*
* @param int $actions bitwise-or'ed actions * @param int $actions bitwise-or'ed actions
* @return boolean * @return boolean
* *
@ -1162,6 +1177,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* Return access for LDAP interaction. * Return access for LDAP interaction.
*
* @return Access instance of Access for LDAP interaction * @return Access instance of Access for LDAP interaction
*/ */
public function getLDAPAccess($gid) { public function getLDAPAccess($gid) {
@ -1170,6 +1186,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* create a group * create a group
*
* @param string $gid * @param string $gid
* @return bool * @return bool
* @throws \Exception * @throws \Exception
@ -1197,6 +1214,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* delete a group * delete a group
*
* @param string $gid gid of the group to delete * @param string $gid gid of the group to delete
* @return bool * @return bool
* @throws \Exception * @throws \Exception
@ -1206,7 +1224,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
if ($ret = $this->groupPluginManager->deleteGroup($gid)) { if ($ret = $this->groupPluginManager->deleteGroup($gid)) {
#delete group in nextcloud internal db #delete group in nextcloud internal db
$this->access->getGroupMapper()->unmap($gid); $this->access->getGroupMapper()->unmap($gid);
$this->access->connection->writeToCache("groupExists".$gid, false); $this->access->connection->writeToCache("groupExists" . $gid, false);
} }
return $ret; return $ret;
} }
@ -1215,6 +1233,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* Add a user to a group * Add a user to a group
*
* @param string $uid Name of the user to add to group * @param string $uid Name of the user to add to group
* @param string $gid Name of the group in which add the user * @param string $gid Name of the group in which add the user
* @return bool * @return bool
@ -1233,6 +1252,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* Removes a user from a group * Removes a user from a group
*
* @param string $uid Name of the user to remove from group * @param string $uid Name of the user to remove from group
* @param string $gid Name of the group from which remove the user * @param string $gid Name of the group from which remove the user
* @return bool * @return bool
@ -1251,6 +1271,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
/** /**
* Gets group details * Gets group details
*
* @param string $gid Name of the group * @param string $gid Name of the group
* @return array | false * @return array | false
* @throws \Exception * @throws \Exception
@ -1266,6 +1287,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
* Return LDAP connection resource from a cloned connection. * Return LDAP connection resource from a cloned connection.
* The cloned connection needs to be closed manually. * The cloned connection needs to be closed manually.
* of the current access. * of the current access.
*
* @param string $gid * @param string $gid
* @return resource of the LDAP connection * @return resource of the LDAP connection
*/ */

View File

@ -36,6 +36,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* Constructor * Constructor
*
* @param string[] $serverConfigPrefixes array containing the config Prefixes * @param string[] $serverConfigPrefixes array containing the config Prefixes
*/ */
public function __construct($serverConfigPrefixes, ILDAPWrapper $ldap, GroupPluginManager $groupPluginManager) { public function __construct($serverConfigPrefixes, ILDAPWrapper $ldap, GroupPluginManager $groupPluginManager) {
@ -51,6 +52,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* Tries the backends one after the other until a positive result is returned from the specified method * Tries the backends one after the other until a positive result is returned from the specified method
*
* @param string $gid the gid connected to the request * @param string $gid the gid connected to the request
* @param string $method the method of the group backend that shall be called * @param string $method the method of the group backend that shall be called
* @param array $parameters an array of parameters to be passed * @param array $parameters an array of parameters to be passed
@ -60,7 +62,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
$cacheKey = $this->getGroupCacheKey($gid); $cacheKey = $this->getGroupCacheKey($gid);
foreach ($this->backends as $configPrefix => $backend) { foreach ($this->backends as $configPrefix => $backend) {
if ($result = call_user_func_array([$backend, $method], $parameters)) { if ($result = call_user_func_array([$backend, $method], $parameters)) {
if(!$this->isSingleBackend()) { if (!$this->isSingleBackend()) {
$this->writeToCache($cacheKey, $configPrefix); $this->writeToCache($cacheKey, $configPrefix);
} }
return $result; return $result;
@ -71,6 +73,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* Asks the backend connected to the server that supposely takes care of the gid from the request. * Asks the backend connected to the server that supposely takes care of the gid from the request.
*
* @param string $gid the gid connected to the request * @param string $gid the gid connected to the request
* @param string $method the method of the group backend that shall be called * @param string $method the method of the group backend that shall be called
* @param array $parameters an array of parameters to be passed * @param array $parameters an array of parameters to be passed
@ -107,6 +110,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* is user in group? * is user in group?
*
* @param string $uid uid of the user * @param string $uid uid of the user
* @param string $gid gid of the group * @param string $gid gid of the group
* @return bool * @return bool
@ -119,6 +123,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* Get all groups a user belongs to * Get all groups a user belongs to
*
* @param string $uid Name of the user * @param string $uid Name of the user
* @return string[] with group names * @return string[] with group names
* *
@ -140,6 +145,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* get a list of all users in a group * get a list of all users in a group
*
* @return string[] with user ids * @return string[] with user ids
*/ */
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
@ -166,6 +172,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* delete a group * delete a group
*
* @param string $gid gid of the group to delete * @param string $gid gid of the group to delete
* @return bool * @return bool
*/ */
@ -176,6 +183,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* Add a user to a group * Add a user to a group
*
* @param string $uid Name of the user to add to group * @param string $uid Name of the user to add to group
* @param string $gid Name of the group in which add the user * @param string $gid Name of the group in which add the user
* @return bool * @return bool
@ -189,6 +197,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* Removes a user from a group * Removes a user from a group
*
* @param string $uid Name of the user to remove from group * @param string $uid Name of the user to remove from group
* @param string $gid Name of the group from which remove the user * @param string $gid Name of the group from which remove the user
* @return bool * @return bool
@ -202,6 +211,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* returns the number of users in a group, who match the search term * returns the number of users in a group, who match the search term
*
* @param string $gid the internal group name * @param string $gid the internal group name
* @param string $search optional, a search string * @param string $search optional, a search string
* @return int|bool * @return int|bool
@ -213,6 +223,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* get an array with group details * get an array with group details
*
* @param string $gid * @param string $gid
* @return array|false * @return array|false
*/ */
@ -223,6 +234,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* get a list of all groups * get a list of all groups
*
* @return string[] with group names * @return string[] with group names
* *
* Returns a list with all groups * Returns a list with all groups
@ -242,6 +254,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* check if a group exists * check if a group exists
*
* @param string $gid * @param string $gid
* @return bool * @return bool
*/ */
@ -251,6 +264,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* Check if backend implements actions * Check if backend implements actions
*
* @param int $actions bitwise-or'ed actions * @param int $actions bitwise-or'ed actions
* @return boolean * @return boolean
* *
@ -264,6 +278,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* Return access for LDAP interaction. * Return access for LDAP interaction.
*
* @param string $gid * @param string $gid
* @return Access instance of Access for LDAP interaction * @return Access instance of Access for LDAP interaction
*/ */
@ -274,6 +289,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
/** /**
* Return a new LDAP connection for the specified group. * Return a new LDAP connection for the specified group.
* The connection needs to be closed manually. * The connection needs to be closed manually.
*
* @param string $gid * @param string $gid
* @return resource of the LDAP connection * @return resource of the LDAP connection
*/ */

View File

@ -57,6 +57,7 @@ class Helper {
/** /**
* returns prefixes for each saved LDAP/AD server configuration. * returns prefixes for each saved LDAP/AD server configuration.
*
* @param bool $activeConfigurations optional, whether only active configuration shall be * @param bool $activeConfigurations optional, whether only active configuration shall be
* retrieved, defaults to false * retrieved, defaults to false
* @return array with a list of the available prefixes * @return array with a list of the available prefixes
@ -97,6 +98,7 @@ class Helper {
/** /**
* *
* determines the host for every configured connection * determines the host for every configured connection
*
* @return array an array with configprefix as keys * @return array an array with configprefix as keys
* *
*/ */
@ -149,6 +151,7 @@ class Helper {
/** /**
* deletes a given saved LDAP/AD server configuration. * deletes a given saved LDAP/AD server configuration.
*
* @param string $prefix the configuration prefix of the config to delete * @param string $prefix the configuration prefix of the config to delete
* @return bool true on success, false otherwise * @return bool true on success, false otherwise
*/ */
@ -166,11 +169,11 @@ class Helper {
DELETE DELETE
FROM `*PREFIX*appconfig` FROM `*PREFIX*appconfig`
WHERE `configkey` LIKE ? WHERE `configkey` LIKE ?
'.$saveOtherConfigurations.' ' . $saveOtherConfigurations . '
AND `appid` = \'user_ldap\' AND `appid` = \'user_ldap\'
AND `configkey` NOT IN (\'enabled\', \'installed_version\', \'types\', \'bgjUpdateGroupsLastRun\') AND `configkey` NOT IN (\'enabled\', \'installed_version\', \'types\', \'bgjUpdateGroupsLastRun\')
'); ');
$delRows = $query->execute([$prefix.'%']); $delRows = $query->execute([$prefix . '%']);
if ($delRows === null) { if ($delRows === null) {
return false; return false;
@ -185,8 +188,9 @@ class Helper {
/** /**
* checks whether there is one or more disabled LDAP configurations * checks whether there is one or more disabled LDAP configurations
* @throws \Exception *
* @return bool * @return bool
* @throws \Exception
*/ */
public function haveDisabledConfigurations() { public function haveDisabledConfigurations() {
$all = $this->getServerConfigurationPrefixes(false); $all = $this->getServerConfigurationPrefixes(false);
@ -201,6 +205,7 @@ class Helper {
/** /**
* extracts the domain from a given URL * extracts the domain from a given URL
*
* @param string $url the URL * @param string $url the URL
* @return string|false domain as string on success, false otherwise * @return string|false domain as string on success, false otherwise
*/ */
@ -234,6 +239,7 @@ class Helper {
/** /**
* sanitizes a DN received from the LDAP server * sanitizes a DN received from the LDAP server
*
* @param array $dn the DN in question * @param array $dn the DN in question
* @return array|string the sanitized DN * @return array|string the sanitized DN
*/ */
@ -247,12 +253,12 @@ class Helper {
return $result; return $result;
} }
if(!is_string($dn)) { if (!is_string($dn)) {
throw new \LogicException('String expected ' . \gettype($dn) . ' given'); throw new \LogicException('String expected ' . \gettype($dn) . ' given');
} }
if (($sanitizedDn = $this->sanitizeDnCache->get($dn)) !== null) { if (($sanitizedDn = $this->sanitizeDnCache->get($dn)) !== null) {
return $sanitizedDn; return $sanitizedDn;
} }
//OID sometimes gives back DNs with whitespace after the comma //OID sometimes gives back DNs with whitespace after the comma
@ -274,9 +280,9 @@ class Helper {
'\;' => '\5c3B', '\;' => '\5c3B',
'\"' => '\5c22', '\"' => '\5c22',
'\#' => '\5c23', '\#' => '\5c23',
'(' => '\28', '(' => '\28',
')' => '\29', ')' => '\29',
'*' => '\2A', '*' => '\2A',
]; ];
$sanitizedDn = str_replace(array_keys($replacements), array_values($replacements), $sanitizedDn); $sanitizedDn = str_replace(array_keys($replacements), array_values($replacements), $sanitizedDn);
$this->sanitizeDnCache->set($dn, $sanitizedDn); $this->sanitizeDnCache->set($dn, $sanitizedDn);
@ -286,6 +292,7 @@ class Helper {
/** /**
* converts a stored DN so it can be used as base parameter for LDAP queries, internally we store them for usage in LDAP filters * converts a stored DN so it can be used as base parameter for LDAP queries, internally we store them for usage in LDAP filters
*
* @param string $dn the DN * @param string $dn the DN
* @return string * @return string
*/ */
@ -316,7 +323,7 @@ class Helper {
$userSession = \OC::$server->getUserSession(); $userSession = \OC::$server->getUserSession();
$userPluginManager = \OC::$server->query('LDAPUserPluginManager'); $userPluginManager = \OC::$server->query('LDAPUserPluginManager');
$userBackend = new User_Proxy( $userBackend = new User_Proxy(
$configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession, $userPluginManager $configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession, $userPluginManager
); );
$uid = $userBackend->loginName2UserName($param['uid']); $uid = $userBackend->loginName2UserName($param['uid']);

View File

@ -30,7 +30,7 @@ use OC\DB\QueryBuilder\QueryBuilder;
/** /**
* Class AbstractMapping * Class AbstractMapping
* *
* @package OCA\User_LDAP\Mapping * @package OCA\User_LDAP\Mapping
*/ */
abstract class AbstractMapping { abstract class AbstractMapping {
@ -41,6 +41,7 @@ abstract class AbstractMapping {
/** /**
* returns the DB table name which holds the mappings * returns the DB table name which holds the mappings
*
* @return string * @return string
*/ */
abstract protected function getTableName(bool $includePrefix = true); abstract protected function getTableName(bool $includePrefix = true);
@ -57,6 +58,7 @@ abstract class AbstractMapping {
/** /**
* checks whether a provided string represents an existing table col * checks whether a provided string represents an existing table col
*
* @param string $col * @param string $col
* @return bool * @return bool
*/ */
@ -73,11 +75,12 @@ abstract class AbstractMapping {
/** /**
* Gets the value of one column based on a provided value of another column * Gets the value of one column based on a provided value of another column
*
* @param string $fetchCol * @param string $fetchCol
* @param string $compareCol * @param string $compareCol
* @param string $search * @param string $search
* @throws \Exception
* @return string|false * @return string|false
* @throws \Exception
*/ */
protected function getXbyY($fetchCol, $compareCol, $search) { protected function getXbyY($fetchCol, $compareCol, $search) {
if (!$this->isColNameValid($fetchCol)) { if (!$this->isColNameValid($fetchCol)) {
@ -87,7 +90,7 @@ abstract class AbstractMapping {
} }
$query = $this->dbc->prepare(' $query = $this->dbc->prepare('
SELECT `' . $fetchCol . '` SELECT `' . $fetchCol . '`
FROM `'. $this->getTableName() .'` FROM `' . $this->getTableName() . '`
WHERE `' . $compareCol . '` = ? WHERE `' . $compareCol . '` = ?
'); ');
@ -101,6 +104,7 @@ abstract class AbstractMapping {
/** /**
* Performs a DELETE or UPDATE query to the database. * Performs a DELETE or UPDATE query to the database.
*
* @param \Doctrine\DBAL\Driver\Statement $query * @param \Doctrine\DBAL\Driver\Statement $query
* @param array $parameters * @param array $parameters
* @return bool true if at least one row was modified, false otherwise * @return bool true if at least one row was modified, false otherwise
@ -113,12 +117,13 @@ abstract class AbstractMapping {
/** /**
* Gets the LDAP DN based on the provided name. * Gets the LDAP DN based on the provided name.
* Replaces Access::ocname2dn * Replaces Access::ocname2dn
*
* @param string $name * @param string $name
* @return string|false * @return string|false
*/ */
public function getDNByName($name) { public function getDNByName($name) {
$dn = array_search($name, $this->cache); $dn = array_search($name, $this->cache);
if($dn === false) { if ($dn === false) {
$dn = $this->getXbyY('ldap_dn', 'owncloud_name', $name); $dn = $this->getXbyY('ldap_dn', 'owncloud_name', $name);
$this->cache[$dn] = $name; $this->cache[$dn] = $name;
} }
@ -127,6 +132,7 @@ abstract class AbstractMapping {
/** /**
* Updates the DN based on the given UUID * Updates the DN based on the given UUID
*
* @param string $fdn * @param string $fdn
* @param string $uuid * @param string $uuid
* @return bool * @return bool
@ -141,7 +147,7 @@ abstract class AbstractMapping {
$r = $this->modify($query, [$fdn, $uuid]); $r = $this->modify($query, [$fdn, $uuid]);
if($r && is_string($oldDn) && isset($this->cache[$oldDn])) { if ($r && is_string($oldDn) && isset($this->cache[$oldDn])) {
$this->cache[$fdn] = $this->cache[$oldDn]; $this->cache[$fdn] = $this->cache[$oldDn];
unset($this->cache[$oldDn]); unset($this->cache[$oldDn]);
} }
@ -172,11 +178,12 @@ abstract class AbstractMapping {
/** /**
* Gets the name based on the provided LDAP DN. * Gets the name based on the provided LDAP DN.
*
* @param string $fdn * @param string $fdn
* @return string|false * @return string|false
*/ */
public function getNameByDN($fdn) { public function getNameByDN($fdn) {
if(!isset($this->cache[$fdn])) { if (!isset($this->cache[$fdn])) {
$this->cache[$fdn] = $this->getXbyY('owncloud_name', 'ldap_dn', $fdn); $this->cache[$fdn] = $this->getXbyY('owncloud_name', 'ldap_dn', $fdn);
} }
return $this->cache[$fdn]; return $this->cache[$fdn];
@ -201,6 +208,7 @@ abstract class AbstractMapping {
/** /**
* Searches mapped names by the giving string in the name column * Searches mapped names by the giving string in the name column
*
* @param string $search * @param string $search
* @param string $prefixMatch * @param string $prefixMatch
* @param string $postfixMatch * @param string $postfixMatch
@ -209,11 +217,11 @@ abstract class AbstractMapping {
public function getNamesBySearch($search, $prefixMatch = "", $postfixMatch = "") { public function getNamesBySearch($search, $prefixMatch = "", $postfixMatch = "") {
$query = $this->dbc->prepare(' $query = $this->dbc->prepare('
SELECT `owncloud_name` SELECT `owncloud_name`
FROM `'. $this->getTableName() .'` FROM `' . $this->getTableName() . '`
WHERE `owncloud_name` LIKE ? WHERE `owncloud_name` LIKE ?
'); ');
$res = $query->execute([$prefixMatch.$this->dbc->escapeLikeParameter($search).$postfixMatch]); $res = $query->execute([$prefixMatch . $this->dbc->escapeLikeParameter($search) . $postfixMatch]);
$names = []; $names = [];
if ($res !== false) { if ($res !== false) {
while ($row = $query->fetch()) { while ($row = $query->fetch()) {
@ -225,6 +233,7 @@ abstract class AbstractMapping {
/** /**
* Gets the name based on the provided LDAP UUID. * Gets the name based on the provided LDAP UUID.
*
* @param string $uuid * @param string $uuid
* @return string|false * @return string|false
*/ */
@ -238,6 +247,7 @@ abstract class AbstractMapping {
/** /**
* Gets the UUID based on the provided LDAP DN * Gets the UUID based on the provided LDAP DN
*
* @param string $dn * @param string $dn
* @return false|string * @return false|string
* @throws \Exception * @throws \Exception
@ -248,6 +258,7 @@ abstract class AbstractMapping {
/** /**
* gets a piece of the mapping list * gets a piece of the mapping list
*
* @param int $offset * @param int $offset
* @param int $limit * @param int $limit
* @return array * @return array
@ -269,6 +280,7 @@ abstract class AbstractMapping {
/** /**
* attempts to map the given entry * attempts to map the given entry
*
* @param string $fdn fully distinguished name (from LDAP) * @param string $fdn fully distinguished name (from LDAP)
* @param string $name * @param string $name
* @param string $uuid a unique identifier as used in LDAP * @param string $uuid a unique identifier as used in LDAP
@ -287,14 +299,14 @@ abstract class AbstractMapping {
} }
$row = [ $row = [
'ldap_dn' => $fdn, 'ldap_dn' => $fdn,
'owncloud_name' => $name, 'owncloud_name' => $name,
'directory_uuid' => $uuid 'directory_uuid' => $uuid
]; ];
try { try {
$result = $this->dbc->insertIfNotExist($this->getTableName(), $row); $result = $this->dbc->insertIfNotExist($this->getTableName(), $row);
if((bool)$result === true) { if ((bool)$result === true) {
$this->cache[$fdn] = $name; $this->cache[$fdn] = $name;
} }
// insertIfNotExist returns values as int // insertIfNotExist returns values as int
@ -306,12 +318,13 @@ abstract class AbstractMapping {
/** /**
* removes a mapping based on the owncloud_name of the entry * removes a mapping based on the owncloud_name of the entry
*
* @param string $name * @param string $name
* @return bool * @return bool
*/ */
public function unmap($name) { public function unmap($name) {
$query = $this->dbc->prepare(' $query = $this->dbc->prepare('
DELETE FROM `'. $this->getTableName() .'` DELETE FROM `' . $this->getTableName() . '`
WHERE `owncloud_name` = ?'); WHERE `owncloud_name` = ?');
return $this->modify($query, [$name]); return $this->modify($query, [$name]);
@ -319,6 +332,7 @@ abstract class AbstractMapping {
/** /**
* Truncate's the mapping table * Truncate's the mapping table
*
* @return bool * @return bool
*/ */
public function clear() { public function clear() {

View File

@ -40,7 +40,7 @@ use OCA\User_LDAP\User\Manager;
abstract class Proxy { abstract class Proxy {
private static $accesses = []; private static $accesses = [];
private $ldap = null; private $ldap = null;
/** @var bool */ /** @var bool */
private $isSingleBackend; private $isSingleBackend;
/** @var \OCP\ICache|null */ /** @var \OCP\ICache|null */
@ -72,11 +72,11 @@ abstract class Proxy {
static $coreNotificationManager; static $coreNotificationManager;
if ($fs === null) { if ($fs === null) {
$ocConfig = \OC::$server->getConfig(); $ocConfig = \OC::$server->getConfig();
$fs = new FilesystemHelper(); $fs = new FilesystemHelper();
$log = new LogWrapper(); $log = new LogWrapper();
$avatarM = \OC::$server->getAvatarManager(); $avatarM = \OC::$server->getAvatarManager();
$db = \OC::$server->getDatabaseConnection(); $db = \OC::$server->getDatabaseConnection();
$userMap = new UserMapping($db); $userMap = new UserMapping($db);
$groupMap = new GroupMapping($db); $groupMap = new GroupMapping($db);
$coreUserManager = \OC::$server->getUserManager(); $coreUserManager = \OC::$server->getUserManager();
$coreNotificationManager = \OC::$server->getNotificationManager(); $coreNotificationManager = \OC::$server->getNotificationManager();
@ -107,7 +107,7 @@ abstract class Proxy {
* @return string * @return string
*/ */
protected function getUserCacheKey($uid) { protected function getUserCacheKey($uid) {
return 'user-'.$uid.'-lastSeenOn'; return 'user-' . $uid . '-lastSeenOn';
} }
/** /**
@ -115,7 +115,7 @@ abstract class Proxy {
* @return string * @return string
*/ */
protected function getGroupCacheKey($gid) { protected function getGroupCacheKey($gid) {
return 'group-'.$gid.'-lastSeenOn'; return 'group-' . $gid . '-lastSeenOn';
} }
/** /**
@ -143,8 +143,8 @@ abstract class Proxy {
abstract protected function activeBackends(): int; abstract protected function activeBackends(): int;
protected function isSingleBackend(): bool{ protected function isSingleBackend(): bool {
if($this->isSingleBackend === null) { if ($this->isSingleBackend === null) {
$this->isSingleBackend = $this->activeBackends() === 1; $this->isSingleBackend = $this->activeBackends() === 1;
} }
return $this->isSingleBackend; return $this->isSingleBackend;
@ -152,6 +152,7 @@ abstract class Proxy {
/** /**
* Takes care of the request to the User backend * Takes care of the request to the User backend
*
* @param string $id * @param string $id
* @param string $method string, the method of the user backend that shall be called * @param string $method string, the method of the user backend that shall be called
* @param array $parameters an array of parameters to be passed * @param array $parameters an array of parameters to be passed
@ -177,7 +178,7 @@ abstract class Proxy {
if ($key === null) { if ($key === null) {
return $prefix; return $prefix;
} }
return $prefix.hash('sha256', $key); return $prefix . hash('sha256', $key);
} }
/** /**
@ -206,7 +207,7 @@ abstract class Proxy {
if ($this->cache === null) { if ($this->cache === null) {
return; return;
} }
$key = $this->getCacheKey($key); $key = $this->getCacheKey($key);
$value = base64_encode(json_encode($value)); $value = base64_encode(json_encode($value));
$this->cache->set($key, $value, 2592000); $this->cache->set($key, $value, 2592000);
} }

View File

@ -72,6 +72,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* Tries the backends one after the other until a positive result is returned from the specified method * Tries the backends one after the other until a positive result is returned from the specified method
*
* @param string $uid the uid connected to the request * @param string $uid the uid connected to the request
* @param string $method the method of the user backend that shall be called * @param string $method the method of the user backend that shall be called
* @param array $parameters an array of parameters to be passed * @param array $parameters an array of parameters to be passed
@ -86,7 +87,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
$instance = $this->getAccess($configPrefix); $instance = $this->getAccess($configPrefix);
} }
if ($result = call_user_func_array([$instance, $method], $parameters)) { if ($result = call_user_func_array([$instance, $method], $parameters)) {
if(!$this->isSingleBackend()) { if (!$this->isSingleBackend()) {
$this->writeToCache($cacheKey, $configPrefix); $this->writeToCache($cacheKey, $configPrefix);
} }
return $result; return $result;
@ -97,6 +98,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* Asks the backend connected to the server that supposely takes care of the uid from the request. * Asks the backend connected to the server that supposely takes care of the uid from the request.
*
* @param string $uid the uid connected to the request * @param string $uid the uid connected to the request
* @param string $method the method of the user backend that shall be called * @param string $method the method of the user backend that shall be called
* @param array $parameters an array of parameters to be passed * @param array $parameters an array of parameters to be passed
@ -138,6 +140,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* Check if backend implements actions * Check if backend implements actions
*
* @param int $actions bitwise-or'ed actions * @param int $actions bitwise-or'ed actions
* @return boolean * @return boolean
* *
@ -151,6 +154,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* Backend name to be shown in user management * Backend name to be shown in user management
*
* @return string the name of the backend to be shown * @return string the name of the backend to be shown
*/ */
public function getBackendName() { public function getBackendName() {
@ -179,6 +183,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* check if a user exists * check if a user exists
*
* @param string $uid the username * @param string $uid the username
* @return boolean * @return boolean
*/ */
@ -203,6 +208,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* check if a user exists on LDAP * check if a user exists on LDAP
*
* @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user
* name or an instance of that user * name or an instance of that user
* @return boolean * @return boolean
@ -214,6 +220,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* Check if the password is correct * Check if the password is correct
*
* @param string $uid The username * @param string $uid The username
* @param string $password The password * @param string $password The password
* @return bool * @return bool
@ -234,7 +241,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
$id = 'LOGINNAME,' . $loginName; $id = 'LOGINNAME,' . $loginName;
return $this->handleRequest($id, 'loginName2UserName', [$loginName]); return $this->handleRequest($id, 'loginName2UserName', [$loginName]);
} }
/** /**
* returns the username for the given LDAP DN, if available * returns the username for the given LDAP DN, if available
* *
@ -248,6 +255,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* get the user's home directory * get the user's home directory
*
* @param string $uid the username * @param string $uid the username
* @return boolean * @return boolean
*/ */
@ -257,6 +265,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* get display name of the user * get display name of the user
*
* @param string $uid user ID of the user * @param string $uid user ID of the user
* @return string display name * @return string display name
*/ */
@ -277,6 +286,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* checks whether the user is allowed to change his avatar in Nextcloud * checks whether the user is allowed to change his avatar in Nextcloud
*
* @param string $uid the Nextcloud user name * @param string $uid the Nextcloud user name
* @return boolean either the user can or cannot * @return boolean either the user can or cannot
*/ */
@ -286,6 +296,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* Get a list of all display names and user ids. * Get a list of all display names and user ids.
*
* @param string $search * @param string $search
* @param string|null $limit * @param string|null $limit
* @param string|null $offset * @param string|null $offset
@ -305,6 +316,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* delete a user * delete a user
*
* @param string $uid The username of the user to delete * @param string $uid The username of the user to delete
* @return bool * @return bool
* *
@ -313,9 +325,10 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
public function deleteUser($uid) { public function deleteUser($uid) {
return $this->handleRequest($uid, 'deleteUser', [$uid]); return $this->handleRequest($uid, 'deleteUser', [$uid]);
} }
/** /**
* Set password * Set password
*
* @param string $uid The username * @param string $uid The username
* @param string $password The new password * @param string $password The new password
* @return bool * @return bool
@ -334,6 +347,7 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* Count the number of users * Count the number of users
*
* @return int|bool * @return int|bool
*/ */
public function countUsers() { public function countUsers() {
@ -349,16 +363,18 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* Return access for LDAP interaction. * Return access for LDAP interaction.
*
* @param string $uid * @param string $uid
* @return Access instance of Access for LDAP interaction * @return Access instance of Access for LDAP interaction
*/ */
public function getLDAPAccess($uid) { public function getLDAPAccess($uid) {
return $this->handleRequest($uid, 'getLDAPAccess', [$uid]); return $this->handleRequest($uid, 'getLDAPAccess', [$uid]);
} }
/** /**
* Return a new LDAP connection for the specified user. * Return a new LDAP connection for the specified user.
* The connection needs to be closed manually. * The connection needs to be closed manually.
*
* @param string $uid * @param string $uid
* @return resource of the LDAP connection * @return resource of the LDAP connection
*/ */
@ -368,11 +384,12 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
/** /**
* Creates a new user in LDAP * Creates a new user in LDAP
*
* @param $username * @param $username
* @param $password * @param $password
* @return bool * @return bool
*/ */
public function createUser($username, $password) { public function createUser($username, $password) {
return $this->handleRequest($username, 'createUser', [$username,$password]); return $this->handleRequest($username, 'createUser', [$username, $password]);
} }
} }

View File

@ -61,7 +61,7 @@ class Group_LDAPTest extends TestCase {
$conMethods = get_class_methods('\OCA\User_LDAP\Connection'); $conMethods = get_class_methods('\OCA\User_LDAP\Connection');
$accMethods = get_class_methods('\OCA\User_LDAP\Access'); $accMethods = get_class_methods('\OCA\User_LDAP\Access');
} }
$lw = $this->createMock(ILDAPWrapper::class); $lw = $this->createMock(ILDAPWrapper::class);
$connector = $this->getMockBuilder('\OCA\User_LDAP\Connection') $connector = $this->getMockBuilder('\OCA\User_LDAP\Connection')
->setMethods($conMethods) ->setMethods($conMethods)
->setConstructorArgs([$lw, null, null]) ->setConstructorArgs([$lw, null, null])
@ -169,7 +169,7 @@ class Group_LDAPTest extends TestCase {
->method('isDNPartOfBase') ->method('isDNPartOfBase')
->willReturn(true); ->willReturn(true);
$groupBackend = new GroupLDAP($access,$pluginManager); $groupBackend = new GroupLDAP($access, $pluginManager);
$users = $groupBackend->countUsersInGroup('group', '3'); $users = $groupBackend->countUsersInGroup('group', '3');
$this->assertSame(2, $users); $this->assertSame(2, $users);
@ -178,7 +178,7 @@ class Group_LDAPTest extends TestCase {
public function testCountUsersWithPlugin() { public function testCountUsersWithPlugin() {
/** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')
->setMethods(['implementsActions','countUsersInGroup']) ->setMethods(['implementsActions', 'countUsersInGroup'])
->getMock(); ->getMock();
$pluginManager->expects($this->once()) $pluginManager->expects($this->once())
@ -196,7 +196,7 @@ class Group_LDAPTest extends TestCase {
$ldap = new GroupLDAP($access, $pluginManager); $ldap = new GroupLDAP($access, $pluginManager);
$this->assertEquals($ldap->countUsersInGroup('gid', 'search'),42); $this->assertEquals($ldap->countUsersInGroup('gid', 'search'), 42);
} }
public function testGidNumber2NameSuccess() { public function testGidNumber2NameSuccess() {
@ -478,7 +478,7 @@ class Group_LDAPTest extends TestCase {
$uid = 'someUser'; $uid = 'someUser';
$gid = 'someGroup'; $gid = 'someGroup';
$cacheKey = 'inGroup'.$uid.':'.$gid; $cacheKey = 'inGroup' . $uid . ':' . $gid;
$access->connection->expects($this->once()) $access->connection->expects($this->once())
->method('getFromCache') ->method('getFromCache')
@ -746,16 +746,16 @@ class Group_LDAPTest extends TestCase {
->willReturn([$group1, $group2]); ->willReturn([$group1, $group2]);
$access->expects($this->any()) $access->expects($this->any())
->method('dn2groupname') ->method('dn2groupname')
->willReturnCallback(function(string $dn) { ->willReturnCallback(function (string $dn) {
return ldap_explode_dn($dn, 1)[0]; return ldap_explode_dn($dn, 1)[0];
}); });
$access->expects($this->any()) $access->expects($this->any())
->method('groupname2dn') ->method('groupname2dn')
->willReturnCallback(function (string $gid) use ($group1, $group2) { ->willReturnCallback(function (string $gid) use ($group1, $group2) {
if($gid === $group1['cn']) { if ($gid === $group1['cn']) {
return $group1['dn'][0]; return $group1['dn'][0];
} }
if($gid === $group2['cn']) { if ($gid === $group2['cn']) {
return $group2['dn'][0]; return $group2['dn'][0];
} }
}); });
@ -774,7 +774,7 @@ class Group_LDAPTest extends TestCase {
public function testCreateGroupWithPlugin() { public function testCreateGroupWithPlugin() {
/** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')
->setMethods(['implementsActions','createGroup']) ->setMethods(['implementsActions', 'createGroup'])
->getMock(); ->getMock();
$pluginManager->expects($this->once()) $pluginManager->expects($this->once())
@ -792,7 +792,7 @@ class Group_LDAPTest extends TestCase {
$ldap = new GroupLDAP($access, $pluginManager); $ldap = new GroupLDAP($access, $pluginManager);
$this->assertEquals($ldap->createGroup('gid'),true); $this->assertEquals($ldap->createGroup('gid'), true);
} }
@ -820,7 +820,7 @@ class Group_LDAPTest extends TestCase {
public function testDeleteGroupWithPlugin() { public function testDeleteGroupWithPlugin() {
/** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')
->setMethods(['implementsActions','deleteGroup']) ->setMethods(['implementsActions', 'deleteGroup'])
->getMock(); ->getMock();
$pluginManager->expects($this->once()) $pluginManager->expects($this->once())
@ -847,7 +847,7 @@ class Group_LDAPTest extends TestCase {
$ldap = new GroupLDAP($access, $pluginManager); $ldap = new GroupLDAP($access, $pluginManager);
$this->assertEquals($ldap->deleteGroup('gid'),'result'); $this->assertEquals($ldap->deleteGroup('gid'), 'result');
} }
@ -875,7 +875,7 @@ class Group_LDAPTest extends TestCase {
public function testAddToGroupWithPlugin() { public function testAddToGroupWithPlugin() {
/** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')
->setMethods(['implementsActions','addToGroup']) ->setMethods(['implementsActions', 'addToGroup'])
->getMock(); ->getMock();
$pluginManager->expects($this->once()) $pluginManager->expects($this->once())
@ -893,7 +893,7 @@ class Group_LDAPTest extends TestCase {
$ldap = new GroupLDAP($access, $pluginManager); $ldap = new GroupLDAP($access, $pluginManager);
$this->assertEquals($ldap->addToGroup('uid', 'gid'),'result'); $this->assertEquals($ldap->addToGroup('uid', 'gid'), 'result');
} }
@ -921,7 +921,7 @@ class Group_LDAPTest extends TestCase {
public function testRemoveFromGroupWithPlugin() { public function testRemoveFromGroupWithPlugin() {
/** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')
->setMethods(['implementsActions','removeFromGroup']) ->setMethods(['implementsActions', 'removeFromGroup'])
->getMock(); ->getMock();
$pluginManager->expects($this->once()) $pluginManager->expects($this->once())
@ -939,7 +939,7 @@ class Group_LDAPTest extends TestCase {
$ldap = new GroupLDAP($access, $pluginManager); $ldap = new GroupLDAP($access, $pluginManager);
$this->assertEquals($ldap->removeFromGroup('uid', 'gid'),'result'); $this->assertEquals($ldap->removeFromGroup('uid', 'gid'), 'result');
} }
@ -967,7 +967,7 @@ class Group_LDAPTest extends TestCase {
public function testGetGroupDetailsWithPlugin() { public function testGetGroupDetailsWithPlugin() {
/** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */ /** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager') $pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')
->setMethods(['implementsActions','getGroupDetails']) ->setMethods(['implementsActions', 'getGroupDetails'])
->getMock(); ->getMock();
$pluginManager->expects($this->once()) $pluginManager->expects($this->once())
@ -985,7 +985,7 @@ class Group_LDAPTest extends TestCase {
$ldap = new GroupLDAP($access, $pluginManager); $ldap = new GroupLDAP($access, $pluginManager);
$this->assertEquals($ldap->getGroupDetails('gid'),'result'); $this->assertEquals($ldap->getGroupDetails('gid'), 'result');
} }