2 authkit authorization permission objects for BlueChips
5 from authkit.authenticate import AddDictToEnviron
6 from authkit.authorize import NotAuthenticatedError, NotAuthorizedError
7 from authkit.permissions import RequestPermission
9 from bluechips import model
10 from bluechips.model import meta
12 class BlueChipUser(RequestPermission):
13 def check(self, app, environ, start_response):
14 if 'REMOTE_USER' not in environ:
15 raise NotAuthenticatedError('Not Authenticated')
16 environ['user'] = meta.Session.query(model.User).\
17 filter_by(username=unicode(environ['REMOTE_USER'])).\
19 if environ['user'] == None:
20 raise NotAuthorizedError('You are not allowed access.')
21 return app(environ, start_response)
23 class DummyAuthenticate(AddDictToEnviron):
25 Set the authkit.authenticate environment variable so
26 authkit.authorize shuts up
28 def __init__(self, app, app_conf):
30 newenv['authkit.authenticate'] = True
31 newenv['authkit.config'] = {'setup.enable': True}
32 if 'fake_username' in app_conf:
33 newenv['REMOTE_USER'] = app_conf['fake_username']
34 super(DummyAuthenticate, self).__init__(app, newenv)
36 __all__ = ['BlueChipUser', 'DummyAuthenticate']