Skip to content

Commit 0eccaef

Browse files
committed
Merge pull request #6 from preemeijer/groupsprovider
Option for choosing a groupsprovider
2 parents 6c26c62 + 7557140 commit 0eccaef

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

config/voot.ini.defaults

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ dsn = "sqlite:/PATH/TO/APP/data/voot.sqlite"
2121
persistentConnection = FALSE
2222

2323
[LdapVootStorage]
24-
; OpenLDAP / Fedora Directory Server
24+
; OpenLDAP - Which groupsprovider solution are you using.
25+
; Options: posixgroup, groupsofnames(default)
26+
; Uncomment the following line when using posixgroups
27+
; groupsProvider = "posixgroup"
28+
29+
; Uncomment the appropriate OpenLDAP solution
30+
31+
; OpenLDAP - GROUPOFNAMES / Fedora Directory Server
2532
uri = "ldap://localhost"
2633
peopleDn = "ou=People,dc=example,dc=org"
2734
groupDn = "ou=Groups,dc=example,dc=org"
@@ -33,6 +40,18 @@ attributeMapping["id"] = "uid"
3340
attributeMapping["displayName"] = "cn"
3441
attributeMapping["mail"] = "mail"
3542

43+
; OpenLDAP - POSIXGROUP
44+
;uri = "ldap://"
45+
;peopleDn = "ou=Users,dc=,dc=,dc="
46+
;groupDn = "ou=Groups,dc=,dc=,dc="
47+
48+
;userIdAttribute = "uid";
49+
;memberAttribute = "memberUid"
50+
51+
;attributeMapping["id"] = "cn"
52+
;attributeMapping["displayName"] = "cn"
53+
;attributeMapping["mail"] = "mail"
54+
3655
; Microsoft Active Directory
3756
;uri = "ldap://ad.example.org"
3857
;bindDn = "cn=Administrator,cn=Users,dc=example,dc=org"

src/fkooman/VootProvider/LdapVootStorage.php

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ public function getGroupMembers($resourceOwnerId, $groupId, $startIndex = 0, $co
112112
$memberAttribute = $this->config->s('LdapVootStorage')->l('memberAttribute');
113113

114114
$userDn = $this->getUserDn($resourceOwnerId);
115-
115+
116+
$groupsProvider = $this->config->s('LdapVootStorage')->l('groupsProvider');
117+
116118
// FIXME: make sure the user is member of the group being requested
117119

118120
$filter = '(cn=' . $groupId . ')';
@@ -127,6 +129,17 @@ public function getGroupMembers($resourceOwnerId, $groupId, $startIndex = 0, $co
127129
if (false === $query) {
128130
throw new VootStorageException("ldap_error", "directory query for group failed");
129131
}
132+
133+
$all = ldap_get_entries($this->ldapConnection, $query);
134+
135+
switch ($groupsProvider) {
136+
case "posixgroup":
137+
// we are only interested in group memberuid array
138+
$attributes = $all[0];
139+
break;
140+
default:
141+
break;
142+
}
130143

131144
$entry = @ldap_first_entry($this->ldapConnection, $query);
132145
if (false === $entry) {
@@ -143,7 +156,16 @@ public function getGroupMembers($resourceOwnerId, $groupId, $startIndex = 0, $co
143156
for ($i = 0; $i < $attributes[$memberAttribute]["count"]; $i++) {
144157
// member DN
145158
// fetch attributes for this particular user
146-
$userAttributes = $this->getUserAttributesByDn($attributes[$memberAttribute][$i]);
159+
switch ($groupsProvider) {
160+
case "posixgroup":
161+
$user_dn = 'uid=' . $attributes[$memberAttribute][$i] . ',' . $this->config->s('LdapVootStorage')->l('peopleDn');
162+
$userAttributes = $this->getUserAttributesByDn($user_dn);
163+
break;
164+
default:
165+
$userAttributes = $this->getUserAttributesByDn($attributes[$memberAttribute][$i]);
166+
break;
167+
}
168+
147169
$userAttributes['voot_membership_role'] = "member";
148170
array_push($data, $userAttributes);
149171
}
@@ -167,8 +189,19 @@ public function isMemberOf($resourceOwnerId, $startIndex = null, $count = null)
167189
$userDn = $this->getUserDn($resourceOwnerId);
168190

169191
$userGroups = array();
192+
193+
$groupsProvider = $this->config->s('LdapVootStorage')->l('groupsProvider');
194+
170195
/* get the groups the user is a member of */
171-
$filter = '(' . $this->config->s('LdapVootStorage')->l('memberAttribute') . '=' . $userDn . ')';
196+
switch ($groupsProvider) {
197+
case "posixgroup":
198+
$filter = '(' . $this->config->s('LdapVootStorage')->l('memberAttribute') . '=' . $resourceOwnerId . ')';
199+
break;
200+
default:
201+
$filter = '(' . $this->config->s('LdapVootStorage')->l('memberAttribute') . '=' . $userDn . ')';
202+
break;
203+
}
204+
172205
$query = @ldap_search($this->ldapConnection, $this->config->s('LdapVootStorage')->l('groupDn'), $filter);
173206
if (false === $query) {
174207
throw new VootStorageException("ldap_error", "directory query for groups failed");

0 commit comments

Comments
 (0)