2011-02-16 70 views
0

我有一个网站,只有注册用户可以登录和查看文档,现在这些文档通过Apache提供,如果您有URL,可以直接查看而无需登录。我想使用Django身份验证来保护这些文件夹,我有蜜蜂尝试这样做,但没有成功:Django保护访问静态媒体

的httpd.conf:

WSGIScriptAlias//home/www/wsgi-scripts/mysite.wsgi 

<Directory /home/www/wsgi-scripts> 
Order allow,deny 
Allow from all 
</Directory> 

<Location /media/protected> 
AuthType Basic 
AuthName "Authentication Required" 
AuthBasicProvider wsgi 
WSGIAuthUserScript /home/www/wsgi-scripts/auth.wsgi 
Require valid-user 
</Location> 

auth.wsgi:

import os, sys 
os.environ['PYTHON_EGG_CACHE'] = '/tmp' 
apache_configuration= os.path.dirname(__file__) 
project = os.path.dirname(apache_configuration) 
workspace = os.path.dirname(project) 
sys.path.append(workspace) 
sys.path.append('/usr/lib/python2.4/site-packages/django/') 
sys.path.append('/home/www') 
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' 

from django.contrib.auth.models import User 
from django import db 
import threading 
cache = threading.local() 

def check_password(environ, username, password): 
    cache.username = None 
    cache.permissions = [''] 
    db.reset_queries() 
    kwargs = {'username': username, 'is_active': True} 
    try: 
     try: 
      user = User.objects.get(**kwargs) 
     except User.DoesNotExist: 
      return None 
     if user.check_password(password): 
      cache.username = username 
      cache.permissions = user.get_group_permissions() 
      return True 
     else: 
      return False 
    finally: 
     db.connection.close() 

什么我做错了吗?

THKS

回答

0

如果在Apache错误日志文件中有什么错误消息?

另外,什么'mod_auth *'模块加载到您的Apache? 。

即下面的什么被加载:

LoadModule authn_file_module libexec/apache2/mod_authn_file.so 
LoadModule authn_dbm_module libexec/apache2/mod_authn_dbm.so 
LoadModule authn_anon_module libexec/apache2/mod_authn_anon.so 
LoadModule authn_dbd_module libexec/apache2/mod_authn_dbd.so 
LoadModule authn_default_module libexec/apache2/mod_authn_default.so 
LoadModule authz_host_module libexec/apache2/mod_authz_host.so 
LoadModule authz_groupfile_module libexec/apache2/mod_authz_groupfile.so 
LoadModule authz_user_module libexec/apache2/mod_authz_user.so 
LoadModule authz_dbm_module libexec/apache2/mod_authz_dbm.so 
LoadModule authz_owner_module libexec/apache2/mod_authz_owner.so 
LoadModule authz_default_module libexec/apache2/mod_authz_default.so 
LoadModule auth_basic_module libexec/apache2/mod_auth_basic.so 
LoadModule auth_digest_module libexec/apache2/mod_auth_digest.so 

这些中的某些子集,需要为它工作。以上列表适用于Apache 2.2。我无法记住我的头顶是必需的,但更新问题与你现在正在加载。