ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 用Django和mod_wsgi设置SVN基本的授权认证

用Django和mod_wsgi设置SVN基本的授权认证

原创 Linux操作系统 作者:jieforest 时间:2012-08-02 11:09:23 0 删除 编辑
Consider this use case:

You have Django web application up and running on Apache and ‘mod_wsgi’. You plan to host Subversion repository on the same server and want it to be accessible to your web application users.

By default, Subversion will use ‘htpasswd’ file to authenticate users. So you will need to maintain two sets of users – one in ‘Django’ database and the other in Subversion ‘htpasswd’ file. You also need to keep them in sync so that the users have the same password and username for Subversion as well for logging in the web application.

Does that look like a lot of work to do? Is there a better way to do this? Yes, there is!

You can configure Apache to use Django’s authentication mechanism to authenticate users.

The ‘mod_wsgi’ comes to your rescue and makes things a lot easier for you.

Firstly, you need to define a ‘wsgi’ authentication handler script. which will tell Apache to use Django’s authentication for users accessing a Subversion repository.

CODE:

#! /usr/local/bin/python

import sys
import os
from django.contrib.auth.models import User
sys.path[0:0] = [
'/usr/lib/python/site-packages',
'/srv/src/app',
]
os.environ['DJANGO_SETTINGS_MODULE']='apphandler.settings'
from django.conf import settings

def check_password(environ, username, password):
        user = None
        try :
                   user = User.objects.get(**kwargs)
        except :
                return None
        return user.check_password(password)

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/301743/viewspace-739609/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-04-23

  • 博文量
    441
  • 访问量
    602345