Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
58828d20
Commit
58828d20
authored
12 years ago
by
Arthur Schiwon
Browse files
Options
Downloads
Patches
Plain Diff
LDAP: usersInGroup now also does LDAP serverside search.
parent
3f85432d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/user_ldap/group_ldap.php
+41
-30
41 additions, 30 deletions
apps/user_ldap/group_ldap.php
with
41 additions
and
30 deletions
apps/user_ldap/group_ldap.php
+
41
−
30
View file @
58828d20
...
...
@@ -139,61 +139,72 @@ class GROUP_LDAP extends lib\Access implements \OCP\GroupInterface {
if
(
!
$this
->
enabled
)
{
return
array
();
}
$this
->
groupSearch
=
$search
;
if
(
$this
->
connection
->
isCached
(
'usersInGroup'
.
$gid
))
{
$groupUsers
=
$this
->
connection
->
getFromCache
(
'usersInGroup'
.
$gid
);
if
(
!
empty
(
$this
->
groupSearch
))
{
$groupUsers
=
array_filter
(
$groupUsers
,
array
(
$this
,
'groupMatchesFilter'
));
}
if
(
$limit
==
-
1
)
{
$limit
=
null
;
}
return
array_slice
(
$groupUsers
,
$offset
,
$limit
);
$cachekey
=
'usersInGroup-'
.
$gid
.
'-'
.
$search
.
'-'
.
$limit
.
'-'
.
$offset
;
// check for cache of the exact query
$groupUsers
=
$this
->
connection
->
getFromCache
(
$cachekey
);
if
(
!
is_null
(
$groupUsers
))
{
return
$groupUsers
;
}
// check for cache of the query without limit and offset
$groupUsers
=
$this
->
connection
->
getFromCache
(
'usersInGroup-'
.
$gid
.
'-'
.
$search
);
if
(
!
is_null
(
$groupUsers
))
{
$groupUsers
=
array_slice
(
$groupUsers
,
$offset
,
$limit
);
$this
->
connection
->
writeToCache
(
$cachekey
,
$groupUsers
);
return
$groupUsers
;
}
if
(
$limit
==
-
1
)
{
$limit
=
null
;
}
$groupDN
=
$this
->
groupname2dn
(
$gid
);
if
(
!
$groupDN
)
{
$this
->
connection
->
writeToCache
(
'usersInGroup'
.
$gid
,
array
());
// group couldn't be found, return empty resultset
$this
->
connection
->
writeToCache
(
$cachekey
,
array
());
return
array
();
}
$members
=
$this
->
readAttribute
(
$groupDN
,
$this
->
connection
->
ldapGroupMemberAssocAttr
);
if
(
!
$members
)
{
$this
->
connection
->
writeToCache
(
'usersInGroup'
.
$gid
,
array
());
//in case users could not be retrieved, return empty resultset
$this
->
connection
->
writeToCache
(
$cachekey
,
array
());
return
array
();
}
$result
=
array
();
$search
=
empty
(
$search
)
?
'*'
:
'*'
.
$search
.
'*'
;
$groupUsers
=
array
();
$isMemberUid
=
(
strtolower
(
$this
->
connection
->
ldapGroupMemberAssocAttr
)
==
'memberuid'
);
foreach
(
$members
as
$member
)
{
if
(
$isMemberUid
)
{
$filter
=
\OCP\Util
::
mb_str_replace
(
'%uid'
,
$member
,
$this
->
connection
->
ldapLoginFilter
,
'UTF-8'
);
//we got uids, need to get their DNs to 'tranlsate' them to usernames
$filter
=
$this
->
combineFilterWithAnd
(
array
(
\OCP\Util
::
mb_str_replace
(
'%uid'
,
$member
,
$this
->
connection
>
ldapLoginFilter
,
'UTF-8'
),
$this
->
connection
->
ldapUserDisplayName
.
'='
.
$search
));
$ldap_users
=
$this
->
fetchListOfUsers
(
$filter
,
'dn'
);
if
(
count
(
$ldap_users
)
<
1
)
{
continue
;
}
$result
[]
=
$this
->
dn2username
(
$ldap_users
[
0
]);
continue
;
$groupUsers
[]
=
$this
->
dn2username
(
$ldap_users
[
0
]);
}
else
{
//we got DNs, check if we need to filter by search or we can give back all of them
if
(
$search
!=
'*'
)
{
if
(
!
$this
->
readAttribute
(
$member
,
$this
->
connection
->
ldapUserDisplayName
,
$this
->
connection
->
ldapUserDisplayName
.
'='
.
$search
))
{
continue
;
}
}
// dn2username will also check if the users belong to the allowed base
if
(
$ocname
=
$this
->
dn2username
(
$member
))
{
$
result
[]
=
$ocname
;
$
groupUsers
[]
=
$ocname
;
}
}
}
if
(
!
$isMemberUid
)
{
$result
=
array_intersect
(
$result
,
\OCP\User
::
getUsers
());
}
$groupUsers
=
array_unique
(
$result
,
SORT_LOCALE_STRING
);
$this
->
connection
->
writeToCache
(
'usersInGroup'
.
$gid
,
$groupUsers
);
if
(
!
empty
(
$this
->
groupSearch
))
{
$groupUsers
=
array_filter
(
$groupUsers
,
array
(
$this
,
'groupMatchesFilter'
));
}
if
(
$limit
==
-
1
)
{
$limit
=
null
;
}
return
array_slice
(
$groupUsers
,
$offset
,
$limit
);
natsort
(
$groupUsers
);
$this
->
connection
->
writeToCache
(
'usersInGroup-'
.
$gid
.
'-'
.
$search
,
$groupUsers
);
$groupUsers
=
array_slice
(
$groupUsers
,
$offset
,
$limit
);
$this
->
connection
->
writeToCache
(
$cachekey
,
$groupUsers
);
return
$groupUsers
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment