Advertisement
Guest User

Untitled

a guest
Apr 6th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. from ldap3 import Server, Connection, ALL_ATTRIBUTES, MOCK_SYNC
  2.  
  3. REAL_SERVER = 'ldap.jumpcloud.com'
  4. BASE_DN = 'ou=Users,o=5ca4e308c67f9237e6aa027b,dc=jumpcloud,dc=com'
  5. BIND_USER = 'LDAPSearch'
  6. BIND_PASSWORD = 'LDAPSearch'
  7.  
  8. server = Server(REAL_SERVER)
  9.  
  10. def get_groups(USER, PASS):
  11. try:
  12. connection = Connection(server, 'uid=%s,%s' % (BIND_USER, BASE_DN), BIND_PASSWORD, auto_bind=True)
  13. auth_connection = Connection(server, 'uid=%s,%s' % (USER, BASE_DN), PASS, auto_bind=True)
  14.  
  15. if connection.search(BASE_DN, '(|(&(objectClass=*)(member=uid=%s,%s)))' % (USER, BASE_DN), attributes=ALL_ATTRIBUTES):
  16. groups = [entry.cn for entry in connection.entries]
  17.  
  18. connection.unbind()
  19. return groups
  20. except:
  21. print('Error')
  22.  
  23. def isAdmin(USER, PASS):
  24. for group in get_groups(USER, PASS):
  25. if group == "Administrators":
  26. return True
  27. return False
  28.  
  29. def isTestGroup(USER, PASS):
  30. for group in get_groups(USER, PASS):
  31. if group == "testgroup":
  32. return True
  33. return False
  34.  
  35.  
  36. print(isAdmin('testuser', 'testuser'))
  37. print(isAdmin('normal', 'normal'))
  38. print(isTestGroup('testuser', 'testuser'))
  39. print(isTestGroup('normal', 'normal'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement