Hi all,
For some reason, my LDAP authentication quit working when I deployed my Django site to another server. Here are my settings:
import ldap
from django_auth_ldap.config import LDAPSearch
#LDAP SETUP
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
AUTH_LDAP_SERVER_URI = "ldap://
ldap.mycompany.com"
AUTH_LDAP_BIND_DN = "CN=MyCompany ,OU=cabletest,OU=Teamwork,OU=community,DC=cablelabs,DC=com"
AUTH_LDAP_BIND_PASSWORD = "Password"
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=community,dc=mycompany,dc=com",ldap.SCOPE_SUBTREE, "(sAMAccountName=%(user)s)")
AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName", "last_name": "sn","username":"sAMAccountName","email": "mail"}
AUTH_LDAP_CONNECTION_OPTIONS = {
ldap.OPT_REFERRALS: 0
}
AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = True
It looks like everything is authenticating properly. If I intentionally use bad credentials, I get taken back to the login screen, but when I use good credentials, I'm brought back to the main page which should happen. The only problem is that and IF statements that look to see if the user is authenticated fail. For instance, in my template, I have:
<div id="header-bottom">
<div id='dashboard'>Dashboard</div>
<div id='authinfo'>
{% if context.user.is_authenticated %}
Welcome {{ context.user.first_name }}
(<a href="/logout">Logout</a>)
{% else %}
<a href="/login">Login</a>
{% endif %}
</div>
</div>
Always executes the 'else' portion.
My error logs show the following:
[Wed Apr 10 08:27:10 2013] [error] search_s('ou=community,dc=mycompany,dc=com', 2, '(sAMAccountName=%(user)s)') returned 1 objects: cn=theuser ,ou=it,ou=employees,ou=internal,ou=community,dc=mycompany,dc=com
[Wed Apr 10 08:27:10 2013] [error] Populating Django user jakirby
[Wed Apr 10 08:27:10 2013] [error] Django user jakirby does not have a profile to populate
Can anyone see what I may be doing wrong?
Jason