Skip to content

Commit

Permalink
Allow to switch Group Schema for LDAP Groups
Browse files Browse the repository at this point in the history
This allows to switch between different types of LDAP Groups. The
default behaviour (REVA_LDAP_GROUP_SCHEMA="rfc2307") is to use the
"posixGroup" objectclass with "memberUID" attribute. Any other value for
REVA_LDAP_GROUP_SCHEMA will switch the behaviour to objectclass
"groupOfNames" and the "member" Attribute.
  • Loading branch information
rhafer committed Mar 22, 2022
1 parent 6835c02 commit d64194a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
7 changes: 7 additions & 0 deletions tests/TestHelpers/OcisHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ public static function getUsersOU():string {
return $ou ? $ou : "TestUsers";
}

/**
* @return string
*/
public static function getGroupSchema():string {
$schema = \getenv("REVA_LDAP_GROUP_SCHEMA");
return $schema ? $schema : "rfc2307";
}
/**
* @return string
*/
Expand Down
4 changes: 4 additions & 0 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ public function pushToLastStatusCodesArrays():void {
* @var string
*/
private $ldapGroupsOU;
/**
* @var string
*/
private $ldapGroupSchema;
/**
* @var bool
*/
Expand Down
44 changes: 38 additions & 6 deletions tests/acceptance/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ public function connectToLdap(array $suiteParameters):void {
$this->ldapBaseDN = OcisHelper::getBaseDN();
$this->ldapUsersOU = OcisHelper::getGroupsOU();
$this->ldapGroupsOU = OcisHelper::getUsersOU();
$this->ldapGroupSchema = OcisHelper::getGroupSchema();
$this->ldapHost = OcisHelper::getHostname();
$this->ldapPort = OcisHelper::getLdapPort();
$useSsl = OcisHelper::useSsl();
Expand Down Expand Up @@ -572,6 +573,7 @@ public function connectToLdap(array $suiteParameters):void {
$this->ldapHost = (string)$ldapConfig['ldapHost'];
$this->ldapPort = (int)$ldapConfig['ldapPort'];
$this->ldapAdminUser = (string)$ldapConfig['ldapAgentName'];
$this->ldapGroupSchema = "rfc2307";
$this->ldapUsersOU = (string)$suiteParameters['ldapUsersOU'];
$this->ldapGroupsOU = (string)$suiteParameters['ldapGroupsOU'];
}
Expand Down Expand Up @@ -767,9 +769,19 @@ public function createLdapGroup(string $group):void {
$newDN = 'cn=' . $group . ',ou=' . $this->ldapGroupsOU . ',' . $baseDN;
$entry = [];
$entry['cn'] = $group;
$entry['objectclass'][] = 'posixGroup';
$entry['objectclass'][] = 'top';
$entry['gidNumber'] = 5000;

if ($this->ldapGroupSchema == "rfc2307") {
$entry['objectclass'][] = 'posixGroup';
$entry['gidNumber'] = 5000;
} else {
$entry['objectclass'][] = 'groupOfNames';
$entry['member'] = "";
}
if (OcisHelper::isTestingOnOcis()) {
$entry['objectclass'][] = 'ownCloud';
$entry['ownCloudUUID'] = $this->generateUUIDv4();
}
$this->ldap->add($newDN, $entry);
\array_push($this->ldapCreatedGroups, $group);
// For syncing the ldap groups
Expand Down Expand Up @@ -3847,10 +3859,20 @@ public function addUserToLdapGroup(string $user, string $group, ?string $ou = nu
if ($ou === null) {
$ou = $this->getLdapGroupsOU();
}
$memberAttr = "";
$memberValue = "";
if ($this->ldapGroupSchema == "rfc2307") {
$memberAttr = "memberUID";
$memberValue = "$user";
} else {
$memberAttr = "member";
$userbase = "ou=" . $this->getLdapUsersOU() . "," . $this->ldapBaseDN;
$memberValue = "uid=$user" . "," . "$userbase";
}
$this->setTheLdapAttributeOfTheEntryTo(
"memberUid",
$memberAttr,
"cn=$group,ou=$ou",
$user,
$memberValue,
true
);
}
Expand Down Expand Up @@ -3881,9 +3903,19 @@ public function removeUserFromLdapGroup(string $user, string $group, ?string $ou
if ($ou === null) {
$ou = $this->getLdapGroupsOU();
}
$memberAttr = "";
$memberValue = "";
if ($this->ldapGroupSchema == "rfc2307") {
$memberAttr = "memberUID";
$memberValue = "$user";
} else {
$memberAttr = "member";
$userbase = "ou=" . $this->getLdapUsersOU() . "," . $this->ldapBaseDN;
$memberValue = "uid=$user" . "," . "$userbase";
}
$this->deleteValueFromLdapAttribute(
$user,
"memberUid",
$memberValue,
$memberAttr,
"cn=$group,ou=$ou"
);
$this->theLdapUsersHaveBeenReSynced();
Expand Down

0 comments on commit d64194a

Please sign in to comment.