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
42492338
Commit
42492338
authored
12 years ago
by
Arthur Schiwon
Browse files
Options
Downloads
Patches
Plain Diff
LDAP: put app under the OCA\user_ldap\ namespace
parent
57c375ea
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/user_ldap/appinfo/app.php
+3
-5
3 additions, 5 deletions
apps/user_ldap/appinfo/app.php
apps/user_ldap/group_ldap.php
+24
-22
24 additions, 22 deletions
apps/user_ldap/group_ldap.php
apps/user_ldap/user_ldap.php
+19
-17
19 additions, 17 deletions
apps/user_ldap/user_ldap.php
with
46 additions
and
44 deletions
apps/user_ldap/appinfo/app.php
+
3
−
5
View file @
42492338
...
...
@@ -22,15 +22,13 @@
*/
require_once
(
'apps/user_ldap/lib_ldap.php'
);
require_once
(
'apps/user_ldap/user_ldap.php'
);
require_once
(
'apps/user_ldap/group_ldap.php'
);
// OC::$CLASSPATH['OCA\user_ldap\LDAP_Access']='apps/user_ldap/lib/access.php';
// require_once('apps/user_ldap/group_ldap.php');
OCP\App
::
registerAdmin
(
'user_ldap'
,
'settings'
);
// register user backend
OC_User
::
useBackend
(
new
OC
_
USER_LDAP
()
);
OC_Group
::
useBackend
(
new
OC
_
GROUP_LDAP
()
);
OC_User
::
useBackend
(
new
OC
A\user_ldap\
USER_LDAP
());
OC_Group
::
useBackend
(
new
OC
A\user_ldap\
GROUP_LDAP
());
// add settings page to navigation
$entry
=
array
(
...
...
This diff is collapsed.
Click to expand it.
apps/user_ldap/group_ldap.php
+
24
−
22
View file @
42492338
...
...
@@ -21,7 +21,9 @@
*
*/
class
OC_GROUP_LDAP
extends
OC_Group_Backend
{
namespace
OCA\user_ldap
;
class
GROUP_LDAP
extends
\OC_Group_Backend
{
// //group specific settings
protected
$ldapGroupFilter
;
protected
$ldapGroupMemberAssocAttr
;
...
...
@@ -33,8 +35,8 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
protected
$_groups
=
array
();
public
function
__construct
()
{
$this
->
ldapGroupFilter
=
OCP\Config
::
getAppValue
(
'user_ldap'
,
'ldap_group_filter'
,
'(objectClass=posixGroup)'
);
$this
->
ldapGroupMemberAssocAttr
=
OCP\Config
::
getAppValue
(
'user_ldap'
,
'ldap_group_member_assoc_attribute'
,
'uniqueMember'
);
$this
->
ldapGroupFilter
=
\
OCP\Config
::
getAppValue
(
'user_ldap'
,
'ldap_group_filter'
,
'(objectClass=posixGroup)'
);
$this
->
ldapGroupMemberAssocAttr
=
\
OCP\Config
::
getAppValue
(
'user_ldap'
,
'ldap_group_member_assoc_attribute'
,
'uniqueMember'
);
if
(
!
empty
(
$this
->
ldapGroupFilter
)
&&
!
empty
(
$this
->
ldapGroupMemberAssocAttr
))
{
$this
->
configured
=
true
;
...
...
@@ -56,14 +58,14 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
if
(
isset
(
$this
->
_group_user
[
$gid
][
$uid
]))
{
return
$this
->
_group_user
[
$gid
][
$uid
];
}
$dn_user
=
OC_LDAP
::
username2dn
(
$uid
);
$dn_group
=
OC_LDAP
::
groupname2dn
(
$gid
);
$dn_user
=
\
OC_LDAP
::
username2dn
(
$uid
);
$dn_group
=
\
OC_LDAP
::
groupname2dn
(
$gid
);
// just in case
if
(
!
$dn_group
||
!
$dn_user
)
{
return
false
;
}
//usually, LDAP attributes are said to be case insensitive. But there are exceptions of course.
$members
=
OC_LDAP
::
readAttribute
(
$dn_group
,
$this
->
ldapGroupMemberAssocAttr
);
$members
=
\
OC_LDAP
::
readAttribute
(
$dn_group
,
$this
->
ldapGroupMemberAssocAttr
);
if
(
!
$members
)
{
return
false
;
}
...
...
@@ -73,8 +75,8 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
if
(
strtolower
(
$this
->
ldapGroupMemberAssocAttr
)
==
'memberuid'
)
{
$dns
=
array
();
foreach
(
$members
as
$mid
)
{
$filter
=
str_replace
(
'%uid'
,
$mid
,
OC_LDAP
::
conf
(
'ldapLoginFilter'
));
$ldap_users
=
OC_LDAP
::
fetchListOfUsers
(
$filter
,
'dn'
);
$filter
=
str_replace
(
'%uid'
,
$mid
,
\
OC_LDAP
::
conf
(
'ldapLoginFilter'
));
$ldap_users
=
\
OC_LDAP
::
fetchListOfUsers
(
$filter
,
'dn'
);
if
(
count
(
$ldap_users
)
<
1
)
{
continue
;
}
...
...
@@ -102,7 +104,7 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
if
(
isset
(
$this
->
_user_groups
[
$uid
]))
{
return
$this
->
_user_groups
[
$uid
];
}
$userDN
=
OC_LDAP
::
username2dn
(
$uid
);
$userDN
=
\
OC_LDAP
::
username2dn
(
$uid
);
if
(
!
$userDN
)
{
$this
->
_user_groups
[
$uid
]
=
array
();
return
array
();
...
...
@@ -113,19 +115,19 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
||
(
strtolower
(
$this
->
ldapGroupMemberAssocAttr
)
==
'member'
))
{
$uid
=
$userDN
;
}
else
if
(
strtolower
(
$this
->
ldapGroupMemberAssocAttr
)
==
'memberuid'
)
{
$result
=
OC_LDAP
::
readAttribute
(
$userDN
,
'uid'
);
$result
=
\
OC_LDAP
::
readAttribute
(
$userDN
,
'uid'
);
$uid
=
$result
[
0
];
}
else
{
// just in case
$uid
=
$userDN
;
}
$filter
=
OC_LDAP
::
combineFilterWithAnd
(
array
(
$filter
=
\
OC_LDAP
::
combineFilterWithAnd
(
array
(
$this
->
ldapGroupFilter
,
$this
->
ldapGroupMemberAssocAttr
.
'='
.
$uid
));
$groups
=
OC_LDAP
::
fetchListOfGroups
(
$filter
,
array
(
OC_LDAP
::
conf
(
'ldapGroupDisplayName'
),
'dn'
));
$this
->
_user_groups
[
$uid
]
=
array_unique
(
OC_LDAP
::
ownCloudGroupNames
(
$groups
),
SORT_LOCALE_STRING
);
$groups
=
\
OC_LDAP
::
fetchListOfGroups
(
$filter
,
array
(
\
OC_LDAP
::
conf
(
'ldapGroupDisplayName'
),
'dn'
));
$this
->
_user_groups
[
$uid
]
=
array_unique
(
\
OC_LDAP
::
ownCloudGroupNames
(
$groups
),
SORT_LOCALE_STRING
);
return
$this
->
_user_groups
[
$uid
];
}
...
...
@@ -142,13 +144,13 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
return
$this
->
_group_users
[
$gid
];
}
$groupDN
=
OC_LDAP
::
groupname2dn
(
$gid
);
$groupDN
=
\
OC_LDAP
::
groupname2dn
(
$gid
);
if
(
!
$groupDN
)
{
$this
->
_group_users
[
$gid
]
=
array
();
return
array
();
}
$members
=
OC_LDAP
::
readAttribute
(
$groupDN
,
$this
->
ldapGroupMemberAssocAttr
);
$members
=
\
OC_LDAP
::
readAttribute
(
$groupDN
,
$this
->
ldapGroupMemberAssocAttr
);
if
(
!
$members
)
{
$this
->
_group_users
[
$gid
]
=
array
();
return
array
();
...
...
@@ -158,21 +160,21 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
$isMemberUid
=
(
strtolower
(
$this
->
ldapGroupMemberAssocAttr
)
==
'memberuid'
);
foreach
(
$members
as
$member
)
{
if
(
$isMemberUid
)
{
$filter
=
OCP\Util
::
mb_str_replace
(
'%uid'
,
$member
,
OC_LDAP
::
conf
(
'ldapLoginFilter'
),
'UTF-8'
);
$ldap_users
=
OC_LDAP
::
fetchListOfUsers
(
$filter
,
'dn'
);
$filter
=
\
OCP\Util
::
mb_str_replace
(
'%uid'
,
$member
,
\
OC_LDAP
::
conf
(
'ldapLoginFilter'
),
'UTF-8'
);
$ldap_users
=
\
OC_LDAP
::
fetchListOfUsers
(
$filter
,
'dn'
);
if
(
count
(
$ldap_users
)
<
1
)
{
continue
;
}
$result
[]
=
OC_LDAP
::
dn2username
(
$ldap_users
[
0
]);
$result
[]
=
\
OC_LDAP
::
dn2username
(
$ldap_users
[
0
]);
continue
;
}
else
{
if
(
$ocname
=
OC_LDAP
::
dn2username
(
$member
)){
if
(
$ocname
=
\
OC_LDAP
::
dn2username
(
$member
)){
$result
[]
=
$ocname
;
}
}
}
if
(
!
$isMemberUid
)
{
$result
=
array_intersect
(
$result
,
OCP\User
::
getUsers
());
$result
=
array_intersect
(
$result
,
\
OCP\User
::
getUsers
());
}
$this
->
_group_users
[
$gid
]
=
array_unique
(
$result
,
SORT_LOCALE_STRING
);
return
$this
->
_group_users
[
$gid
];
...
...
@@ -189,8 +191,8 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
return
array
();
}
if
(
empty
(
$this
->
_groups
))
{
$ldap_groups
=
OC_LDAP
::
fetchListOfGroups
(
$this
->
ldapGroupFilter
,
array
(
OC_LDAP
::
conf
(
'ldapGroupDisplayName'
),
'dn'
));
$this
->
_groups
=
OC_LDAP
::
ownCloudGroupNames
(
$ldap_groups
);
$ldap_groups
=
\
OC_LDAP
::
fetchListOfGroups
(
$this
->
ldapGroupFilter
,
array
(
\
OC_LDAP
::
conf
(
'ldapGroupDisplayName'
),
'dn'
));
$this
->
_groups
=
\
OC_LDAP
::
ownCloudGroupNames
(
$ldap_groups
);
}
return
$this
->
_groups
;
}
...
...
This diff is collapsed.
Click to expand it.
apps/user_ldap/user_ldap.php
+
19
−
17
View file @
42492338
...
...
@@ -23,7 +23,9 @@
*
*/
class
OC_USER_LDAP
extends
OCA\user_ldap\LDAP_Access
implements
OCP\UserInterface
{
namespace
OCA\user_ldap
;
class
USER_LDAP
extends
lib\Access
implements
\OCP\UserInterface
{
// cached settings
protected
$ldapUserFilter
;
...
...
@@ -38,10 +40,10 @@ class OC_USER_LDAP extends OCA\user_ldap\LDAP_Access implements OCP\UserInterfac
protected
$_users
=
null
;
public
function
__construct
()
{
$this
->
ldapUserFilter
=
OCP\Config
::
getAppValue
(
'user_ldap'
,
'ldap_userlist_filter'
,
'(objectClass=posixAccount)'
);
$this
->
ldapQuotaAttribute
=
OCP\Config
::
getAppValue
(
'user_ldap'
,
'ldap_quota_attr'
,
''
);
$this
->
ldapQuotaDefault
=
OCP\Config
::
getAppValue
(
'user_ldap'
,
'ldap_quota_def'
,
''
);
$this
->
ldapEmailAttribute
=
OCP\Config
::
getAppValue
(
'user_ldap'
,
'ldap_email_attr'
,
''
);
$this
->
ldapUserFilter
=
\
OCP\Config
::
getAppValue
(
'user_ldap'
,
'ldap_userlist_filter'
,
'(objectClass=posixAccount)'
);
$this
->
ldapQuotaAttribute
=
\
OCP\Config
::
getAppValue
(
'user_ldap'
,
'ldap_quota_attr'
,
''
);
$this
->
ldapQuotaDefault
=
\
OCP\Config
::
getAppValue
(
'user_ldap'
,
'ldap_quota_def'
,
''
);
$this
->
ldapEmailAttribute
=
\
OCP\Config
::
getAppValue
(
'user_ldap'
,
'ldap_email_attr'
,
''
);
}
private
function
updateQuota
(
$dn
)
{
...
...
@@ -50,26 +52,26 @@ class OC_USER_LDAP extends OCA\user_ldap\LDAP_Access implements OCP\UserInterfac
$quota
=
$this
->
ldapQuotaDefault
;
}
if
(
!
empty
(
$this
->
ldapQuotaAttribute
))
{
$aQuota
=
OC_LDAP
::
readAttribute
(
$dn
,
$this
->
ldapQuotaAttribute
);
$aQuota
=
\
OC_LDAP
::
readAttribute
(
$dn
,
$this
->
ldapQuotaAttribute
);
if
(
$aQuota
&&
(
count
(
$aQuota
)
>
0
))
{
$quota
=
$aQuota
[
0
];
}
}
if
(
!
is_null
(
$quota
))
{
OCP\Config
::
setUserValue
(
OC_LDAP
::
dn2username
(
$dn
),
'files'
,
'quota'
,
OCP\Util
::
computerFileSize
(
$quota
));
\
OCP\Config
::
setUserValue
(
\
OC_LDAP
::
dn2username
(
$dn
),
'files'
,
'quota'
,
\
OCP\Util
::
computerFileSize
(
$quota
));
}
}
private
function
updateEmail
(
$dn
)
{
$email
=
null
;
if
(
!
empty
(
$this
->
ldapEmailAttribute
))
{
$aEmail
=
OC_LDAP
::
readAttribute
(
$dn
,
$this
->
ldapEmailAttribute
);
$aEmail
=
\
OC_LDAP
::
readAttribute
(
$dn
,
$this
->
ldapEmailAttribute
);
if
(
$aEmail
&&
(
count
(
$aEmail
)
>
0
))
{
$email
=
$aEmail
[
0
];
}
if
(
!
is_null
(
$email
)){
OCP\Config
::
setUserValue
(
OC_LDAP
::
dn2username
(
$dn
),
'settings'
,
'email'
,
$email
);
\
OCP\Config
::
setUserValue
(
\
OC_LDAP
::
dn2username
(
$dn
),
'settings'
,
'email'
,
$email
);
}
}
}
...
...
@@ -84,15 +86,15 @@ class OC_USER_LDAP extends OCA\user_ldap\LDAP_Access implements OCP\UserInterfac
*/
public
function
checkPassword
(
$uid
,
$password
){
//find out dn of the user name
$filter
=
OCP\Util
::
mb_str_replace
(
'%uid'
,
$uid
,
OC_LDAP
::
conf
(
'ldapLoginFilter'
),
'UTF-8'
);
$ldap_users
=
OC_LDAP
::
fetchListOfUsers
(
$filter
,
'dn'
);
$filter
=
\
OCP\Util
::
mb_str_replace
(
'%uid'
,
$uid
,
\
OC_LDAP
::
conf
(
'ldapLoginFilter'
),
'UTF-8'
);
$ldap_users
=
\
OC_LDAP
::
fetchListOfUsers
(
$filter
,
'dn'
);
if
(
count
(
$ldap_users
)
<
1
)
{
return
false
;
}
$dn
=
$ldap_users
[
0
];
//are the credentials OK?
if
(
!
OC_LDAP
::
areCredentialsValid
(
$dn
,
$password
))
{
if
(
!
\
OC_LDAP
::
areCredentialsValid
(
$dn
,
$password
))
{
return
false
;
}
...
...
@@ -101,7 +103,7 @@ class OC_USER_LDAP extends OCA\user_ldap\LDAP_Access implements OCP\UserInterfac
$this
->
updateEmail
(
$dn
);
//give back the display name
return
OC_LDAP
::
dn2username
(
$dn
);
return
\
OC_LDAP
::
dn2username
(
$dn
);
}
/**
...
...
@@ -112,8 +114,8 @@ class OC_USER_LDAP extends OCA\user_ldap\LDAP_Access implements OCP\UserInterfac
*/
public
function
getUsers
(){
if
(
is_null
(
$this
->
_users
))
{
$ldap_users
=
OC_LDAP
::
fetchListOfUsers
(
$this
->
ldapUserFilter
,
array
(
OC_LDAP
::
conf
(
'ldapUserDisplayName'
),
'dn'
));
$this
->
_users
=
OC_LDAP
::
ownCloudUserNames
(
$ldap_users
);
$ldap_users
=
\
OC_LDAP
::
fetchListOfUsers
(
$this
->
ldapUserFilter
,
array
(
\
OC_LDAP
::
conf
(
'ldapUserDisplayName'
),
'dn'
));
$this
->
_users
=
\
OC_LDAP
::
ownCloudUserNames
(
$ldap_users
);
}
return
$this
->
_users
;
}
...
...
@@ -125,13 +127,13 @@ class OC_USER_LDAP extends OCA\user_ldap\LDAP_Access implements OCP\UserInterfac
*/
public
function
userExists
(
$uid
){
//getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking.
$dn
=
OC_LDAP
::
username2dn
(
$uid
);
$dn
=
\
OC_LDAP
::
username2dn
(
$uid
);
if
(
!
$dn
)
{
return
false
;
}
//if user really still exists, we will be able to read his cn
$cn
=
OC_LDAP
::
readAttribute
(
$dn
,
'cn'
);
$cn
=
\
OC_LDAP
::
readAttribute
(
$dn
,
'cn'
);
if
(
!
$cn
||
empty
(
$cn
))
{
return
false
;
}
...
...
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