source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/logout.py @ 2959

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/logout.py@2959
Revision 2959, 3.6 KB checked in by pjkersha, 13 years ago (diff)

ows_server/ows_server/controllers/login.py:

  • removed call - BaseController?.call supplies all the needed functionality
  • added to before - filter out getCredentials from return to address - getCredentials can contain cred args so should be removed. The code here is a 2nd line of defence - BaseController?.call removes getCredentials from request URLs so return to should nvere get assigned a getCredenials call.

ows_server/ows_server/controllers/logout.py:

  • same mod to before call as login.py listed above.

ows_server/ows_server/lib/security_util.py:

  • constructURL function - not used but a starting point for attempting to encapsulate security related code and remove it from BaseController?.call

ows_server/ows_server/lib/base.py:

  • if c.requestURL contains getCredentials filter it out and redirect to /discovery instead. getCredentials recives username/password from login form. Without this check these fields can be exposed as URL query args in a c.returnTo address(!)
Line 
1from ows_server.lib.base import *
2from ows_server.lib.security_util import SecuritySession
3import logging
4log = logging.getLogger(__name__)
5
6from paste.request import parse_querystring
7import sys # include in case tracefile is set to sys.stderr
8import base64 # decode the return to address
9from urlparse import urlsplit, urlunsplit
10
11from ndg.security.common.SessionMgr import SessionMgrClient
12
13
14class LogoutController(BaseController):
15    '''Provides the pylons controller for logging out and killing the cookies
16    '''
17   
18    def __before__(self):
19        """Get return to URL"""
20        c.returnTo = request.params.get('r', '')
21       
22        # Check return to address - getCredentials should NOT be returned to
23        # with its query args intact
24        b64decReturnTo = base64.urlsafe_b64decode(c.returnTo)
25        scheme, netloc, pathInfo, query, frag = urlsplit(b64decReturnTo)
26        if 'getCredentials' in pathInfo:
27            # Swap to discovery and remove sensitive creds query args
28            #
29            # TODO: re-write to be more robust and modular.  Nb.
30            # BaseController.__call__ should filter out 'getCredentials'
31            # calls from c.requestURL so this code should never need to be
32            # executed.
33            filteredReturnTo = urlunsplit((scheme,netloc,'/discovery','',''))
34            c.returnTo = base64.urlsafe_b64encode(filteredReturnTo)
35
36   
37    def index(self):
38        ''' Ok, you really want to logout here '''
39
40        if 'ndgSec' not in session:
41            # There's no handle to a security session
42            log.error("logout called but no 'ndgSec' key in session object")
43            return self.__redirect()
44       
45        try:
46            smClnt = SessionMgrClient(uri=g.securityCfg.smURI,
47                    sslCACertFilePathList=g.securityCfg.sslCACertFilePathList,
48                    sslPeerCertCN=g.securityCfg.sslPeerCertCN,
49                    signingCertFilePath=g.securityCfg.wssCertFilePath,
50                    signingPriKeyFilePath=g.securityCfg.wssPriKeyFilePath,
51                    signingPriKeyPwd=g.securityCfg.wssPriKeyPwd,
52                    caCertFilePathList=g.securityCfg.wssCACertFilePathList,
53                    tracefile=g.securityCfg.tracefile)       
54        except Exception, e:
55            log.error("logout - creating Session Manager client: %s" % e)
56            return self.__redirect() 
57       
58        # Disconnect from Session Manager
59        log.info('Calling Session Manager "%s" disconnect for logout...' % \
60                 g.securityCfg.smURI)
61        try:
62            smClnt.disconnect(sessID=session['ndgSec']['sid'])
63        except Exception, e:
64            log.error("Error with Session Manager logout: %s" % e)
65            self.__redirect()
66           
67        try:
68            # easy to kill our cookie
69            SecuritySession.delete()
70            if 'ndgCleared' in session: del session['ndgCleared']
71            session.save()
72           
73        except Exception, e:   
74            log.error("logout - clearing security session: %s" % e)
75
76        return self.__redirect()
77   
78   
79    def __redirect(self):
80        """Handle redirect back to previous page"""
81        if c.returnTo:
82            # Decode the return to address
83            try:
84                b64decReturnTo = base64.urlsafe_b64decode(c.returnTo)
85            except Exception, e:
86                log.error("logout - decoding return URL: %s" % e) 
87                return render_response('content')
88           
89            # and now go back to whence we had come
90            h.redirect_to(b64decReturnTo)
91        else:
92            return render_response('content')
Note: See TracBrowser for help on using the repository browser.