2

I'm trying to write python code which will use LDAP module to validate LDAP connection:

import configuration
from ldap3 import Server, Connection, SIMPLE, SYNC, ALL

server = Server(configuration.LDAP_SERVER, port=XXXX, get_info=ALL)
c = Connection(server, authentication=SIMPLE, user=configuration.LDAP_USER, password=configuration.LDAP_PASS, check_names=True, lazy=False, client_strategy=SYNC, raise_exceptions=False)
c.open()
c.bind()

When running the code, I'm getting:

{'result': 49, 'description': 'invalidCredentials', 'dn': '', 'message': '80090308: LdapErr: DSID-0C09042A, comment: AcceptSecurityContext error, data 52e, v3839\x00', 'referrals': None, 'saslCreds': None, 'type': 'bindResponse'}

I'm sure the user and password I'm using are correct. can you advise what's wrong with the code?

A. Man
  • 337
  • 3
  • 14

1 Answers1

5

I had to google it, but eventually, the below code worked:

import configuration
from ldap3 import Server, Connection, SIMPLE, SYNC, ALL
server = Server(configuration.LDAP_SERVER, get_info=ALL)
conn = Connection(server, "CN=XXXXX,OU=XXX;OU=XXXX,OU=Users,XX=People,XX=corp,XX=[organization],XX=XXX", password=configuration.LDAP_PASS, auto_bind=False)
conn.bind()
print(conn)
A. Man
  • 337
  • 3
  • 14
  • Depending on LDAP server settings, ```auto_bind=False``` may be necessary to avoid a AcceptSecurityContext error prior to getting to ```conn.bind()```, even if the user/pwd info is in the ```Connection()``` call – mwag Mar 25 '20 at 16:44
  • In the latest version, it's changed as `auto_bind='NONE'` – Saikat Aug 19 '22 at 05:07
  • What are you using for the password? Is that something given by your organization? – Jam1 Oct 06 '22 at 05:24