1
1
from bda .ldap import LDAPProps , LDAPNode
2
2
from bda .ldap import BASE , ONELEVEL , SUBTREE
3
3
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
+
4
24
class LDAPUsersConfig (object ):
5
25
"""Define how users look and where they are
6
26
"""
@@ -38,7 +58,7 @@ def ldapUsersConfigFromLUF(luf):
38
58
)
39
59
return uc
40
60
41
- class LDAPUser (LDAPNode ):
61
+ class LDAPUser (LDAPPrincipal ):
42
62
"""An ldap user
43
63
44
64
XXX: should this be a node or an adpater for a node?
@@ -51,10 +71,6 @@ class LDAPUser(LDAPNode):
51
71
two-stage __setitem__ on LDAPNodeAttributes or LDAPUsers needs to be
52
72
adapter around a real normal node.
53
73
"""
54
- @property
55
- def id (self ):
56
- return self .__name__
57
-
58
74
@property
59
75
def login (self ):
60
76
return self .attrs [self .__parent__ ._login_attr ]
@@ -67,21 +83,15 @@ def passwd(self, oldpw, newpw):
67
83
"""
68
84
self ._session .passwd (self .DN , oldpw , newpw )
69
85
70
- class LDAPUsers (LDAPNode ):
71
- """An ldap users collection
86
+ class LDAPUsers (LDAPPrincipals ):
87
+ """Manage LDAP users
72
88
"""
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
82
92
self ._ChildClass = LDAPUser
83
93
if self ._login_attr is not self ._key_attr :
84
- self ._seckey_attrs = (config .login_attr ,)
94
+ self ._seckey_attrs = (cfg .login_attr ,)
85
95
86
96
def idbylogin (self , login ):
87
97
return self ._seckeys [self ._login_attr ][login ]
0 commit comments