httpauthplugin/0000755000175500017550000000000012747442531013701 5ustar debacledebaclehttpauthplugin/0.10/0000755000175500017550000000000011264245747014262 5ustar debacledebaclehttpauthplugin/0.10/httpauth/0000755000175500017550000000000011264245747016123 5ustar debacledebaclehttpauthplugin/0.10/httpauth/__init__.py0000644000175500017550000000000010533471102020202 0ustar debacledebaclehttpauthplugin/0.10/httpauth/filter.py0000644000175500017550000000515611264245747017771 0ustar debacledebaclefrom trac.core import * from trac.config import ListOption from trac.web.api import IRequestFilter, RequestDone, IAuthenticator from trac.web.chrome import INavigationContributor try: from base64 import b64decode except ImportError: from base64 import decodestring as b64decode from acct_mgr.api import AccountManager __all__ = ['HTTPAuthFilter'] class HTTPAuthFilter(Component): """Request filter and handler to provide HTTP authentication.""" paths = ListOption('httpauth', 'paths', default='/login/xmlrpc', doc='Paths to force HTTP authentication on.') formats = ListOption('httpauth', 'formats', doc='Request formats to force HTTP authentication on') implements(IRequestFilter, IAuthenticator) # IRequestFilter methods def pre_process_request(self, req, handler): check = False for path in self.paths: if req.path_info.startswith(path): check = True break if req.args.get('format') in self.formats: check = True if check and not self._check_password(req): self.log.info('HTTPAuthFilter: No/bad authentication data given, returing 403') return self return handler def post_process_request(self, req, template, content_type): return template, content_type # IRequestHandler methods (sort of) def process_request(self, req): if req.session: req.session.save() # Just in case auth_req_msg = 'Authentication required' req.send_response(401) req.send_header('WWW-Authenticate', 'Basic realm="Control Panel"') req.send_header('Content-Type', 'text/plain') req.send_header('Pragma', 'no-cache') req.send_header('Cache-control', 'no-cache') req.send_header('Expires', 'Fri, 01 Jan 1999 00:00:00 GMT') req.send_header('Content-Length', str(len(auth_req_msg))) req.end_headers() if req.method != 'HEAD': req.write(auth_req_msg) raise RequestDone # IAuthenticator methods def authenticate(self, req): user = self._check_password(req) if user: req.environ['REMOTE_USER'] = user self.log.debug('HTTPAuthFilter: Authentication okay for %s', user) return user # Internal methods def _check_password(self, req): header = req.get_header('Authorization') if header: token = header.split()[1] user, passwd = b64decode(token).split(':', 1) if AccountManager(self.env).check_password(user, passwd): return user httpauthplugin/0.10/setup.py0000644000175500017550000000140010772117014015753 0ustar debacledebacle#!/usr/bin/env python # -*- coding: iso-8859-1 -*- from setuptools import setup setup( name = 'TracHTTPAuth', version = '1.1', packages = ['httpauth'], #package_data = { 'httpauth': ['templates/*.cs', 'htdocs/*.js', 'htdocs/*.css' ] }, author = "Noah Kantrowitz", author_email = "noah@coderanger.net", description = "Use the AccountManager plugin to provide HTTP authentication from Trac itself.", license = "BSD", keywords = "trac plugin http auth", url = "http://trac-hacks.org/wiki/HttpAuthPlugin", classifiers = [ 'Framework :: Trac', ], install_requires = ['TracAccountManager'], entry_points = { 'trac.plugins': [ 'httpauth.filter = httpauth.filter', ] } ) httpauthplugin/trunk/0000755000175500017550000000000012112415676015040 5ustar debacledebaclehttpauthplugin/trunk/httpauth/0000755000175500017550000000000012055715260016677 5ustar debacledebaclehttpauthplugin/trunk/httpauth/__init__.py0000644000175500017550000000000010533471102020767 0ustar debacledebaclehttpauthplugin/trunk/httpauth/filter.py0000644000175500017550000000531612055715260020543 0ustar debacledebaclefrom trac.core import * from trac.config import ListOption from trac.web.api import IRequestFilter, RequestDone, IAuthenticator from trac.web.chrome import INavigationContributor try: from base64 import b64decode except ImportError: from base64 import decodestring as b64decode from acct_mgr.api import AccountManager __all__ = ['HTTPAuthFilter'] class HTTPAuthFilter(Component): """Request filter and handler to provide HTTP authentication.""" paths = ListOption('httpauth', 'paths', default='/login/xmlrpc', doc='Paths to force HTTP authentication on.') formats = ListOption('httpauth', 'formats', doc='Request formats to force HTTP authentication on') implements(IRequestFilter, IAuthenticator) # IRequestFilter methods def pre_process_request(self, req, handler): check = False for path in self.paths: if req.path_info.startswith(path): check = True break if req.args.get('format') in self.formats: check = True if check and not self._check_password(req): self.log.info('HTTPAuthFilter: No/bad authentication data given, returing 403') return self return handler def post_process_request(self, req, template, content_type): return template, content_type # IRequestHandler methods (sort of) def process_request(self, req): if req.session: req.session.save() # Just in case auth_req_msg = 'Authentication required' req.send_response(401) req.send_header('WWW-Authenticate', 'Basic realm="Control Panel"') req.send_header('Content-Type', 'text/plain') req.send_header('Pragma', 'no-cache') req.send_header('Cache-control', 'no-cache') req.send_header('Expires', 'Fri, 01 Jan 1999 00:00:00 GMT') req.send_header('Content-Length', str(len(auth_req_msg))) if req.get_header('Content-Length'): req.send_header('Connection', 'close') req.end_headers() if req.method != 'HEAD': req.write(auth_req_msg) raise RequestDone # IAuthenticator methods def authenticate(self, req): user = self._check_password(req) if user: req.environ['REMOTE_USER'] = user self.log.debug('HTTPAuthFilter: Authentication okay for %s', user) return user # Internal methods def _check_password(self, req): header = req.get_header('Authorization') if header: token = header.split()[1] user, passwd = b64decode(token).split(':', 1) if AccountManager(self.env).check_password(user, passwd): return user httpauthplugin/trunk/setup.py0000644000175500017550000000151112112415676016550 0ustar debacledebacle#!/usr/bin/env python # -*- coding: iso-8859-1 -*- from setuptools import setup setup( name = 'TracHTTPAuth', version = '1.1', packages = ['httpauth'], #package_data = { 'httpauth': ['templates/*.cs', 'htdocs/*.js', 'htdocs/*.css' ] }, author = "Noah Kantrowitz", author_email = "noah@coderanger.net", maintainer = "Craig A", maintainer_email = "craiga@fonefit.com", description = "Use the AccountManager plugin to provide HTTP authentication from Trac itself.", license = "BSD", keywords = "trac plugin http auth", url = "http://trac-hacks.org/wiki/HttpAuthPlugin", classifiers = [ 'Framework :: Trac', ], install_requires = ['TracAccountManager'], entry_points = { 'trac.plugins': [ 'httpauth.filter = httpauth.filter', ] } )