Back to index

plone3  3.1.7
basic_auth.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights
00004 # Reserved.
00005 #
00006 # This software is subject to the provisions of the Zope Public License,
00007 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this
00008 # distribution.
00009 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00010 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00011 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00012 # FOR A PARTICULAR PURPOSE.
00013 #
00014 ##############################################################################
00015 """ Basic auth helpers.
00016 
00017 $Id: basic_auth.py 39144 2004-08-12 15:15:55Z jens $
00018 """
00019 
00020 def extraction( self, request ):
00021 
00022     """ Fetch HTTP Basic Auth credentials from the request.
00023     """
00024     creds = request._authUserPW()
00025 
00026     if creds is not None:
00027         name, password = creds
00028 
00029         return { 'login' : name, 'password' : password }
00030 
00031     return {}
00032 
00033 def authentication( self, credentials ):
00034 
00035     """ Authenticate against nested acl_users.
00036     """
00037     real_user_folder = self.simple_uf.acl_users
00038 
00039     login = credentials.get( 'login' )
00040     password = credentials.get( 'password' )
00041 
00042     user = real_user_folder.authenticate( login, password, {} )
00043 
00044     return user is not None and login or None
00045 
00046 
00047 def authorize( self, user ):
00048 
00049     """ Fetch user roles from nested acl_users.
00050     """
00051     real_user_folder = self.simple_uf.acl_users
00052     real_user = real_user_folder.getUserById( user.getId() )
00053     return real_user.getRoles()