changeset 865:6127a2617fc8

cfg.ldap_filter: make ldap filter string configurable
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 20 Jun 2006 21:06:21 +0200
parents b4006d50d2dc
children b270396abba9
files MoinMoin/auth/ldap_login.py wiki/config/more_samples/ldap_smb_farmconfig.py
diffstat 2 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/auth/ldap_login.py	Tue Jun 20 21:04:35 2006 +0200
+++ b/MoinMoin/auth/ldap_login.py	Tue Jun 20 21:06:21 2006 +0200
@@ -47,7 +47,13 @@
         l.simple_bind_s(ldap_binddn.encode(coding), ldap_bindpw.encode(coding))
         if verbose: request.log("LDAP: Bound with binddn %s" % ldap_binddn)
 
-        filterstr = "(%s=%s)" % (cfg.ldap_name_attribute, username)
+        # normal usage: ldap_filter = "(%(ldap_name_attribute)s=%(username)s)"
+        # you can also do more complex filtering like:
+        # "(&(%(ldap_name_attribute)s=%(username)s)(memberOf=CN=WikiUsers,OU=Groups,DC=example,DC=org))"
+        filterstr = cfg.ldap_filter % {
+            'ldap_name_attribute': cfg.ldap_name_attribute,
+            'username': username,
+        }
         if verbose: request.log("LDAP: Searching %s" % filterstr)
         lusers = l.search_st(cfg.ldap_base, cfg.ldap_scope,
                              filterstr.encode(coding), timeout=cfg.ldap_timeout)
--- a/wiki/config/more_samples/ldap_smb_farmconfig.py	Tue Jun 20 21:04:35 2006 +0200
+++ b/wiki/config/more_samples/ldap_smb_farmconfig.py	Tue Jun 20 21:06:21 2006 +0200
@@ -93,6 +93,7 @@
     
     ldap_base = 'ou=SOMEUNIT,dc=example,dc=org' # base DN we use for searching
     ldap_scope = ldap.SCOPE_SUBTREE # scope of the search we do
+    ldap_filter = "(%(ldap_name_attribute)s=%(username)s)" # available: ldap_name_attribute (see below) and username 
     ldap_name_attribute = 'sAMAccountName' # ldap attribute we get the user name from
     ldap_email_attribute = 'mail' # ldap attribute we get the email address from
     ldap_coding = 'utf-8' # coding used for ldap queries and result values