Web2Py and ldap integration

67 views
Skip to first unread message

Davidiam

unread,
Jul 20, 2019, 1:30:00 AM7/20/19
to web2py-users
Hello,

I have read and implemented the recipe for Windows active directory ldap integration with Web2Py (http://www.web2py.com/books/default/chapter/29/09/access-control) and for the most part the documentation is clear except for the last bit where it refers to : 

from gluon.contrib.login_methods.ldap_auth import ldap_auth
auth
.settings.login_methods.append(ldap_auth(mode='ad',
   server
='my.domain.controller',
   base_dn
='ou=Users,dc=domain,dc=com'))


For me there are 2 things that aren't clear here :
1) Where should this code be inserted ?  In the default.py controller or in db.py or somewhere else ?
2) We have multiple domain controllers in our domain, do we need to supply a specific server for the server parameter ?

An example of implementing this with the welcome application would be appreciated, specifying the file which was modified. 

tomt

unread,
Jul 31, 2019, 11:53:24 PM7/31/19
to web2py-users
I have used ldap_auth successfully by implementing the following in models/db.py:
............................................................
from gluon.contrib.login_methods.ldap_auth import ldap_auth
...
db = DAL('mysql://mydb:mydb@localhost/password')
...
# --- end of web2py scaffolding ---
...
auth.settings.login_methods.append(ldap_auth(mode='ad', server='dc1.mydomain.com',base_dn='ou=users,dc=mydomain,dc=com'))
auth.settings.login_methods.append(ldap_auth(mode='ad', server='dc1.mydomain.com',base_dn='ou=operators,dc=mydomain,dc=com'))
...
db2 = DAL('oracle://myextradb/account@password', migrate=False)
............................................................

I found that I had to make extra database definitions after the append statements or I received a segmentation fault. 

I suspect that you could add another append statement to add an additional domain controller but I haven't tested this.

Hopefully this helps you - Tom

Davidiam

unread,
Aug 1, 2019, 9:57:00 AM8/1/19
to web2py-users
Thank you very much for the info. In the mean time we have decided to use shibboleth because we had a lot of issues with the python modules on Windows and because the project added the requirement for sso. I will keep your solution as a reference for the future.
Reply all
Reply to author
Forward
0 new messages