我一直在尝试使用此处https://djangosnippets.org/snippets/2899/找到的代码段来生成ldap后端,但是当我现在登录管理页面时出现错误
TypeError at /admin/login/
'NoneType' object has no attribute '__getitem__'
Request Method: POST
Request URL: http://it.intranet.com/admin/login/?next=/admin/
Django Version: 1.9.6
Exception Type: TypeError
Exception Value:
'NoneType' object has no attribute '__getitem__'
Exception Location: /var/www/infternal/infternal/backend.py in get_or_create_user, line 69
Python Executable: /usr/bin/python
Python Version: 2.7.5
Python Path:
['/var/www/infternal',
'/usr/lib64/python27.zip',
'/usr/lib64/python2.7',
'/usr/lib64/python2.7/plat-linux2',
'/usr/lib64/python2.7/lib-tk',
'/usr/lib64/python2.7/lib-old',
'/usr/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7/site-packages',
'/usr/lib64/python2.7/site-packages/gtk-2.0',
'/usr/lib/python2.7/site-packages']
Server time: Wed, 18 May 2016 11:54:09 +0000
我认为这是因为我没有成功连接到ldap服务器?
我该如何测试?
后端代码完全从代码段中复制。 我的settings.py如下
我唯一不确定的是AD_CERT_FILE字段,我不知道这是什么或者放什么,但是因为我没有使用ssl我认为不需要它?
# active directory authentication module
AD_DNS_NAME = 'example.domain.com' # FQDN of your DC (using just the Domain Name to utilize all DC's)
# If using non-SSL use these
AD_LDAP_PORT=389
AD_LDAP_URL='ldap://%s:%s' % (AD_DNS_NAME,AD_LDAP_PORT)
# If using SSL use these:
#AD_LDAP_PORT=636
#AD_LDAP_URL='ldaps://%s:%s' % (AD_DNS_NAME,AD_LDAP_PORT)
AD_SEARCH_DN = 'DC=example,DC=domain,DC=com'
AD_NT4_DOMAIN = 'example.domain.COM'
AD_SEARCH_FIELDS = ['mail','givenName','sn','sAMAccountName','memberOf']
AD_MEMBERSHIP_ADMIN = ['ITService_App_Admin'] # this ad group gets superuser status in django
# only members of this group can access
AD_MEMBERSHIP_REQ = AD_MEMBERSHIP_ADMIN + ['GS_ITsupport',
'GS_ITDevelopment',]
AD_CERT_FILE = '/certs/certfile' # this is the certificate of the Certificate Authority issuing your DCs certificate
AD_DEBUG=True #Set to false for prod, Slows things down ALOT
AD_DEBUG_FILE='/tmp/ldap.debug'
AUTHENTICATION_BACKENDS = (
'infternal.backend.ActiveDirectoryAuthenticationBackend',
'django.contrib.auth.backends.ModelBackend', #Comment out to prevent authentication from DB
)
答案 0 :(得分:0)
这不是你的错,你得到的TypeError消息不是很有用。
此特定代码段要求您在Django中镜像相关的AD组(您必须使用管理员在Django中创建相同的组)。这些组不应该具有相同的名称,而是使用以下约定(来自源中的注释):
我们的AD小组与Django小组进行了镜像,但以“ID”开头(注意空格)
如果您的Django组名为“ITsupport”,那么您的AD组必须被称为“ID ITsupport”,依此类推。
如果要修改此行为,则必须更改第142行的正则表达式:
re.compile(r'^CN=ID (?P<groupName>[\w|\d|\s]+),')
例如:
re.compile(r'^CN=(?P<groupName>MyADGroup|MyOtherAdGroup|AndSoOn),')
只需将原始表达式替换为由管道(|
)分隔的AD组列表。您仍然需要使用Django管理员或shell创建组。