paulb@651 | 1 | #!/usr/bin/env python |
paulb@651 | 2 | |
paulb@651 | 3 | """ |
paulb@651 | 4 | OpenID redirection resources for XSLForms applications. These resources use |
paulb@651 | 5 | "root" attributes on transaction objects, and therefore should be defined within |
paulb@651 | 6 | the appropriate resources in site maps. |
paulb@651 | 7 | |
paulb@651 | 8 | Copyright (C) 2006, 2007, 2008 Paul Boddie <paul@boddie.org.uk> |
paulb@651 | 9 | |
paulb@651 | 10 | This program is free software; you can redistribute it and/or modify it under |
paulb@651 | 11 | the terms of the GNU Lesser General Public License as published by the Free |
paulb@651 | 12 | Software Foundation; either version 3 of the License, or (at your option) any |
paulb@651 | 13 | later version. |
paulb@651 | 14 | |
paulb@651 | 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
paulb@651 | 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paulb@651 | 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
paulb@651 | 18 | details. |
paulb@651 | 19 | |
paulb@651 | 20 | You should have received a copy of the GNU Lesser General Public License along |
paulb@651 | 21 | with this program. If not, see <http://www.gnu.org/licenses/>. |
paulb@651 | 22 | """ |
paulb@651 | 23 | |
paulb@651 | 24 | import WebStack.Resources.OpenIDRedirect # OpenIDRedirectResource |
paulb@651 | 25 | |
paulb@651 | 26 | OpenIDRedirectAuthenticator = WebStack.Resources.OpenIDRedirect.OpenIDRedirectAuthenticator |
paulb@651 | 27 | |
paulb@651 | 28 | class OpenIDRedirectResource(WebStack.Resources.OpenIDRedirect.OpenIDRedirectResource): |
paulb@651 | 29 | |
paulb@651 | 30 | "A redirect resource which uses dynamic knowledge about the URL space." |
paulb@651 | 31 | |
paulb@651 | 32 | def __init__(self, host, path_to_login, *args, **kw): |
paulb@651 | 33 | |
paulb@651 | 34 | """ |
paulb@651 | 35 | Initialise the resource with the 'host', 'path_to_login' (the path from |
paulb@651 | 36 | the root of the application to the login screen), and other |
paulb@651 | 37 | LoginRedirectResource details. |
paulb@651 | 38 | |
paulb@651 | 39 | To get the root of the application, this resource needs an attribute on |
paulb@651 | 40 | the transaction called "root". |
paulb@651 | 41 | |
paulb@651 | 42 | Examples of 'path_to_login' with "root" attribute and result: |
paulb@651 | 43 | |
paulb@651 | 44 | "login", "/" -> "/login" |
paulb@651 | 45 | "login", "/app/" -> "/app/login" |
paulb@651 | 46 | "app/login", "/" -> "/app/login" |
paulb@651 | 47 | """ |
paulb@651 | 48 | |
paulb@651 | 49 | self.host = host |
paulb@651 | 50 | self.path_to_login = path_to_login |
paulb@651 | 51 | WebStack.Resources.OpenIDRedirect.OpenIDRedirectResource.__init__(self, *args, **kw) |
paulb@651 | 52 | |
paulb@651 | 53 | def get_app_url(self, trans): |
paulb@651 | 54 | return self.host |
paulb@651 | 55 | |
paulb@651 | 56 | def get_login_url(self, trans): |
paulb@651 | 57 | return self.host + trans.get_attributes()["root"] + self.path_to_login |
paulb@651 | 58 | |
paulb@651 | 59 | # vim: tabstop=4 expandtab shiftwidth=4 |