"""A WSGI app for serving CAS. """ import os import tempfile from webob import exc, Response from webob.dec import wsgify template_dir = os.path.join(os.path.dirname(__file__), 'templates') class CASServer(object): """A WSGI CAS server. This CAS server stores credential data (tickets, etc.) in a local sqlite3 database file. `db_path` - The filesystem path to the database to use. If none is given CAS server will create a new one in some new, temporary directory. Please note that credentials will be lost after a CAS server restart. If the path is given and the file exists already, it will be used. If the database file does not exist, it will be created. """ def __init__(self, db_path=None): if db_path is None: db_path = os.path.join(tempfile.mkdtemp(), 'cas.db') self.db_path = db_path @wsgify def __call__(self, req): if req.path in ['/login', '/validate', '/logout']: return getattr(self, req.path[1:])(req) return exc.HTTPNotFound() def login(self, req): return Response( open(os.path.join(template_dir, 'login.html'), 'r').read()) def validate(self, req): return exc.HTTPNotImplemented() def logout(self, req): return exc.HTTPNotImplemented() cas_server = CASServer def make_cas_server(global_conf, **local_conf): return CASServer(**local_conf)