LDAP support

107 views
Skip to first unread message

b.pin...@gmail.com

unread,
Jul 15, 2013, 8:53:18 AM7/15/13
to moz...@googlegroups.com
Hi members of the moztrap group,

I recently decided that Moztrap would be a great addition to the set of tools we are using as a
team to manage testing efforts. I was pleasantly surprised by the ease of installation
and deployment. The UI is very responsive as well.

The only blocker I encountered was the lack of out-of-the-box support for LDAP. I managed to
overcome that by manually adding django-auth-ldap and python-ldap to the list of
virtualenv requirements. This seems to work with django-auth-ldap 1.1.4.

The only issue I'm experiencing is during "create/add" operations on model objects.
My LDAP-originating user is not an object of the User class. More explicitly, I get:

ValueError at /manage/product/add/

Cannot assign "<django.utils.functional.SimpleLazyObject object at 0x2fd4d90>": "Product.created_by" must be a "User" instance.

I think I have two options here - either try and use Django 1.5 under the hood
or write my own auth backend that would extend django-auth-ldap.

I would very much appreciate any help or pointers - that's my first encounter
with LDAP implementation in Python.


Thanks in advance,
Regards

Blazej Pindelski

b.pin...@gmail.com

unread,
Jul 17, 2013, 9:13:14 AM7/17/13
to moz...@googlegroups.com
Answering myself, maybe someone will find it useful :)

Managed to fix the error by overriding the get_user_model function from django_auth_ldap.backend
Adding

    from django_auth_ldap import backend
    backend.get_user_model = lambda: User

to moztrap/model/core/auth.py seems to solve the issue (in a stop-gap manner).

Cathy Dai

unread,
Nov 20, 2013, 5:15:28 AM11/20/13
to moz...@googlegroups.com
Hi Blazej,

I added both django-auth-ldap and python-ldap to moztrap server and configured base.py to have AUTH_LDAP_ settings as below. Also, I added the lines you mentioned in auth.py. But as I use ldap user to log in Moztrap, it reports "
  • Please enter a correct username and password. Note that both fields are case-sensitive.
" just as no LDAP is integrated at all. Do I miss anything else important?

AUTHENTICATION_BACKENDS = [
    "moztrap.model.core.auth.ModelBackend",
    "moztrap.model.core.auth.BrowserIDBackend",
    "django_auth_ldap.backend.LDAPBackend",
    "django.contrib.auth.backends.ModelBackend",
    ]

AUTH_LDAP_SERVER_URI = "ldap://xxx"
AUTH_LDAP_BIND_DN = "cn=<base_account>,dc=xx,dc=xxx,dc=com"
AUTH_LDAP_BIND_PASSWORD = "<base_password>"

AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=user,dc=xxx,dc=xxx,dc=com",ldap.SCOPE_SUBTREE, "(&(objectCategory=person)(objectClass=user)(sAMAccountName=%(user)s))")

AUTH_LDAP_USER_ATTR_MAP = {
   "first_name":"givenName",
   "last_name":"sn",
   "email":"mail"
}

Thanks,
Cathy 
Reply all
Reply to author
Forward
0 new messages