2010-02-16 2 views
2

Django 응용 프로그램이 python-ldap 라이브러리 (ldap_groups django 응용 프로그램)를 사용하고 Windows 2003 가상 시스템 도메인의 Active Directory에 대해 사용자를 추가해야합니다. 우분투 가상 머신에서 실행되는 응용 프로그램은 Windows 도메인의 구성원이 아닙니다. 여기 ldap가 수행 할 오류 발생

코드입니다 :

settings.py

DNS_NAME='IP_ADRESS' 

LDAP_PORT=389 
LDAP_URL='ldap://%s:%s' % (DNS_NAME,LDAP_PORT) 
BIND_USER='cn=administrateur,cn=users,dc=my,dc=domain,dc=fr' 
BIND_PASSWORD="AdminPassword" 

SEARCH_DN='cn=users,dc=my,dc=domain,dc=fr' 
NT4_DOMAIN='E2C' 
SEARCH_FIELDS= ['mail','givenName','sn','sAMAccountName','memberOf'] 
MEMBERSHIP_REQ=['Group_Required','Alternative_Group'] 

AUTHENTICATION_BACKENDS = (

    'ldap_groups.accounts.backends.ActiveDirectoryGroupMembershipSSLBackend', 
    'django.contrib.auth.backends.ModelBackend', 
) 

DEBUG=True 
DEBUG_FILE='/$HOME/ldap.debug' 

내 코드를 추적 할 때, "사용자의 호출을 추가하는 동안 문제가있는 것 같다

import ldap 
import ldap.modlist as modlist 

username, email, password = kwargs['username'], kwargs['email'], kwargs['password1'] 

ldap.set_option(ldap.OPT_REFERRALS, 0) 

# Open a connection 
l = ldap.initialize(settings.LDAP_URL) 

# Bind/authenticate with a user with apropriate rights to add objects 
l.simple_bind_s(settings.BIND_USER,settings.BIND_PASSWORD) 

# The dn of our new entry/object 
dn="cn=%s,%s" % (username,settings.SEARCH_DN) 


# A dict to help build the "body" of the object 
attrs = {} 
attrs['objectclass'] = ['top','organizationalRole','simpleSecurityObject'] 
attrs['cn'] = username.encode('utf-16') 
attrs['userPassword'] = password.encode('utf-16') 
attrs['description'] = 'User object for replication using slurpd' 

# Convert our dict to nice syntax for the add-function using modlist-module 
ldif = modlist.addModlist(attrs) 

# Do the actual synchronous add-operation to the ldapserver 
l.add_s(dn,ldif) 

# Its nice to the server to disconnect and free resources when done 
l.unbind_s() 

backends.py l.add_s ". 내가 잘못 자격 증명을 사용하는 경우 서버가 잘못된 증명서를 반환, 그래서 내가 위에서 사용하고 자격 증명이 LDAP 디렉토리에 바인딩 할 올바른 생각

UNWILLING_TO_PERFORM at /accounts/register/ 

{'info': '00002077: SvcErr: DSID-031907B4, problem 5003 (WILL_NOT_PERFORM), data 0\n', 'desc': 'Server is unwilling to perform'} 

:

그러나 그것은 다음 오류를 반환합니다.

아마도 내 우분투 도메인의 구성원이어야합니까 또는 내 코드에서 뭔가 잘못 되었습니까?

답변

2

문제점을 발견했습니다. 사실 내 objectclass는 Active Directory를 준수하지 않았습니다. 파이썬 문자열로 정보 인코딩을 변경합니다. 여기

코드가 사용하는 것입니다

attrs = {} 
     attrs['objectclass'] = ['top','person','organizationalPerson','user'] 
     attrs['cn'] = str(username) 
     attrs['userPassword'] = str(password) 
     attrs['mail']=str(email) 
     attrs['givenName']=str(firstname) 
     attrs['sn']=str(surname) 
     attrs['description'] = 'User object for replication using slurpd' 

내가 성공적으로 내 Active Directory에 계정을 추가 할 수 있습니다.

희망이 있으면 도움이 될 것입니다.