Skip to content
Snippets Groups Projects
Commit 54a9fd2e authored by Arthur Schiwon's avatar Arthur Schiwon
Browse files

group LDAP: implemented inGroup()

parent 1f91224f
Branches
No related tags found
No related merge requests found
......@@ -40,7 +40,20 @@
* Checks whether the user is member of a group or not.
*/
public function inGroup($uid, $gid) {
return array();
$filter = OC_LDAP::combineFilterWithAnd(array(
$this->ldapGroupFilter,
LDAP_GROUP_MEMBER_ASSOC_ATTR.'='.$uid,
$this->ldapGroupDisplayName.'='.$gid
));
$groups = OC_LDAP::search($filter, $this->ldapGroupDisplayName);
if(count($groups) == 1) {
return true;
} else if(count($groups) < 1) {
return false;
} else {
throw new Exception('Too many groups of the same name!? – this excpetion should never been thrown :)');
}
}
/**
......
......@@ -21,6 +21,8 @@
*
*/
define(LDAP_GROUP_MEMBER_ASSOC_ATTR,'memberUid');
class OC_LDAP {
static protected $ldapConnectionRes = false;
static protected $configured = false;
......@@ -64,6 +66,48 @@
return $findings;
}
/**
* @brief combines the input filters with AND
* @param $filters array, the filters to connect
* @returns the combined filter
*
* Combines Filter arguments with AND
*/
static public function combineFilterWithAnd($filters) {
return self::combineFilter($filters,'&');
}
/**
* @brief combines the input filters with AND
* @param $filters array, the filters to connect
* @returns the combined filter
*
* Combines Filter arguments with AND
*/
static public function combineFilterWithOr($filters) {
return self::combineFilter($filters,'|');
}
/**
* @brief combines the input filters with given operator
* @param $filters array, the filters to connect
* @param $operator either & or |
* @returns the combined filter
*
* Combines Filter arguments with AND
*/
static private function combineFilter($filters, $operator) {
$combinedFilter = '('.$operator;
foreach($filters as $filter) {
if(substr($filter,0,1) != '(') {
$filter = '('.$filter.')';
}
$combinedFilter.=$filter;
}
$combinedFilter.=')';
return $combinedFilter;
}
/**
* Returns the LDAP handler
*/
......
......@@ -31,6 +31,10 @@ class Test_Group_Ldap extends UnitTestCase {
$this->assertIsA(OC_Group::getGroups(),gettype(array()));
$this->assertIsA($group_ldap->getGroups(),gettype(array()));
$this->assertFalse(OC_Group::inGroup('john','dosers'),gettype(false));
$this->assertFalse($group_ldap->inGroup('john','dosers'),gettype(false));
//TODO: check also for expected true result. This backend won't be able to do any modifications, maybe use a dummy for this.
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment