source: MILK/trunk/milk_server/milk_server/config/milkMiddleware.py @ 4579

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

Add animated watch icon for page loading and add this to config +
implement usage when ingesting granulite data - since this is very slow.

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