source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/config/ndgMiddleware.py @ 4259

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/config/ndgMiddleware.py@4259
Revision 4259, 6.1 KB checked in by cbyrom, 11 years ago (diff)

Add ability to set the discovery service URL from the ndgDiscovery.config
file + remove unused 'layoutdir' config property.

Line 
1# ndg middleware
2from paste.deploy import CONFIG
3from ows_server.models.Utilities import myConfig
4
5
6class NDGConfigError(Exception): 
7    '''Errors related to reading from ndg config file'''
8     
9class ndgMiddleware:
10   
11    def __init__(self, app, g, app_conf):
12       
13        #this is the next application in the wsgi stack
14        self.app=app
15       
16        #set up the ndg configuration file
17       
18        #Changed by Dom: CONFIG.get wasn't respecting the %(home)s variable, so moved to app_conf section in ini file.
19        #cf=CONFIG.get('configfile')
20        cf= CONFIG['app_conf']['configfile']
21        cf=myConfig(cf)
22     
23        self.globals=g
24        self.globals.htdocs=cf.get('DEFAULT','htdocs',None)
25        self.globals.localLink=cf.get('layout','localLink',None)
26        self.globals.localImage=cf.get('layout','localImage',None)
27        self.globals.localAlt=cf.get('layout','localAlt','Visit Local Site')
28        self.globals.ndgLink=cf.get('layout','ndgLink','http://ndg.nerc.ac.uk')
29        self.globals.ndgImage=cf.get('layout','ndgImage',None)
30        self.globals.ndgAlt=cf.get('layout','ndgAlt','Visit NDG')
31        self.globals.stfcLink=cf.get('layout','stfcLink')
32        self.globals.stfcImage=cf.get('layout','stfcImage')
33        self.globals.helpIcon=cf.get('layout','helpIcon')
34        self.globals.navPlus=cf.get('layout','navPlus')
35        self.globals.navMinus=cf.get('layout','navMinus')
36        self.globals.LeftAlt=cf.get('layout','HdrLeftAlt')
37        self.globals.LeftLogo=cf.get('layout','HdrLeftLogo')
38        self.globals.pageLogo="bodcHdr"
39        self.globals.icons_xml=cf.get('layout','Xicon')
40        self.globals.icons_plot=cf.get('layout','plot')
41        self.globals.icons_prn=cf.get('layout','printer')
42        self.globals.icons_A=cf.get('NDG_A_SERVICE','icon')
43        self.globals.icons_B=cf.get('NDG_B_SERVICE','icon')
44        self.globals.icons_D=cf.get('DISCOVERY','icon')
45        self.globals.icons_R=cf.get('RELATED','icon')
46        self.globals.icons_key=cf.get('layout','key')
47       
48        self.globals.disclaimer=cf.get('default','disclaimer')
49       
50        self.globals.discoveryURL=cf.get('SEARCH','discoveryURL')
51       
52        self.globals.server=cf.get('DEFAULT','server','')
53
54        # for standalone discovery
55        self.globals.standalone=cf.config.getboolean('DISCOVERY','standalone')
56
57        # NB, without this set, the default host on ndg.badc.rl.ac.uk will be used by ndgSearch
58        if cf.config.has_option('DISCOVERY', 'discoveryServiceURL'):
59            self.globals.discoveryServiceURL = \
60                cf.config.get('DISCOVERY', 'discoveryServiceURL')       
61
62       
63        # Security Related
64
65        # Single Sign On settings - check for mode of operation:
66        # 1) act as a client to a separate Single Sign On Service
67        # or
68        # 2) Single Sign On service is integrated into THIS service
69        securityEnabled = not self.globals.standalone
70        isSSOClient = cf.config.has_section('NDG_SECURITY.ssoClient') and \
71            securityEnabled
72           
73        isSSOService = cf.config.has_section('NDG_SECURITY.ssoService') and \
74            securityEnabled
75           
76        if isSSOClient and isSSOService:
77            raise NDGConfigError(\
78                "NDG_SECURITY.ssoClient and NDG_SECURITY.ssoService " + \
79                "sections are present in the NDG Config file: " + \
80                "only one or the other may be set")
81 
82        if isSSOClient:
83            try:
84                from \
85            ndg.security.client.ssoclient.ssoclient.config.ssoClientMiddleware\
86                    import SSOMiddleware
87            except ImportError, e:
88                # If standalone flag is not present security must be enabled
89                raise NDGConfigError(\
90                    '%s: importing Single Sign On Client SSOMiddleware: %s' % \
91                        (__name__, e))
92                       
93               
94            self.app = SSOMiddleware(app, cf.config, g, app_conf,
95                                     defSection='NDG_SECURITY.ssoClient')
96           
97            self.globals.sslServer = g.ndg.security.common.sso.cfg.sslServer
98            self.globals.wayfuri=g.ndg.security.common.sso.cfg.wayfuri
99            self.globals.logout=g.ndg.security.common.sso.cfg.logoutURI
100           
101        elif isSSOService:
102            try:
103                from ndg.security.server.sso.sso.config.ssoServiceMiddleware \
104                    import SSOMiddleware
105            except ImportError, e:
106                # If standalone flag is not present security must be enabled
107                raise NDGConfigError(\
108                    '%s: importing Single Sign On Service SSOMiddleware: %s' %\
109                        (__name__, e))
110                       
111               
112            self.app = SSOMiddleware(app, g, app_conf,
113                                     defSection='NDG_SECURITY.ssoService',
114                                     wssSection='NDG_SECURITY.wssecurity')
115           
116            self.globals.sslServer=g.ndg.security.server.sso.cfg.sslServer
117            self.globals.wayfuri=g.ndg.security.server.sso.cfg.wayfuri
118            self.globals.logout=g.ndg.security.server.sso.cfg.logoutURI
119            self.globals.getCredentials=g.ndg.security.server.sso.cfg.getCredentials
120
121        # Policy Enforcement Point initialisation
122        if securityEnabled:
123            try:
124                from ndg.security.common.authz.pep import PEP
125            except ImportError, e:
126                # If standalone flag is not present security must be enabled
127                raise NDGConfigError('%s: expecting standalone config ' % \
128                        __name__ + 
129                        'flag set to False for Policy Enforcement Point ' + \
130                        'import: %s' % e)
131           
132            self.globals.pep = PEP(cfg=cf.config, 
133                                   cfgSection='NDG_SECURITY.gatekeeper')
134           
135        self.config=cf
136       
137       
138    def __call__(self,environ,start_response):
139       
140        environ['ndgConfig']=self.config
141        return self.app(environ,start_response)
142   
Note: See TracBrowser for help on using the repository browser.