Changeset 4909
- Timestamp:
- 06/02/09 16:56:59 (12 years ago)
- Location:
- TI12-security/trunk/python
- Files:
-
- 29 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/ndg.security.server/ndg/security/server/wsgi/__init__.py
r4907 r4909 12 12 import httplib 13 13 14 14 class NDGSecurityMiddlewareError(Exception): 15 '''Base exception class for NDG Security middleware''' 16 17 class NDGSecurityMiddlewareConfigError(NDGSecurityMiddlewareError): 18 '''NDG Security Middleware Configuration error''' 19 15 20 class NDGSecurityMiddlewareBase(object): 16 21 """Base class for NDG Security Middleware classes""" … … 109 114 return response 110 115 116 @staticmethod 117 def getStatusMessage(statusCode): 118 '''Make a standard status message for use with start_response 119 @type statusCode: int 120 @param statusCode: HTTP status code 121 @rtype: str 122 @return: status code with standard message 123 @raise KeyError: for invalid status code 124 ''' 125 return '%d %s' % (statusCode, httplib.responses[statusCode]) 126 111 127 # Utility functions to support Paste Deploy application and filter function 112 128 # signatures … … 235 251 fset=_setStart_response, 236 252 doc="Reference to WSGI start_response function") 237 253 254 255 def _redirect(self, url, start_response=None): 256 """Do a HTTP 302 redirect 257 258 @type start_response: callable following WSGI start_response convention 259 @param start_response: WSGI start response callable 260 @type url: basestring 261 @param url: URL to redirect to 262 @rtype: list 263 @return: empty HTML body 264 """ 265 if start_response is None: 266 # self.start_response will be None if initCall decorator wasn't 267 # applied to __call__ 268 if start_response is None: 269 raise NDGSecurityMiddlewareConfigError("No start_response " 270 "function set.") 271 start_response = self.start_response 272 273 start_response(NDGSecurityMiddlewareBase.getStatusMessage(302), 274 [('Content-type', 'text/html'), 275 ('Content-length', '0'), 276 ('Location', url)]) 277 return [] 278 279 238 280 class NDGSecurityPathFilter(NDGSecurityMiddlewareBase): 239 """Speciali zation of NDG Security Middleware to enable filtering based on281 """Specialisation of NDG Security Middleware to enable filtering based on 240 282 PATH_INFO 241 283 … … 259 301 260 302 _isSSLRequest = lambda self: self.environ.get( 261 NDGSecurityPathFilter.sslKeyName) == '1'303 NDGSecurityPathFilter.sslKeyName) == '1' 262 304 isSSLRequest = property(fget=_isSSLRequest, 263 doc="Approximation for is an SSL request boolean " 264 "- depends on Apache config SSLOptions " 265 "StdEnvVars option being set") 305 doc="Is an SSL request boolean " 306 "- depends on Apache config") 266 307 267 308 def __init__(self, *arg, **kw): 268 309 super(NDGSecurityPathFilter, self).__init__(*arg, **kw) 269 self._pathMatchList = []270 310 271 311 def _getPathMatchList(self): … … 286 326 if isinstance(pathList, basestring): 287 327 # Try parsing a space separated list of file paths 288 self._pathMatchList = pathList.split()328 self._pathMatchList=[path.strip() for path in pathList.split(',')] 289 329 290 330 elif not isinstance(pathList, (list, tuple)): -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/wsgi/authn.py
r4855 r4909 1 1 """HTTP Basic Authentication Middleware 2 2 3 NERC Data 3 NERC DataGrid Project 4 4 5 5 """ … … 7 7 __date__ = "13/01/09" 8 8 __copyright__ = "(C) 2009 Science and Technology Facilities Council" 9 __license__ = "BSD - see LICENSE file in top-level directory" 9 10 __contact__ = "Philip.Kershaw@stfc.ac.uk" 10 11 __revision__ = "$Id$" -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/wsgi/openid/relyingparty/__init__.py
r4907 r4909 33 33 'signinInterfaceMiddlewareClass': None, 34 34 'baseURL': '', 35 'sessionKey': 'beaker.session', 36 'reservedPaths': [] 35 'sessionKey': 'beaker.session' 37 36 } 38 37 propertyDefaults.update(NDGSecurityMiddlewareBase.propertyDefaults) … … 120 119 log.debug('No referer set for redirect following logout') 121 120 122 # if self.pathInfo not in self.reservedPaths: 121 # Set a return to address following logout. 122 # TODO: This code will need to be refactored if this middleware is 123 # deployed externally via a proxy - HTTP_REFERER will be the internal 124 # URI instead of the one exposed outside 123 125 if 'HTTP_REFERER' in environ: 124 126 session['ndg.security.server.wsgi.openid.relyingparty.referer'] = \ … … 150 152 151 153 return self._app(environ, set401UnauthorizedReponse) 152 153 def _redirect(self, url):154 """Do a HTTP 302 redirect155 156 @type url: basestring157 @param url: URL to redirect to158 @rtype: list159 @return: empty HTML body160 """161 self.start_response('302 %s' % httplib.responses[302],162 [('Content-type', 'text/html'),163 ('Location', url)])164 return []165 154 166 def _setReservedPaths(self, paths):167 if isinstance(paths, basestring):168 self._reservedPaths = [path.strip() for path in paths.split(',')]169 elif isinstance(paths, (tuple, list)):170 self._reservedPaths = paths171 else:172 raise AttributeError("Reserved paths must be a string or list or "173 "tuple")174 def _getReservedPaths(self):175 return self._reservedPaths176 177 reservedPaths = property(fget=_getReservedPaths,178 fset=_setReservedPaths,179 doc="Set paths that logout redirect must avoid "180 "e.g. AuthKit OpenID processing")181 155 182 156 class SigninInterfaceError(Exception): -
TI12-security/trunk/python/ndg.security.server/ndg/security/server/wsgi/pep/__init__.py
r4863 r4909 8 8 __contact__ = "Philip.Kershaw@stfc.ac.uk" 9 9 __revision__ = "$Id$" 10 __license__ = "BSD "10 __license__ = "BSD - see LICENSE file in top-levle directory" 11 11 import logging 12 12 log = logging.getLogger(__name__) … … 27 27 sslServerDNKeyName = 'SSL_SERVER_S_DN' 28 28 29 def __init__(self, *arg, **kw):29 def __init__(self, app, app_conf, prefix='', **local_conf): 30 30 log.debug("Initialising PEPMiddleware ...") 31 super(PEPMiddleware, self).__init__(*arg, **kw) 31 32 super(PEPMiddleware, self).__init__(app, app_conf, prefix=prefix, 33 **local_conf) 32 34 self.charset = '; charset=utf-8' 33 35 34 @NDGSecurity MiddlewareBase.initCall36 @NDGSecurityPathFilter.initCall 35 37 def __call__(self, environ, start_response): 36 log.debug(" CallingPEPMiddleware.__call__ ...")38 log.debug("PEPMiddleware.__call__ ...") 37 39 38 # TODO: Is a security session set?39 if True:40 log.info('No security session is set')41 else:42 log.info('Security session is set')43 if self.isSSLRequest:44 45 response = self._redirectFromHTTPS2HTTP(start_response)46 if response is not None:47 return response48 49 40 # Is this requested URL secured? 50 41 if self.pathMatch: 51 return self._setErrorResponse(environ, 52 start_response, 53 code=self.errorResponseCode) 42 # return self._setErrorResponse(environ, 43 # start_response, 44 # code=self.errorResponseCode) 45 def _start_response(status, header, exc_info=None): 46 '''alter start_response to return unauthorised status 47 48 @type status: str 49 @param status: HTTP status code and status message 50 @type header: list 51 @param header: list of field, value tuple HTTP header content 52 @type exc_info: Exception 53 @param exc_info: exception info 54 ''' 55 log.debug('[%s] is a secured URI: setting 403 status...' % 56 self.pathInfo) 57 58 _status = self.getStatusMessage(403) 59 60 return start_response(_status, header, exc_info) 61 54 62 else: 55 # User is logged in - Redirect to HTTP based URL and complete 56 # Policy enforcement 57 pass 58 # if self.isSSLRequest: 59 # response = self._redirectFromHTTPS2HTTP(start_response) 60 # if response is not None: 61 # return response 63 _start_response = start_response 62 64 63 return self._setResponse(environ, start_response) 65 return self._setResponse(environ, _start_response) 66 64 67 65 68 def _redirectFromHTTPS2HTTP(self, start_response): -
TI12-security/trunk/python/ndg.security.test/ndg/security/test/combinedservices/singlesignonservice/sso.cfg
r4890 r4909 16 16 # content such as graphics and stylesheets 17 17 #configDir=%(here)s 18 configDir=/home/pjkersha/workspace/security/python/ndg.security.server/ndg/security/server/sso/sso/badc_site 18 19 19 20 # Switch from default templates package to templates/ in alternative directory 20 #templatesPackage: ndg.security.server.sso.sso.badc_site.templates21 templatesPackage: ndg.security.server.sso.sso.badc_site.templates 21 22 22 23 # Redirect SOAP output to a file e.g. open(<somefile>, 'w') -
TI12-security/trunk/python/ndg.security.test/ndg/security/test/openidrelyingparty/services.ini
r4907 r4909 3 3 # 4 4 # Paste configuration for OpenID Relying Party test service 5 # * Session Manager6 # * Attribute Authority7 5 # 8 6 # The %(here)s variable will be replaced with the parent directory of this file … … 34 32 [filter:SessionMiddlewareFilter] 35 33 paste.filter_app_factory=beaker.middleware:SessionMiddleware 36 #beaker.session.key = sso37 34 beaker.session.secret = somesecret 38 35 … … 48 45 49 46 openid.relyingparty.sessionKey = beaker.session 50 openid.relyingparty.baseURL = http://localhost:5600 51 openid.relyingparty.reservedPaths = %(authkit.openid.path.process)s, %(authkit.openid.path.verify)s 47 openid.relyingparty.baseURL = %(authkit.openid.baseurl)s 52 48 openid.relyingparty.signinInterfaceMiddlewareClass = ndg.security.server.wsgi.openid.relyingparty.signin_interface.buffet.BuffetSigninTemplate 53 49 openid.relyingparty.signinInterface.templatePackage = ndg.security.server.wsgi.openid.relyingparty.signin_interface.buffet.templates … … 70 66 authkit.cookie.signoutpath = /logout 71 67 authkit.openid.path.signedin=/ 72 #authkit.openid.path.process=/PROCESS73 #authkit.openid.path.verify=/VERIFY74 authkit.openid.path.process=/process75 authkit.openid.path.verify=/verify76 68 authkit.openid.store.type=file 77 69 authkit.openid.store.config=%(here)s/data/openid
Note: See TracChangeset
for help on using the changeset viewer.