我在使用django-auth-ldap 1.2.8对ldap用户进行身份验证时遇到问题。 我可以按照以下说明使用Apache Directory Studio登录:
hostname: private.pai.org
port: 389
Auth: Bind DN – cn=testuser1@test.com,ou=users,dc=ldap,dc=pai,dc=org`
Bind Password: thePassword
但是在尝试使用以下设置的Django时:
import ldap
from django_auth_ldap.config import LDAPSearch,GroupOfUniqueNamesType
# logging
import logging
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
# where to search
AUTH_LDAP_SERVER_URI = "ldap://private.pai.org:389"
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=ldap,dc=pai,dc=org",
ldap.SCOPE_SUBTREE, "(cn=%(user)s)"
)
# group settings
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=ldap,dc=pai,dc=org",
ldap.SCOPE_SUBTREE, "(objectClass=GroupOfUniqueNames)"
)
AUTH_LDAP_GROUP_TYPE = GroupOfUniqueNamesType()
# disable caching
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 0
AUTH_LDAP_CACHE_GROUPS = 0
# bind user to django groups
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": ("ou=users,dc=ldap,dc=pai,dc=org" ),
"is_staff": ("ou=users,dc=ldap,dc=pai,dc=org")
}
AUTH_LDAP_USER_ATTR_MAP = {
"email": "cn"
}
我遇到以下错误
search_s('ou=users,dc=ldap,dc=pai,dc=org', 2, '(cn=testuser1@test.com)') raised NO_SUCH_OBJECT({'desc': u'No such object'},)
看起来ou中找不到cn? 有人可以说如何克服这个错误吗?