python – 使用ldap配置文件在django admin中进行身份验证
我正在开发一个Django应用程序,它需要支持LDAP身份验证直接进入默认管理页面.
我已经集成了 django-auth-ldap并跟随 documentation直到我能理解它. 我已经使用OpenLDAP和php图形界面配置了本地LDAP服务器(我也可以使用ldif文件配置).当我尝试登录管理页面时,Django会在其中找到本地服务器及其用户对象,并且还可以识别用户所属的组.尽管如此,我无法登录.我发现的错误:
在Admin界面中,无法登录. # - - - - LDAP CONFIGURATION - - - - # # # Importing ldap libraries and applications import ldap from django_auth_ldap.config import LDAPSearch,GroupOfNamesType,PosixGroupType # ...connecting to ldap server (local environment uses IP) AUTH_LDAP_SERVER_URI = "ldap://10.0.2.15" # ...account to enter into ldap server (anonymous is not always allowed) #AUTH_LDAP_BIND_DN = "cn=admin,dc=whiteqube" #AUTH_LDAP_BIND_PASSWORD = "root" # ...path where to start to search groups AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=groups,dc=whiteqube",ldap.SCOPE_SUBTREE,# allow searching from current node to all nodes below "(objectClass=posixGroup)" # type of object ) AUTH_LDAP_GROUP_TYPE = PosixGroupType() # a posixGroup is identified by the keyword "cn" into ldap server # ...associations between ldap and django groups AUTH_LDAP_USER_FLAGS_BY_GROUP = { "is_active": "cn=active,ou=groups,"is_staff": "cn=staff,"is_superuser": "cn=superuser,dc=whiteqube" } AUTH_LDAP_PROFILE_FLAGS_BY_GROUPS = { "is_awesome": ["cn=awesome,dc=whiteqube"] } # ...node where to start to search users AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,# allow searching from current node to all nodes below "(cn=%(user)s)" #"(objectClass=posixAccount)" #"(objectClass=inetOrgPerson)" ) # Keep ModelBackend around for per-user permissions and maybe a local # superuser. AUTHENTICATION_BACKENDS = ( 'django_auth_ldap.backend.LDAPBackend','django.contrib.auth.backends.ModelBackend',) # Enable debug for ldap server connection logger = logging.getLogger('django_auth_ldap') logger.addHandler(logging.StreamHandler()) logger.setLevel(logging.DEBUG) # - - - - END LDAP CONFIGURATION - - - - # 我的LDAP充满了这些对象: > ou = groups,dc = whitecube > > ou = users,dc = whiteqube 其中“groups”和“users”是OrganizationalUnit,“staff”和“superuser”是posixGroup,“sonia”是posixAccount. 我确定ldap对象被配置为必须,因为Django调试识别用户的组依赖. Ps:当我使用django本地帐户时,我可以登录管理员. 我错在哪里?我错过了任何进一步的属性配置吗? 解决方法
我终于搞定了!
调试:用户必须属于所有组(活动,工作人员,超级用户)才能登录管理界面,至少已创建新的个人组. 在我的上一篇文章中,settings.py和LDAP树的配置是正确的,因此您可以保留有关如何创建LDAP并在django应用程序中实现的信息.请记住:如果您使用默认组,请在所有组中添加用户以允许管理员登录. 谢谢.再见 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |