-
-
Save westfeld/bb1d5e8727ce13910623933e041e9782 to your computer and use it in GitHub Desktop.
ldaptor test using Python 3.6.6 and twisted 19.2.0 and ldaptor 19.0.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.internet import reactor, defer | |
from ldaptor.protocols.ldap import ldapclient, ldapsyntax, ldapconnector | |
@defer.inlineCallbacks | |
def example(): | |
# The following arguments may be also specified as unicode strings | |
# but it is recommended to use byte strings for ldaptor objects | |
serverip = b'ldap.server.com' | |
basedn = b'dc=my-company,dc=com' | |
binddn = b'LDAP_USERNAME' | |
bindpw = b'LDAP_PASSWORD' | |
query = b'(cn=Joe)' | |
c = ldapconnector.LDAPClientCreator(reactor, ldapclient.LDAPClient) | |
overrides = {basedn: (serverip, 389)} | |
client = yield c.connect(basedn, overrides=overrides) | |
# startTLS fails | |
resp = yield client.startTLS() | |
yield client.bind(binddn, bindpw) | |
o = ldapsyntax.LDAPEntry(client, basedn) | |
results = yield o.search(filterText=query) | |
for entry in results: | |
print(entry.getLDIF()) | |
if __name__ == '__main__': | |
df = example() | |
df.addErrback(lambda err: err.printTraceback()) | |
df.addCallback(lambda _: reactor.stop()) | |
reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment