[10321] | 1 | """A WSGI app for serving CAS. |
---|
| 2 | """ |
---|
[10335] | 3 | import os |
---|
[10351] | 4 | import tempfile |
---|
[10327] | 5 | from webob import exc, Response |
---|
[10321] | 6 | from webob.dec import wsgify |
---|
| 7 | |
---|
[10335] | 8 | template_dir = os.path.join(os.path.dirname(__file__), 'templates') |
---|
[10321] | 9 | |
---|
[10335] | 10 | |
---|
[10321] | 11 | class CASServer(object): |
---|
| 12 | """A WSGI CAS server. |
---|
[10351] | 13 | |
---|
| 14 | This CAS server stores credential data (tickets, etc.) in a local |
---|
| 15 | sqlite3 database file. |
---|
| 16 | |
---|
| 17 | `db_path` - |
---|
| 18 | The filesystem path to the database to use. If none is given |
---|
| 19 | CAS server will create a new one in some new, temporary |
---|
| 20 | directory. Please note that credentials will be lost after a |
---|
| 21 | CAS server restart. |
---|
| 22 | |
---|
| 23 | If the path is given and the file exists already, it will be |
---|
| 24 | used. |
---|
| 25 | |
---|
| 26 | If the database file does not exist, it will be created. |
---|
[10321] | 27 | """ |
---|
[10351] | 28 | def __init__(self, db_path=None): |
---|
| 29 | if db_path is None: |
---|
| 30 | db_path = os.path.join(tempfile.mkdtemp(), 'cas.db') |
---|
| 31 | self.db_path = db_path |
---|
| 32 | |
---|
[10321] | 33 | @wsgify |
---|
| 34 | def __call__(self, req): |
---|
[10335] | 35 | if req.path in ['/login', '/validate', '/logout']: |
---|
| 36 | return getattr(self, req.path[1:])(req) |
---|
[10321] | 37 | return exc.HTTPNotFound() |
---|
| 38 | |
---|
[10327] | 39 | def login(self, req): |
---|
[10335] | 40 | return Response( |
---|
| 41 | open(os.path.join(template_dir, 'login.html'), 'r').read()) |
---|
[10321] | 42 | |
---|
[10327] | 43 | def validate(self, req): |
---|
| 44 | return exc.HTTPNotImplemented() |
---|
| 45 | |
---|
| 46 | def logout(self, req): |
---|
| 47 | return exc.HTTPNotImplemented() |
---|
| 48 | |
---|
[10321] | 49 | cas_server = CASServer |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | def make_cas_server(global_conf, **local_conf): |
---|
| 53 | return CASServer(**local_conf) |
---|