source: TI12-security/trunk/python/ndg.security.client/ndg/security/client/ssoclient/ssoclient/config/ssoClientMiddleware.py @ 3918

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.client/ndg/security/client/ssoclient/ssoclient/config/ssoClientMiddleware.py@3918
Revision 3918, 3.8 KB checked in by pjkersha, 12 years ago (diff)

Initial Integration of Single Sign On Service with OpenID and Pylons AuthKit?:

  • WAYF now contains an OpenID textbox for sign in
  • No role integration carried out yet - OpenID has no better privileges than an anonymous user(!)
  • Integrated into Authkit - requires lots of config settings in pylons ini file
  • HTTP 401 error get redirected automatically to WAYF
  • Need to create an AuthKit? egg from SVN 151 checkout - will put on NDG dist
Line 
1'''
2Security middleware - set-up configuration items
3
4P J Kershaw 18/03/08
5'''
6import logging
7log = logging.getLogger(__name__)
8
9class ndg:
10    '''Class structure to define a namespace for SSO Client config attached
11    Pylons global variable 'g'
12    '''
13    class security:
14        class common:
15            class sso:
16                cfg = None
17
18class SSOMiddleware(object):
19   
20    def __init__(self, app, cfg, appGlobals, **kw):
21       
22        log.debug("SSOMiddleware.__init__ ...")
23        self.app = app
24
25        ndg.security.client.ssoclient.cfg = SSOClientConfig(cfg, **kw)
26        appGlobals.ndg = ndg
27
28    def __call__(self, environ, start_response):
29        log.debug("SSOMiddleware.__call__ ...")
30       
31        return self.app(environ, start_response)
32
33import sys
34from ConfigParser import SafeConfigParser as ConfigParser
35       
36class SSOClientConfigError(Exception):
37    """Handle errors from parsing security config items"""
38
39class SSOClientConfig(object):
40    """Get Security related parameters from the Pylons NDG config file"""
41
42    def __init__(self, cfg=None, **parseKw):
43        '''Get settings for Single Sign On client'''
44       
45        if isinstance(cfg, basestring):
46            # Assume file path to be read
47            self.read(cfg)
48        else:
49            # Assume existing config type object
50            self.cfg = cfg
51
52        if self.cfg:
53            self.parse(**parseKw)
54           
55    def read(self, cfgFilePath):
56        '''Read config file into SafeConfigParser instance
57       
58        @type cfgFilePath: pylons config file object
59        @param cfgFilePath: reference to NDG configuration file.'''
60        self.cfg = ConfigParser()
61        self.cfg.read(cfgFilePath)
62 
63    def parse(self, defSection='DEFAULT', layoutSection='layout'):
64        '''Extract content of config file object into self'''
65       
66        # Hostname
67        self.server=self.cfg.get(defSection, 'server')
68
69        # For secure connections
70        self.sslServer = self.cfg.get(defSection, 'sslServer')
71                     
72        # Where Are You From URI - defaults to server root if not set in
73        # config - i.e. assumes same host as client
74        if self.cfg.has_option(defSection, 'wayfURI'):       
75            self.wayfuri = self.cfg.get(defSection, 'wayfURI')
76        else:
77            self.wayfuri = '%s/wayf' % self.server
78
79        # Logout URI can reside on this server or somewhere else determined by
80        # the logout config file setting
81        if self.cfg.has_option(defSection, 'logoutURI'):       
82            self.logoutURI = self.cfg.get(defSection, 'logoutURI')
83        else:
84            self.logoutURI = '%s/logout' % self.server
85           
86        self.localLink=self.cfg.get(layoutSection, 'localLink', None)
87        self.localImage=self.cfg.get(layoutSection, 'localImage', None)
88        self.localAlt=self.cfg.get(layoutSection, 'localAlt', 'Visit Local Site')
89        self.ndgLink=self.cfg.get(layoutSection, 'ndgLink', 'http://ndg.nerc.ac.uk')
90        self.ndgImage=self.cfg.get(layoutSection, 'ndgImage', None)
91        self.ndgAlt=self.cfg.get(layoutSection, 'ndgAlt','Visit NDG')
92        self.stfcLink=self.cfg.get(layoutSection, 'stfcLink')
93        self.stfcImage=self.cfg.get(layoutSection, 'stfcImage')
94        self.helpIcon=self.cfg.get(layoutSection, 'helpIcon')
95        self.LeftAlt=self.cfg.get(layoutSection, 'HdrLeftAlt')
96        self.LeftLogo=self.cfg.get(layoutSection, 'HdrLeftLogo')
97        self.pageLogo="bodcHdr"
98        self.icons_xml=self.cfg.get(layoutSection,'Xicon')
99        self.icons_plot=self.cfg.get(layoutSection,'plot')
100        self.icons_prn=self.cfg.get(layoutSection, 'printer')
101       
102        self.disclaimer = self.cfg.get(defSection, 'disclaimer')
103   
104        # TODO: re-include security settings to enable logout via Session
105        # Manager
Note: See TracBrowser for help on using the repository browser.