Guest User

Untitled

a guest
Aug 6th, 2018
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. from census.settings import Constants
  2. from ldap3 import Server, Connection, ALL, ALL_ATTRIBUTES, NTLM, SYNC
  3.  
  4.  
  5. class LDAPClient:
  6. def __init__(self,
  7. username=Constants.AD_USERNAME,
  8. password=Constants.AD_PASSWORD,
  9. base=Constants.AD_BASE,
  10. url=Constants.AD_SERVER):
  11. self.username = username
  12. self.password = password
  13. self.base = base
  14. self.url = url
  15. self.connection = None
  16.  
  17. def get_server(self):
  18. return Server(self.url, get_info=ALL)
  19.  
  20. def get_connection(self, server=None, client_strategy=SYNC,
  21. auto_bind=True, authentication=NTLM):
  22. if server is None:
  23. server = self.get_server()
  24. self.connection = Connection(server, user=self.username,
  25. password=self.password,
  26. authentication=authentication,
  27. client_strategy=client_strategy,
  28. auto_bind=auto_bind,
  29. read_only=True)
  30.  
  31. def paged_search(self, filter):
  32. if self.connection is None:
  33. self.get_connection()
  34. conn = self.connection
  35. return conn.extend.standard.paged_search(self.base,
  36. filter,
  37. attributes=ALL_ATTRIBUTES,
  38. generator=False)
Add Comment
Please, Sign In to add comment