Friday, October 14, 2011

How to set up web2py + ldap with Windows Active Directory

This is a recipe to use web2py + ldap in the real world.

Install python-ldap
1. Download and install  python-ldap (e.g. python-ldap-2.4.3.win32-py2.7)

Edit models/db.py
2. edit auth.define_tables() to allow login with username and not email.


auth.define_tables(username=True)

3. Add the following at the bottom of page.
Replace server and base_dn to your setting.

# all we need is login
auth.settings.actions_disabled=['register','change_password','request_reset_password','retrieve_username','profile']

# you don't have to remember me
auth.settings.remember_me_form = False

# ldap authentication and not save password on web2py
from gluon.contrib.login_methods.ldap_auth import ldap_auth
auth.settings.login_methods = [ldap_auth(mode='ad',
   server='OchibaServer',
   base_dn='dc=ochiba,dc=com')]

4. Result










7 comments:

  1. This was a really great tutorial.
    How easy when knowing what to do.

    Regards Falk

    ReplyDelete
  2. I just want to add that if you are using 1.99.4 this won't work. It's not due to anything wrong with the instructions, it's a bug. There's a fix for it here.

    http://code.google.com/p/web2py/issues/detail?id=565&can=1&q=ldap

    ReplyDelete
    Replies
    1. @Derek - that fix did not work for me.

      Delete
  3. Derek,

    Thank you for the comment. Yes I maded the fix :)
    1.99.6 will be released next few weeks which includes this patch so we will be fine.

    ReplyDelete
  4. I am a newbie. I followed these instructions and I am not getting the login form. where do I add that ?

    ReplyDelete
  5. ldap online training| ldap training| call us+919000444287 ...
    http://www.21cssindia.com/courses/ldap-online-training-103.html
    ఈ పేజీని అనువదించు
    LDAP Online Training, LDAP training, LDAP course contents, LDAP , call us: +919000444287,dharani@21cssindia.com.
    course contents, biztalk admin enquiry, ...Courses at 21st Century Software Solutions
    Talend Online Training -Hyperion Online Training - IBM Unica Online Training -
    Siteminder Online Training - SharePoint Online Training - Informatica Online Training
    SalesForce Online Training - Many more… | Call Us +917386622889
    Visit: http://www.21cssindia.com/courses.html

    ReplyDelete