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

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

Add new run mode - debug for atom editor - to display stack trace with
any errors experienced - add necessary code + templates for this +
add new templates for the granulator web page + add template function
to allow generic uploading of data files and start connecting this into
the code - to allow ingest of granulite and CSML/CDML data.

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        self.globals.debugAtomEditor = cf.get('ATOM_EDITOR','debug')
48       
49        self.globals.disclaimer=cf.get('default','disclaimer')
50       
51        self.globals.discoveryURL=cf.get('SEARCH','discoveryURL')
52       
53        self.globals.server=cf.get('DEFAULT','server','')
54
55        # for standalone discovery
56        self.globals.standalone=cf.config.getboolean('DISCOVERY','standalone')
57
58        # NB, without this set, the default host on ndg.badc.rl.ac.uk will be used by ndgSearch
59        if cf.config.has_option('DISCOVERY', 'discoveryServiceURL'):
60            self.globals.discoveryServiceURL = \
61                cf.config.get('DISCOVERY', 'discoveryServiceURL')       
62
63       
64        # Security Related
65
66        # Single Sign On settings - check for mode of operation:
67        # 1) act as a client to a separate Single Sign On Service
68        # or
69        # 2) Single Sign On service is integrated into THIS service
70        securityEnabled = not self.globals.standalone
71        isSSOClient = cf.config.has_section('NDG_SECURITY.ssoClient') and \
72            securityEnabled
73           
74        isSSOService = cf.config.has_section('NDG_SECURITY.ssoService') and \
75            securityEnabled
76           
77        if isSSOClient and isSSOService:
78            raise NDGConfigError(\
79                "NDG_SECURITY.ssoClient and NDG_SECURITY.ssoService " + \
80                "sections are present in the NDG Config file: " + \
81                "only one or the other may be set")
82 
83        if isSSOClient:
84            try:
85                from \
86            ndg.security.client.ssoclient.ssoclient.config.ssoClientMiddleware\
87                    import SSOMiddleware
88            except ImportError, e:
89                # If standalone flag is not present security must be enabled
90                raise NDGConfigError(\
91                    '%s: importing Single Sign On Client SSOMiddleware: %s' % \
92                        (__name__, e))
93                       
94               
95            self.app = SSOMiddleware(app, cf.config, g, app_conf,
96                                     defSection='NDG_SECURITY.ssoClient')
97           
98            self.globals.sslServer = g.ndg.security.common.sso.cfg.sslServer
99            self.globals.wayfuri=g.ndg.security.common.sso.cfg.wayfuri
100            self.globals.logout=g.ndg.security.common.sso.cfg.logoutURI
101           
102        elif isSSOService:
103            try:
104                from ndg.security.server.sso.sso.config.ssoServiceMiddleware \
105                    import SSOMiddleware
106            except ImportError, e:
107                # If standalone flag is not present security must be enabled
108                raise NDGConfigError(\
109                    '%s: importing Single Sign On Service SSOMiddleware: %s' %\
110                        (__name__, e))
111                       
112               
113            self.app = SSOMiddleware(app, g, app_conf,
114                                     defSection='NDG_SECURITY.ssoService',
115                                     wssSection='NDG_SECURITY.wssecurity')
116           
117            self.globals.sslServer=g.ndg.security.server.sso.cfg.sslServer
118            self.globals.wayfuri=g.ndg.security.server.sso.cfg.wayfuri
119            self.globals.logout=g.ndg.security.server.sso.cfg.logoutURI
120            self.globals.getCredentials=g.ndg.security.server.sso.cfg.getCredentials
121
122        # Policy Enforcement Point initialisation
123        if securityEnabled:
124            try:
125                from ndg.security.common.authz.pep import PEP
126            except ImportError, e:
127                # If standalone flag is not present security must be enabled
128                raise NDGConfigError('%s: expecting standalone config ' % \
129                        __name__ + 
130                        'flag set to False for Policy Enforcement Point ' + \
131                        'import: %s' % e)
132           
133            self.globals.pep = PEP(cfg=cf.config, 
134                                   cfgSection='NDG_SECURITY.gatekeeper')
135           
136        self.config=cf
137       
138       
139    def __call__(self,environ,start_response):
140       
141        environ['ndgConfig']=self.config
142        return self.app(environ,start_response)
143   
Note: See TracBrowser for help on using the repository browser.