source: MILK/trunk/milk_server/milk_server/config/ndgMiddleware.py @ 4482

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/MILK/trunk/milk_server/milk_server/config/ndgMiddleware.py@4482
Revision 4482, 6.0 KB checked in by cbyrom, 11 years ago (diff)

Replace 'viewItems' controller and flesh out selected Items controller - to allow user to plot results out in Google Earth and conTerra +
add wmc client section to config file to allow this to be specified as
an alternative service + tidy up some logging and unused code + update
prototype version to avoid IE problems.

Line 
1# ndg middleware
2from paste.deploy import CONFIG
3from milk_server.lib.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        cf= CONFIG['app_conf']['configfile']
18        cf=myConfig(cf)
19     
20        self.globals=g
21        self.globals.htdocs=cf.get('DEFAULT','htdocs',None)
22        self.globals.localLink=cf.get('layout','localLink',None)
23        self.globals.localAlt=cf.get('layout','localAlt','Visit Local Site')
24        self.globals.ndgLink=cf.get('layout','ndgLink','http://ndg.nerc.ac.uk')
25        self.globals.ndgImage=cf.get('layout','ndgImage',None)
26        self.globals.ndgAlt=cf.get('layout','ndgAlt','Visit NDG')
27        self.globals.stfcLink=cf.get('layout','stfcLink')
28        self.globals.stfcImage=cf.get('layout','stfcImage')
29        self.globals.helpIcon=cf.get('layout','helpIcon')
30        self.globals.navPlus=cf.get('layout','navPlus')
31        self.globals.navMinus=cf.get('layout','navMinus')
32        self.globals.LeftAlt=cf.get('layout','HdrLeftAlt')
33        self.globals.LeftLogo=cf.get('layout','HdrLeftLogo')
34        self.globals.pageLogo="bodcHdr"
35        self.globals.icons_xml=cf.get('layout','Xicon')
36        self.globals.icons_plot=cf.get('layout','plot')
37        self.globals.icons_prn=cf.get('layout','printer')
38        self.globals.icons_A=cf.get('NDG_A_SERVICE','icon')
39        self.globals.icons_B=cf.get('NDG_B_SERVICE','icon')
40        self.globals.icons_D=cf.get('DISCOVERY','icon')
41        self.globals.icons_R=cf.get('RELATED','icon')
42        self.globals.icons_key=cf.get('layout','key')
43       
44        self.globals.atomEditorEnabled = cf.get('ATOM_EDITOR','enabled')
45        self.globals.debugAtomEditor = cf.get('ATOM_EDITOR','debug')
46
47        self.globals.wmcClientURL = cf.get('WMC_CLIENT','url')
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.