Changeset 1500
- Timestamp:
- 11/29/05 19:14:23 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/handlers/modpython.py
r1495 r1500 164 164 # mod_python hooks into this function. 165 165 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 apache172 173 # mod_python fakes the environ, and thus doesn't process SetEnv. This fixes174 # that so that the following import works175 os.environ.update(req.subprocess_env)176 from django.models.auth import users177 178 # check for PythonOptions179 _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 valid187 kwargs = {'username__exact': req.user, 'is_active__exact': True}188 if staff_only:189 kwargs['is_staff__exact'] = True190 if superuser_only:191 kwargs['is_superuser__exact'] = True192 try:193 user = users.get_object(**kwargs)194 except users.UserDoesNotExist:195 return apache.HTTP_UNAUTHORIZED196 197 # check the password and any permission given198 if user.check_password(req.get_basic_auth_pw()):199 if permission_name:200 if user.has_perm(permission_name):201 return apache.OK202 else:203 return apache.HTTP_UNAUTHORIZED204 else:205 return apache.OK206 else:207 return apache.HTTP_UNAUTHORIZED208 django/trunk/docs/apache_auth.txt
r1496 r1500 8 8 9 9 * Serve media files directly from Apache only to authenticated users. 10 10 11 11 * Authenticate access to a Subversion_ repository against Django users with 12 12 a certain permission. 13 13 14 14 * Allow certain users to connect to a WebDAV share created with mod_dav_. 15 15 16 16 Configuring Apache 17 17 ================== … … 25 25 AuthName "example.com" 26 26 Require valid-user 27 27 28 28 SetEnv DJANGO_SETTINGS_MODULE mysite.settings 29 PythonAuthenHandler django.co re.handlers.modpython29 PythonAuthenHandler django.contrib.auth.handlers.modpython 30 30 </Location> 31 31 … … 38 38 ================================ ========================================= 39 39 ``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) 41 41 will be allowed. 42 42 43 43 Defaults to ``on``. 44 44 … … 46 46 those with the ``is_superuser`` flag set) 47 47 will be allowed. 48 48 49 49 Defaults to ``off``. 50 50 51 51 ``DjangoPermissionName`` The name of a permission to require for 52 access. See `custom permissions`_ for52 access. See `custom permissions`_ for 53 53 more information. 54 54 55 55 By default no specific permission will be 56 56 required. 57 57 ================================ ========================================= 58 58 59 59 .. _authentication system: http://www.djangoproject.com/documentation/authentication/ 60 60 .. _Subversion: http://subversion.tigris.org/
