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

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

Improve look + feel - esp. on windows IE + pass debug flag into
validator + properly handle empty author content.

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') or False
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                                       isDebug = self.globals.debugAtomEditor)
71
72        # initialise collection to store re-usable connections to the eXist DB
73        self.globals.eXistDBCons = {}
74       
75        # Security Related
76
77        # Single Sign On settings - check for mode of operation:
78        # 1) act as a client to a separate Single Sign On Service
79        # or
80        # 2) Single Sign On service is integrated into THIS service
81        securityEnabled = not self.globals.standalone
82        isSSOClient = cf.config.has_section('NDG_SECURITY.ssoClient') and \
83            securityEnabled
84           
85        isSSOService = cf.config.has_section('NDG_SECURITY.ssoService') and \
86            securityEnabled
87           
88        if isSSOClient and isSSOService:
89            raise NDGConfigError(\
90                "NDG_SECURITY.ssoClient and NDG_SECURITY.ssoService " + \
91                "sections are present in the NDG Config file: " + \
92                "only one or the other may be set")
93 
94        if isSSOClient:
95            try:
96                from \
97            ndg.security.client.ssoclient.ssoclient.config.ssoClientMiddleware\
98                    import SSOMiddleware
99            except ImportError, e:
100                # If standalone flag is not present security must be enabled
101                raise NDGConfigError(\
102                    '%s: importing Single Sign On Client SSOMiddleware: %s' % \
103                        (__name__, e))
104                       
105               
106            self.app = SSOMiddleware(app, cf.config, g, app_conf,
107                                     defSection='NDG_SECURITY.ssoClient')
108           
109            self.globals.sslServer = g.ndg.security.common.sso.cfg.sslServer
110            self.globals.wayfuri=g.ndg.security.common.sso.cfg.wayfuri
111            self.globals.logout=g.ndg.security.common.sso.cfg.logoutURI
112           
113        elif isSSOService:
114            try:
115                from ndg.security.server.sso.sso.config.ssoServiceMiddleware \
116                    import SSOMiddleware
117            except ImportError, e:
118                # If standalone flag is not present security must be enabled
119                raise NDGConfigError(\
120                    '%s: importing Single Sign On Service SSOMiddleware: %s' %\
121                        (__name__, e))
122                       
123               
124            self.app = SSOMiddleware(app, g, app_conf,
125                                     defSection='NDG_SECURITY.ssoService',
126                                     wssSection='NDG_SECURITY.wssecurity')
127           
128            self.globals.sslServer=g.ndg.security.server.sso.cfg.sslServer
129            self.globals.wayfuri=g.ndg.security.server.sso.cfg.wayfuri
130            self.globals.logout=g.ndg.security.server.sso.cfg.logoutURI
131            self.globals.getCredentials=g.ndg.security.server.sso.cfg.getCredentials
132
133        # Policy Enforcement Point initialisation
134        if securityEnabled:
135            try:
136                from ndg.security.common.authz.pep import PEP
137            except ImportError, e:
138                # If standalone flag is not present security must be enabled
139                raise NDGConfigError('%s: expecting standalone config ' % \
140                        __name__ + 
141                        'flag set to False for Policy Enforcement Point ' + \
142                        'import: %s' % e)
143           
144            self.globals.pep = PEP(cfg=cf.config, 
145                                   cfgSection='NDG_SECURITY.gatekeeper')
146           
147        self.config=cf
148       
149       
150    def __call__(self,environ,start_response):
151       
152        environ['ndgConfig']=self.config
153        return self.app(environ,start_response)
154   
Note: See TracBrowser for help on using the repository browser.