1 | ''' |
---|
2 | Class defining the config params for the milk server |
---|
3 | ''' |
---|
4 | from paste.deploy import CONFIG |
---|
5 | from ndgUtils.models.myconfig import myConfig |
---|
6 | from ndgUtils.lib.atomvalidator import AtomValidator |
---|
7 | import milk_server.lib.helpers as h |
---|
8 | |
---|
9 | class NDGConfigError(Exception): |
---|
10 | '''Errors related to reading from ndg config file''' |
---|
11 | |
---|
12 | class milkMiddleware: |
---|
13 | |
---|
14 | def __init__(self, app, g, app_conf): |
---|
15 | |
---|
16 | #this is the next application in the wsgi stack |
---|
17 | self.app=app |
---|
18 | |
---|
19 | #set up the ndg configuration file |
---|
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.localAlt=cf.get('layout','localAlt','Visit Local Site') |
---|
27 | self.globals.ndgLink=cf.get('layout','ndgLink','http://ndg.nerc.ac.uk') |
---|
28 | self.globals.ndgImage=cf.get('layout','ndgImage',None) |
---|
29 | self.globals.ndgAlt=cf.get('layout','ndgAlt','Visit NDG') |
---|
30 | self.globals.stfcLink=cf.get('layout','stfcLink') |
---|
31 | self.globals.stfcImage=cf.get('layout','stfcImage') |
---|
32 | self.globals.helpIcon=cf.get('layout','helpIcon') |
---|
33 | self.globals.navPlus=cf.get('layout','navPlus') |
---|
34 | self.globals.loadingIcon=cf.get('layout','loadingIcon') |
---|
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.atomEditorEnabled = cf.get('ATOM_EDITOR','enabled') |
---|
49 | self.globals.debugAtomEditor = cf.get('ATOM_EDITOR','debug') or False |
---|
50 | |
---|
51 | self.globals.wmcClientURL = cf.get('WMC_CLIENT','url') |
---|
52 | |
---|
53 | self.globals.disclaimer=cf.get('default','disclaimer') |
---|
54 | |
---|
55 | self.globals.discoveryURL=cf.get('SEARCH','discoveryURL') |
---|
56 | |
---|
57 | self.globals.server=cf.get('DEFAULT','server','') |
---|
58 | |
---|
59 | # for standalone discovery |
---|
60 | self.globals.standalone=cf.config.getboolean('DISCOVERY','standalone') |
---|
61 | |
---|
62 | # NB, without this set, the default host on ndg.badc.rl.ac.uk will be used by ndgSearch |
---|
63 | if cf.config.has_option('DISCOVERY', 'discoveryServiceURL'): |
---|
64 | self.globals.discoveryServiceURL = \ |
---|
65 | cf.config.get('DISCOVERY', 'discoveryServiceURL') |
---|
66 | |
---|
67 | self.globals.pwFile = cf.get('NDG_EXIST','passwordFile') |
---|
68 | # set up the validator for atoms - to allow re-use across the app |
---|
69 | self.globals.validator = AtomValidator(None, self.globals.pwFile, \ |
---|
70 | newLineChar="<br/>", |
---|
71 | isDebug = self.globals.debugAtomEditor) |
---|
72 | |
---|
73 | # initialise collection to store re-usable connections to the eXist DB |
---|
74 | self.globals.eXistDBCons = {} |
---|
75 | |
---|
76 | # Security Related |
---|
77 | |
---|
78 | # Single Sign On settings - check for mode of operation: |
---|
79 | # 1) act as a client to a separate Single Sign On Service |
---|
80 | # or |
---|
81 | # 2) Single Sign On service is integrated into THIS service |
---|
82 | securityEnabled = not self.globals.standalone |
---|
83 | isSSOClient = cf.config.has_section('NDG_SECURITY.ssoClient') and \ |
---|
84 | securityEnabled |
---|
85 | |
---|
86 | isSSOService = cf.config.has_section('NDG_SECURITY.ssoService') and \ |
---|
87 | securityEnabled |
---|
88 | |
---|
89 | if isSSOClient and isSSOService: |
---|
90 | raise NDGConfigError(\ |
---|
91 | "NDG_SECURITY.ssoClient and NDG_SECURITY.ssoService " + \ |
---|
92 | "sections are present in the NDG Config file: " + \ |
---|
93 | "only one or the other may be set") |
---|
94 | |
---|
95 | if isSSOClient: |
---|
96 | try: |
---|
97 | from \ |
---|
98 | ndg.security.client.ssoclient.ssoclient.config.ssoClientMiddleware\ |
---|
99 | import SSOMiddleware |
---|
100 | except ImportError, e: |
---|
101 | # If standalone flag is not present security must be enabled |
---|
102 | raise NDGConfigError(\ |
---|
103 | '%s: importing Single Sign On Client SSOMiddleware: %s' % \ |
---|
104 | (__name__, e)) |
---|
105 | |
---|
106 | |
---|
107 | self.app = SSOMiddleware(app, cf.config, g, app_conf, |
---|
108 | defSection='NDG_SECURITY.ssoClient') |
---|
109 | |
---|
110 | self.globals.sslServer = g.ndg.security.common.sso.cfg.sslServer |
---|
111 | self.globals.wayfuri=g.ndg.security.common.sso.cfg.wayfuri |
---|
112 | self.globals.logout=g.ndg.security.common.sso.cfg.logoutURI |
---|
113 | |
---|
114 | elif isSSOService: |
---|
115 | try: |
---|
116 | from ndg.security.server.sso.sso.config.ssoServiceMiddleware \ |
---|
117 | import SSOMiddleware |
---|
118 | except ImportError, e: |
---|
119 | # If standalone flag is not present security must be enabled |
---|
120 | raise NDGConfigError(\ |
---|
121 | '%s: importing Single Sign On Service SSOMiddleware: %s' %\ |
---|
122 | (__name__, e)) |
---|
123 | |
---|
124 | |
---|
125 | self.app = SSOMiddleware(app, g, app_conf, |
---|
126 | defSection='NDG_SECURITY.ssoService', |
---|
127 | wssSection='NDG_SECURITY.wssecurity') |
---|
128 | |
---|
129 | self.globals.sslServer=g.ndg.security.server.sso.cfg.sslServer |
---|
130 | self.globals.wayfuri=g.ndg.security.server.sso.cfg.wayfuri |
---|
131 | self.globals.logout=g.ndg.security.server.sso.cfg.logoutURI |
---|
132 | self.globals.getCredentials=g.ndg.security.server.sso.cfg.getCredentials |
---|
133 | |
---|
134 | # Policy Enforcement Point initialisation |
---|
135 | if securityEnabled: |
---|
136 | try: |
---|
137 | from ndg.security.common.authz.pep import PEP |
---|
138 | except ImportError, e: |
---|
139 | # If standalone flag is not present security must be enabled |
---|
140 | raise NDGConfigError('%s: expecting standalone config ' % \ |
---|
141 | __name__ + |
---|
142 | 'flag set to False for Policy Enforcement Point ' + \ |
---|
143 | 'import: %s' % e) |
---|
144 | |
---|
145 | self.globals.pep = PEP(cfg=cf.config, |
---|
146 | cfgSection='NDG_SECURITY.gatekeeper') |
---|
147 | |
---|
148 | self.config=cf |
---|
149 | |
---|
150 | self.__setUpHelpText(g) |
---|
151 | |
---|
152 | |
---|
153 | def __setUpHelpText(self, g): |
---|
154 | |
---|
155 | cf = CONFIG['app_conf']['helpConfigfile'] |
---|
156 | cf = myConfig(cf) |
---|
157 | # NB, the cf.config class lowercases everything. |
---|
158 | for (section, val) in cf.config.items('ATOM_EDITOR'): |
---|
159 | setattr(g, section, val) |
---|
160 | |
---|
161 | # extend the granulite example link - to add a valid location |
---|
162 | g.example_granulite = g.example_granulite.replace('HREF', \ |
---|
163 | h.url_for(controller = 'atom_editor/listatom', \ |
---|
164 | action='showExampleGranulite')) |
---|
165 | |
---|
166 | |
---|
167 | def __call__(self,environ,start_response): |
---|
168 | |
---|
169 | environ['ndgConfig']=self.config |
---|
170 | return self.app(environ,start_response) |
---|
171 | |
---|