summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarian Sigler <m@qjym.de>2012-09-24 03:10:02 +0200
committerMarian Sigler <m@qjym.de>2012-09-24 03:10:02 +0200
commit2a5d01f833014258cad8fefa2a7a519738e5dbf7 (patch)
treea0437b2f7269510fa7df4bc29bb6a70abfa1cc24
parent3136cb1c3d2000e414a8cf0c8bb6a267dc67eb51 (diff)
parent42595026cec2d779f540cb87bf28ab2aa0daf608 (diff)
downloadweb-2a5d01f833014258cad8fefa2a7a519738e5dbf7.tar.gz
web-2a5d01f833014258cad8fefa2a7a519738e5dbf7.tar.bz2
web-2a5d01f833014258cad8fefa2a7a519738e5dbf7.zip
Merge branch 'master' of ssh://git.spline.de/account-web
Conflicts: account.py
-rw-r--r--account.py33
1 files changed, 25 insertions, 8 deletions
diff --git a/account.py b/account.py
index d4e56a6..e8a9aeb 100644
--- a/account.py
+++ b/account.py
@@ -6,7 +6,7 @@ LDAP_HOST = 'ldap://localhost:5678'
LDAP_BASE_DN = 'dc=account,dc=spline,dc=inf,dc=fu-berlin,dc=de'
LDAP_ADMIN_USER = 'admin'
LDAP_ADMIN_PASS = 'admin'
-SERVICES = ['foren','jabber', 'gitlab']
+SERVICES = ['foren','jabber', 'gitlab', 'osqa']
@@ -17,7 +17,7 @@ class AccountService:
its own authentication request (bind).
To test you stuff against our test setup use Port-Forwarding
- ssh spline -L 5678:vm-splinux:389 -N
+ ssh spline -L 5678:vm-acocunt:389 -N
* register a new user
>> service = AccountService(LDAP_HOST, LDAP_BASE_DN, ADMIN_USER, ADMIN_PW, SERVICES)
@@ -43,8 +43,10 @@ class AccountService:
* find accounts
>> service = AccountService(LDAP_HOST, LDAP_BASE_DN, LDAP_ADMIN_USER, LDAP_ADMIN_PASS, SERVICES)
- >> all_accounts = service.find()
+ >> all_accounts = service.find() # find all accounts
>> print([x.uid for x in all_accounts])
+ >> service.find_by_uid('test') # find users by uid
+ >> service.find_by_mail('test@test.de') # find users by mail
"""
def __init__(self, ldap_host, base_dn, admin_user, admin_pass, services):
@@ -81,19 +83,31 @@ class AccountService:
return acc
+ def find_by_uid(self, uid):
+ return self.find({'uid':uid})
- def find(self, filterstr = '(objectClass=*)'):
+ def find_by_mail(self, mail):
+ return self.find({'mail':mail})
+
+ def find(self, filters = {}):
"""
- Find accounts with raw ldap filter syntax
+ Find accounts by a given filter with key:value semantic)
"""
- self._bind_as_admin()
+ self._bind_anonymous()
dn = 'ou=users,%s' % self.base_dn
+
+ filters['objectClass'] = 'inetOrgPerson'
+ filter_as_list = ['(%s=%s)' % (k,v) for k,v in filters.items()]
+ filterstr = ''.join(filter_as_list)
+ if len(filter_as_list) > 1:
+ filterstr = '(&%s)' % filterstr
+
data = self.connection.search_s(dn,ldap.SCOPE_SUBTREE,filterstr)
accounts = []
- for a in data[1:]:
- accounts.append(Account(a[1]['uid'], a[1]['mail']))
+ for a in data:
+ accounts.append(Account(a[1]['uid'],a[1]['mail']))
self._unbind()
@@ -172,6 +186,9 @@ class AccountService:
def _bind_as_admin(self):
self._bind('cn=%s,%s' % (self.admin_user, self.base_dn), self.admin_pass)
+ def _bind_anonymous(self):
+ self._bind('','')
+
def _unbind(self):
self.connection.unbind_s()