-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathldap_example.py
More file actions
53 lines (38 loc) · 1.25 KB
/
ldap_example.py
File metadata and controls
53 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Short ldap example...
Test ldap server is...
Server: ldap.forumsys.com
Port: 389
Bind DN: cn=read-only-admin,dc=example,dc=com
Bind Password: password
All user passwords are password.
You may also bind to individual Users (uid) or the two Groups (ou) that include:
ou=mathematicians,dc=example,dc=com
riemann
gauss
euler
euclid
ou=scientists,dc=example,dc=com
einstein
newton
galieleo
tesla
For more details see http://www.forumsys.com/en/tutorials/integration-how-to/ldap/online-ldap-test-server/
Thanks for the free server!!!
"""
import ldap
import json
LDAP_SERVER = 'ldap.forumsys.com'
DN_READONLY_ADMIN = 'cn=read-only-admin,dc=example,dc=com'
DN_MATHEMATICIANS = 'ou=mathematicians,dc=example,dc=com'
DN_SCIENTISTS = 'ou=scientists,dc=example,dc=com'
DN_EINSTEIN = 'uid=einstein,dc=example,dc=com'
try:
conn = ldap.initialize('ldap://{server_url}'.format(server_url=LDAP_SERVER))
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_ALLOW) # allow self signed for this test server.
conn.start_tls_s()
print conn.bind_s(DN_READONLY_ADMIN, 'password')
print "I am connected as {dn}".format(dn=conn.whoami_s())
print json.dumps(conn.search_s( DN_SCIENTISTS, ldap.SCOPE_SUBTREE, '(objectclass=*)', ['*'] ), indent=4)
finally:
conn.unbind()