Django

Code

Changeset 1500

Show
Ignore:
Timestamp:
11/29/05 19:14:23 (3 years ago)
Author:
adrian
Message:

Moved Apache auth handler to django/contrib/auth/handlers/modpython.py

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/handlers/modpython.py

    r1495 r1500  
    164164    # mod_python hooks into this function. 
    165165    return ModPythonHandler()(req) 
    166  
    167 def authenhandler(req, **kwargs): 
    168     """ 
    169     Authentication handler that checks against Django's auth database. 
    170     """ 
    171     from mod_python import apache 
    172      
    173     # mod_python fakes the environ, and thus doesn't process SetEnv.  This fixes  
    174     # that so that the following import works 
    175     os.environ.update(req.subprocess_env) 
    176     from django.models.auth import users 
    177      
    178     # check for PythonOptions 
    179     _str_to_bool = lambda s: s.lower() in '1', 'true', 'on', 'yes' 
    180      
    181     options = req.get_options() 
    182     permission_name = options.get('DjangoPermissionName', None) 
    183     staff_only = _str_to_bool(options.get('DjangoRequireStaffStatus', "on")) 
    184     superuser_only = _str_to_bool(options.get('DjangoRequireSuperuserStatus', "off")) 
    185      
    186     # check that the username is valid 
    187     kwargs = {'username__exact': req.user, 'is_active__exact': True} 
    188     if staff_only: 
    189         kwargs['is_staff__exact'] = True 
    190     if superuser_only: 
    191         kwargs['is_superuser__exact'] = True 
    192     try: 
    193         user = users.get_object(**kwargs) 
    194     except users.UserDoesNotExist: 
    195         return apache.HTTP_UNAUTHORIZED 
    196          
    197     # check the password and any permission given 
    198     if user.check_password(req.get_basic_auth_pw()): 
    199         if permission_name: 
    200             if user.has_perm(permission_name): 
    201                 return apache.OK 
    202             else: 
    203                 return apache.HTTP_UNAUTHORIZED 
    204         else: 
    205             return apache.OK 
    206     else: 
    207         return apache.HTTP_UNAUTHORIZED 
    208      
  • django/trunk/docs/apache_auth.txt

    r1496 r1500  
    88 
    99    * Serve media files directly from Apache only to authenticated users. 
    10      
     10 
    1111    * Authenticate access to a Subversion_ repository against Django users with 
    1212      a certain permission. 
    13        
     13 
    1414    * Allow certain users to connect to a WebDAV share created with mod_dav_. 
    15          
     15 
    1616Configuring Apache 
    1717================== 
     
    2525        AuthName "example.com" 
    2626        Require valid-user 
    27          
     27 
    2828        SetEnv DJANGO_SETTINGS_MODULE mysite.settings 
    29         PythonAuthenHandler django.core.handlers.modpython 
     29        PythonAuthenHandler django.contrib.auth.handlers.modpython 
    3030    </Location> 
    3131 
     
    3838    ================================  ========================================= 
    3939    ``DjangoRequireStaffStatus``      If set to ``on`` only "staff" users (i.e. 
    40                                       those with the ``is_staff`` flag set)  
     40                                      those with the ``is_staff`` flag set) 
    4141                                      will be allowed. 
    42                                        
     42 
    4343                                      Defaults to ``on``. 
    4444 
     
    4646                                      those with the ``is_superuser`` flag set) 
    4747                                      will be allowed. 
    48                                        
     48 
    4949                                      Defaults to ``off``. 
    50      
     50 
    5151    ``DjangoPermissionName``          The name of a permission to require for 
    52                                       access. See `custom permissions`_ for 
     52                                      access. See `custom permissions`_ for 
    5353                                      more information. 
    54                                        
     54 
    5555                                      By default no specific permission will be 
    5656                                      required. 
    5757    ================================  ========================================= 
    58      
     58 
    5959.. _authentication system: http://www.djangoproject.com/documentation/authentication/ 
    6060.. _Subversion: http://subversion.tigris.org/