Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from census.settings import Constants
- from ldap3 import Server, Connection, ALL, ALL_ATTRIBUTES, NTLM, SYNC
- class LDAPClient:
- def __init__(self,
- username=Constants.AD_USERNAME,
- password=Constants.AD_PASSWORD,
- base=Constants.AD_BASE,
- url=Constants.AD_SERVER):
- self.username = username
- self.password = password
- self.base = base
- self.url = url
- self.connection = None
- def get_server(self):
- return Server(self.url, get_info=ALL)
- def get_connection(self, server=None, client_strategy=SYNC,
- auto_bind=True, authentication=NTLM):
- if server is None:
- server = self.get_server()
- self.connection = Connection(server, user=self.username,
- password=self.password,
- authentication=authentication,
- client_strategy=client_strategy,
- auto_bind=auto_bind,
- read_only=True)
- def paged_search(self, filter):
- if self.connection is None:
- self.get_connection()
- conn = self.connection
- return conn.extend.standard.paged_search(self.base,
- filter,
- attributes=ALL_ATTRIBUTES,
- generator=False)
Add Comment
Please, Sign In to add comment