Skip to content

Commit f81d059

Browse files
author
chaoflow
committed
LDAPPrincipals factor out, start of LDAPGroups
git-svn-id: https://svn.plone.org/svn/collective/bda.ldap/trunk@121990 db7f04ef-aaf3-0310-a811-c281ed44c4ad
1 parent 867f0e4 commit f81d059

File tree

2 files changed

+56
-17
lines changed

2 files changed

+56
-17
lines changed

src/bda/ldap/groups.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from bda.ldap import LDAPProps, LDAPNode
2+
from bda.ldap import BASE, ONELEVEL, SUBTREE
3+
from bda.ldap.users import LDAPPrincipal, LDAPPrincipals
4+
5+
class LDAPGroupsConfig(object):
6+
"""Define how users look and where they are
7+
"""
8+
def __init__(self,
9+
props,
10+
baseDN='',
11+
id_attr='cn',
12+
scope=ONELEVEL,
13+
queryFilter='(objectClass=groupOfNames)'):
14+
self.props = props
15+
self.baseDN = baseDN
16+
self.id_attr = id_attr
17+
self.scope = scope
18+
self.queryFilter = queryFilter
19+
20+
class LDAPGroup(LDAPPrincipal):
21+
"""An LDAP group
22+
"""
23+
24+
class LDAPGroups(LDAPPrincipals):
25+
"""Manage LDAP groups
26+
"""
27+
def __init__(self, cfg):
28+
super(LDAPGroups, self).__init__(cfg)
29+
self._ChildClass = LDAPGroup

src/bda/ldap/users.py

+27-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
from bda.ldap import LDAPProps, LDAPNode
22
from bda.ldap import BASE, ONELEVEL, SUBTREE
33

4+
class LDAPPrincipal(LDAPNode):
5+
"""Superclass for LDAPUser and LDAPGroup
6+
"""
7+
@property
8+
def id(self):
9+
return self.__name__
10+
11+
class LDAPPrincipals(LDAPNode):
12+
"""Superclass for LDAPUsers and LDAPGroups
13+
"""
14+
# principals have ids
15+
ids = LDAPNode.keys
16+
17+
def __init__(self, cfg):
18+
super(LDAPPrincipals, self).__init__(name=cfg.baseDN, props=cfg.props)
19+
self._search_filter = cfg.queryFilter
20+
self._search_scope = cfg.scope
21+
self._key_attr = cfg.id_attr
22+
23+
424
class LDAPUsersConfig(object):
525
"""Define how users look and where they are
626
"""
@@ -38,7 +58,7 @@ def ldapUsersConfigFromLUF(luf):
3858
)
3959
return uc
4060

41-
class LDAPUser(LDAPNode):
61+
class LDAPUser(LDAPPrincipal):
4262
"""An ldap user
4363
4464
XXX: should this be a node or an adpater for a node?
@@ -51,10 +71,6 @@ class LDAPUser(LDAPNode):
5171
two-stage __setitem__ on LDAPNodeAttributes or LDAPUsers needs to be
5272
adapter around a real normal node.
5373
"""
54-
@property
55-
def id(self):
56-
return self.__name__
57-
5874
@property
5975
def login(self):
6076
return self.attrs[self.__parent__._login_attr]
@@ -67,21 +83,15 @@ def passwd(self, oldpw, newpw):
6783
"""
6884
self._session.passwd(self.DN, oldpw, newpw)
6985

70-
class LDAPUsers(LDAPNode):
71-
"""An ldap users collection
86+
class LDAPUsers(LDAPPrincipals):
87+
"""Manage LDAP users
7288
"""
73-
# principals have ids
74-
ids = LDAPNode.keys
75-
76-
def __init__(self, config):
77-
super(LDAPUsers, self).__init__(name=config.baseDN, props=config.props)
78-
self._search_filter = config.queryFilter
79-
self._search_scope = config.scope
80-
self._key_attr = config.id_attr
81-
self._login_attr = config.login_attr
89+
def __init__(self, cfg):
90+
super(LDAPUsers, self).__init__(cfg)
91+
self._login_attr = cfg.login_attr
8292
self._ChildClass = LDAPUser
8393
if self._login_attr is not self._key_attr:
84-
self._seckey_attrs = (config.login_attr,)
94+
self._seckey_attrs = (cfg.login_attr,)
8595

8696
def idbylogin(self, login):
8797
return self._seckeys[self._login_attr][login]

0 commit comments

Comments
 (0)