Djangoã®èªè¨¼ãActive Directoryã§
Djangoã使ã£ã社å
ã¢ããªã§ãã¦ã¼ã¶ç»é²ãèªåã§ãã£ã¦ãããã¨ããã¾ã§åºæ¥ããã ãã©ããã®ã¢ããªã®ããã«IDã¨ãã¹ã¯ã¼ããè¦ããã®ãããã©ãããã
社å
㧠Active Directory ãåãã¦ãããã ãããããã使ã£ã¦èªè¨¼ã§ããªãã試ãã¦ã¿ãããªãã¨ãªãåãã¦ãã®ã§ã¡ã¢ãã¦ããã
WinXP(2003 Server), Python 2.4.4, Django 0.96, Python-LDAP 2.0.6 for Python 2.4 ã§åä½ç¢ºèªæ¸ã¿ã
åèURL
èªè¨¼ããã¯ã¨ã³ã
Djangoã®èªè¨¼ãç½®ãæããã®ã¯ãããç°¡åãªã®ã§ãå®éããã®ã¯ãããããã
- èªè¨¼ããã¯ã¨ã³ããä½ãã
ããã§ã¯ djangoproject/app/util.py ã« ActiveDirectoryBackend ã¯ã©ã¹ãä½æããã
ç¶æ¿ã¨ãã¯å¿ è¦ãªãã¦ãauthenticate(self, username, password) 㨠get_user(self, user_id) ãå®ç¾©ãã¦ããã°ããï¼å¼æ°åãä¸è´ããã¦ãããªãã¨èªè¨¼ãã§ãã¯ããªãã¿ããï¼ã - settings.py ã« AUTHENTICATION_BACKENDS ãè¨å®ããã
ä¸ããé çªã«èªè¨¼ãæåããã¾ã§ãã©ã¤ãã¦ããã®ã§ãæåã« ActiveDirectoryBackend ã¯ã©ã¹ãæå®ããã
ã¡ãªã¿ã«ã³ã¼ãã¯ãããªæãã
èªè¨¼ãæåããå ´åã«ãã¦ã¼ã¶ãªãã¸ã§ã¯ããä½ãããã«ãã¦ããã
SERVER_ADDRESS ã¯ãpcname.xxx.co.jpãã®ãããªADãµã¼ãã®ã¢ãã¬ã¹ããDOMAIN_NAME ã¯ADãµã¼ããæå±ãããã¡ã¤ã³åï¼ãæå®ããã
ç°å¢ã«ãã£ã¦ã¯åããªãããã
#settings.py AUTHENTICATION_BACKENDS = ( 'djangoproject.app.util.ActiveDirectoryBackend' 'django.contrib.auth.backends.ModelBackend', ) #djangoproject/app/util.py class ActiveDirectoryBackend: def authenticate(self, username='', password=''): if not self.is_valid(username, password): return None try: user = User.objects.get(username=username) except User.DoesNotExist: user = User(username=username, password='dummy') user.save() return user def get_user(self, user_id): try: return User.objects.get(pk=user_id) except User.DoesNotExist: return None def is_valid(self, user='', password=''): try: l = ldap.open('SERVER_ADDRESS') l.simple_bind_s('%s@DOMAIN_NAME' % user, password) l.unbind_s() return True except ldap.LDAPError: return False