我正試圖對LDAP服務器驗證Django應用程序,並且正在接收一些奇怪的行爲。請記住,我對LDAP不太瞭解,所以如果我濫用了某些LDAP術語,請原諒。另請注意,在此問題中,my_domain是我公司的域名,user_id是認證用戶的用戶名。LDAP:'填充Django用戶'導致錯誤'INSUFFICIENT_ACCESS'
這裏是我的settings.py配置文件的相關部分:
AUTHENTICATION_BACKENDS = [
'django_auth_ldap.backend.LDAPBackend'
]
AUTH_LDAP_SERVER_URI = 'ldaps://ipa.my_domain.com:636'
AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,cn=users,cn=accounts,dc=my_domain,dc=com"
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": "cn=all,cn=groups,cn=accounts,dc=my_domain,dc=com",
"is_staff": "cn=all,cn=groups,cn=accounts,dc=my_domain,dc=com",
"is_superuser": "cn=all,cn=groups,cn=accounts,dc=my_domain,dc=com"
}
AUTH_LDAP_ALWAYS_UPDATE_USER = True
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType()
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("cn=groups,cn=accounts,dc=my_domain,dc=com",
ldap.SCOPE_SUBTREE, "(objectClass=member)"
)
AUTH_LDAP_GLOBAL_OPTIONS = {
ldap.OPT_X_TLS_REQUIRE_CERT: False,
ldap.OPT_REFERRALS: False,
}
AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName", "last_name": "sn"}
當我嘗試登錄到我的申請,我收到此錯誤:
Populating Django user user_id search_s('uid=user_id,cn=users,cn=accounts,dc=my_domain,dc=com', 0, '(objectClass=*)') returned 1 objects: uid=user_id,cn=users,cn=accounts,dc=my_domain,dc=com Caught LDAPError while authenticating user_id: INSUFFICIENT_ACCESS({'desc': 'Insufficient access'},)
然而,當我將此標誌從True切換爲False:
AUTH_LDAP_ALWAYS_UPDATE_USER = False
身份驗證成功。現在這裏是奇怪的部分:即使身份驗證成功,我的屬性也不會映射到我的Django用戶對象(在AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName", "last_name": "sn"}
中指定的對象)。當我手動檢查request.user.ldap_user.attrs
時,所有屬性都在那裏。
現在問題來了,'填充Django用戶'究竟是什麼意思?什麼導致'INSUFFICIENT_ACCESS'錯誤,爲什麼翻轉那個標誌修復(隱藏?)這個問題?
謝謝。