Changeset 1890

Show
Ignore:
Timestamp:
01/22/07 22:10:36 (2 years ago)
Author:
coderanger
Message:

HttpAuthPlugin:

What was I smoking when I wrote this? Should actually work now. (closes #1092)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • httpauthplugin/0.10/httpauth/filter.py

    r1858 r1890  
    1616                       doc='Paths to force HTTP authentication on.') 
    1717     
     18    formats = ListOption('httpauth', 'formats', doc='Request formats to force HTTP authentication on') 
     19     
    1820    implements(IRequestFilter, IAuthenticator) 
    1921 
    2022    # IRequestFilter methods 
    2123    def pre_process_request(self, req, handler): 
     24        check = False 
    2225        for path in self.paths: 
    2326            if req.path_info.startswith(path): 
    24                 header = req.get_header('Authorization') 
    25                 if header is None: 
    26                     self.log.info('HTTPAuthFilter: No authentication data given, returing 403') 
    27                     return self # Run HTTP auth 
    28                 else: 
    29                     token = header.split()[1] 
    30                     user, passwd = base64.b64decode(token).split(':', 1) 
    31                     if AccountManager(self.env).check_password(user, passwd): 
    32                         self.log.debug('HTTPAuthFilter: Authentication okay') 
    33                         req.__user = user 
    34                     else: 
    35                         self.log.info('HTTPAuthFilter: Bad authentication data given, returing 403') 
    36                         return self # Failed auth 
    37          
     27                check = True 
     28                break 
     29        if req.args.get('format') in self.formats: 
     30            check = True 
     31        if check and not self._check_password(req): 
     32            self.log.info('HTTPAuthFilter: No/bad authentication data given, returing 403') 
     33            return self 
    3834        return handler 
    3935         
     
    4137        return template, content_type 
    4238 
    43     # IRequestHandler methods         
     39    # IRequestHandler methods (sort of)        
    4440    def process_request(self, req): 
    4541        if req.session: 
     
    6056    # IAuthenticator methods 
    6157    def authenticate(self, req): 
    62         try: 
    63             return req.__user 
    64         except AttributeError: 
    65             return None # Bail out 
     58        user = self._check_password(req) 
     59        if user: 
     60            self.log.debug('HTTPAuthFilter: Authentication okay for %s', user) 
     61            return user 
     62             
     63    # Internal methods 
     64    def _check_password(self, req): 
     65        header = req.get_header('Authorization') 
     66        if header: 
     67            token = header.split()[1] 
     68            user, passwd = base64.b64decode(token).split(':', 1) 
     69            if AccountManager(self.env).check_password(user, passwd): 
     70                return user 
  • httpauthplugin/0.10/setup.py

    r1858 r1890  
    66setup( 
    77    name = 'TracHTTPAuth', 
    8     version = '1.0.1', 
     8    version = '1.1', 
    99    packages = ['httpauth'], 
    1010    #package_data = { 'httpauth': ['templates/*.cs', 'htdocs/*.js', 'htdocs/*.css' ] },