Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ldap3 import Server, Connection, ALL_ATTRIBUTES, MOCK_SYNC
- REAL_SERVER = 'ldap.jumpcloud.com'
- BASE_DN = 'ou=Users,o=5ca4e308c67f9237e6aa027b,dc=jumpcloud,dc=com'
- BIND_USER = 'LDAPSearch'
- BIND_PASSWORD = 'LDAPSearch'
- server = Server(REAL_SERVER)
- def get_groups(USER, PASS):
- try:
- connection = Connection(server, 'uid=%s,%s' % (BIND_USER, BASE_DN), BIND_PASSWORD, auto_bind=True)
- auth_connection = Connection(server, 'uid=%s,%s' % (USER, BASE_DN), PASS, auto_bind=True)
- if connection.search(BASE_DN, '(|(&(objectClass=*)(member=uid=%s,%s)))' % (USER, BASE_DN), attributes=ALL_ATTRIBUTES):
- groups = [entry.cn for entry in connection.entries]
- connection.unbind()
- return groups
- except:
- print('Error')
- def isAdmin(USER, PASS):
- for group in get_groups(USER, PASS):
- if group == "Administrators":
- return True
- return False
- def isTestGroup(USER, PASS):
- for group in get_groups(USER, PASS):
- if group == "testgroup":
- return True
- return False
- print(isAdmin('testuser', 'testuser'))
- print(isAdmin('normal', 'normal'))
- print(isTestGroup('testuser', 'testuser'))
- print(isTestGroup('normal', 'normal'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement