1 | """The base Controller API |
---|
2 | |
---|
3 | Provides the BaseController class for subclassing, and other objects |
---|
4 | utilized by Controllers. |
---|
5 | """ |
---|
6 | from pylons import c, cache, config, g, request, response, session |
---|
7 | from pylons.controllers import WSGIController |
---|
8 | from pylons.controllers.util import abort, etag_cache, redirect_to |
---|
9 | from pylons.decorators import jsonify, validate |
---|
10 | from pylons.i18n import _, ungettext, N_ |
---|
11 | from pylons.templating import render |
---|
12 | |
---|
13 | import sso.lib.helpers as h |
---|
14 | import sso.model as model |
---|
15 | |
---|
16 | import urllib |
---|
17 | from urlparse import urlsplit, urlunsplit |
---|
18 | from base64 import urlsafe_b64encode |
---|
19 | |
---|
20 | from ndg.security.common.pylons.security_util import setSecuritySession, \ |
---|
21 | LoginServiceQuery |
---|
22 | |
---|
23 | import logging |
---|
24 | log = logging.getLogger(__name__) |
---|
25 | |
---|
26 | class BaseControllerError(Exception): |
---|
27 | "Error handling for BaseController" |
---|
28 | |
---|
29 | class BaseController(WSGIController): |
---|
30 | def __call__(self, environ, start_response): |
---|
31 | # Insert any code to be run per request here. The Routes match |
---|
32 | # is under environ['pylons.routes_dict'] should you want to check |
---|
33 | # the action or route vars here |
---|
34 | log.debug("BaseController.__call__ ...") |
---|
35 | |
---|
36 | # construct URL picking up setting of server name from config to |
---|
37 | # avoid exposing absolute URL hidden behind mod_proxy see #857 |
---|
38 | # Also, avoid returning to getCredentials and potentially exposing |
---|
39 | # username/pass-phrase on URL. |
---|
40 | pathInfo = urllib.quote(environ.get('PATH_INFO', '')) |
---|
41 | if 'getCredentials' in pathInfo: |
---|
42 | log.debug("Reverting request URL from getCredentials to login...") |
---|
43 | c.requestURL = g.ndg.security.server.ssoservice.cfg.server+'/login' |
---|
44 | else: |
---|
45 | c.requestURL = g.ndg.security.server.ssoservice.cfg.server+pathInfo |
---|
46 | query='&'.join(["%s=%s" % item for item in request.params.items()]) |
---|
47 | if query: |
---|
48 | c.requestURL += '?' + query |
---|
49 | |
---|
50 | log.debug("BaseController.__call__: c.requestURL = %s" % c.requestURL) |
---|
51 | |
---|
52 | |
---|
53 | return WSGIController.__call__(self, environ, start_response) |
---|
54 | |
---|
55 | # Include the '_' function in the public names |
---|
56 | __all__ = [__name for __name in locals().keys() if not __name.startswith('_') \ |
---|
57 | or __name == '_'] |
---|