Changeset 8196 for trunk/ndg_oauth/ndg_oauth_server
- Timestamp:
- 19/10/12 22:18:42 (8 years ago)
- Location:
- trunk/ndg_oauth/ndg_oauth_server/ndg/oauth/server
- Files:
-
- 4 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ndg_oauth/ndg_oauth_server/ndg/oauth/server/examples/bearer_tok/__init__.py
r8080 r8196 1 """NDG OAuth examples package 2 3 """ 4 __author__ = "P J Kershaw" 5 __date__ = "20/11/08" 6 __copyright__ = "(C) 2009 Science and Technology Facilities Council" 7 __contact__ = "Philip.Kershaw@stfc.ac.uk" 8 __revision__ = "$Id:$" -
trunk/ndg_oauth/ndg_oauth_server/ndg/oauth/server/examples/bearer_tok/bearer_tok_server_app_serve.py
r8195 r8196 1 #from paste.script.serve import ServeCommand2 #3 #ServeCommand("serve").run(["bearer_tok_server_app.ini"])4 1 #!/usr/bin/env python 5 """NDG Security test harness for security web services middleware stack2 """NDG OAuth test harness for bearer token example 6 3 7 4 """ 8 5 __author__ = "P J Kershaw" 9 6 __date__ = "20/11/08" 10 __copyright__ = "(C) 20 09Science and Technology Facilities Council"7 __copyright__ = "(C) 2012 Science and Technology Facilities Council" 11 8 __contact__ = "Philip.Kershaw@stfc.ac.uk" 12 __revision__ = "$Id:$" 9 __revision__ = "$Id:$" 13 10 from os import path 14 import optparse 15 16 from OpenSSL import SSL 17 from OpenSSL import crypto 18 from paste.deploy import loadapp 19 from paste.script.util.logging_config import fileConfig 20 21 THIS_DIR = path.dirname(__file__) 22 SHARED_CONFIG_DIR = path.join(THIS_DIR, '..', 'shared_config') 23 PKI_DIR = path.join(SHARED_CONFIG_DIR, 'pki') 24 CACERT_DIR = path.join(PKI_DIR, 'ca') 25 26 import paste.httpserver 27 from threading import Thread 28 29 30 class PasteDeployAppServer(object): 31 """Wrapper to paste.httpserver to enable background threading""" 32 33 def __init__(self, app=None, cfgFilePath=None, port=7443, host='0.0.0.0', 34 ssl_context=None): 35 """Load an application configuration from cfgFilePath ini file and 36 instantiate Paste server object 37 """ 38 self.__thread = None 39 40 if cfgFilePath: 41 if app: 42 raise KeyError('Set either the "cfgFilePath" or "app" keyword ' 43 'but not both') 44 45 fileConfig(cfgFilePath, defaults={'here':path.dirname(cfgFilePath)}) 46 app = loadapp('config:%s' % cfgFilePath) 47 48 elif app is None: 49 raise KeyError('Either the "cfgFilePath" or "app" keyword must be ' 50 'set') 51 52 self.__pasteServer = paste.httpserver.serve(app, host=host, port=port, 53 start_loop=False, 54 ssl_context=ssl_context) 55 56 @property 57 def pasteServer(self): 58 return self.__pasteServer 59 60 @property 61 def thread(self): 62 return self.__thread 63 64 def start(self): 65 """Start server""" 66 self.pasteServer.serve_forever() 67 68 def startThread(self): 69 """Start server in a separate thread""" 70 self.__thread = Thread(target=PasteDeployAppServer.start, args=(self,)) 71 self.thread.start() 72 73 def terminateThread(self): 74 self.pasteServer.server_close() 75 76 77 class OpenSSLVerifyCallbackMiddleware(object): 78 """Set peer certificate retrieved from PyOpenSSL SSL context callback in 79 environ dict SSL_CLIENT_CERT item 80 81 FOR TESTING PURPOSES ONLY - IT IS NOT THREAD SAFE 82 """ 83 def __init__(self, app): 84 self._app = app 85 self.ssl_client_cert = None 86 self.ssl_client_cert_dn = None 87 # self.ignore_pat = 'localhost' 88 self.ignore_pat = None 89 90 def createSSLCallback(self): 91 """Make a SSL Context callback function and return it to the caller""" 92 def _callback(conn, x509, errnum, errdepth, ok): 93 if errdepth == 0: 94 subject = x509.get_subject() 95 components = subject.get_components() 96 if self.ignore_pat not in [i[-1] for i in components]: 97 self.ssl_client_cert = crypto.dump_certificate( 98 crypto.FILETYPE_PEM, x509) 99 self.ssl_client_cert_dn = '/'+ '/'.join( 100 ['%s=%s' % i for i in components]) 101 return ok 102 103 return _callback 104 105 def __call__(self, environ, start_response): 106 """Set the latest peer SSL client certificate from the SSL callback 107 into environ SSL_CLIENT_CERT key""" 108 if self.ssl_client_cert: 109 environ['SSL_CLIENT_CERT'] = self.ssl_client_cert 110 environ['SSL_CLIENT_S_DN'] = self.ssl_client_cert_dn 111 self.ssl_client_cert = None 112 113 return self._app(environ, start_response) 114 115 116 class ApacheSSLVariablesMiddleware(object): 117 """Simulate Apache SSL environment setting relevant environ variables""" 118 def __init__(self, app): 119 self._app = app 120 121 def __call__(self, environ, start_response): 122 environ['HTTPS'] = '1' 123 return self._app(environ, start_response) 124 125 11 12 from ndg.oauth.server.examples.utils import serve_app 13 126 14 INI_FILENAME = 'bearer_tok_server_app.ini' 127 15 … … 130 18 # $ ./securityservicesapp.py -h 131 19 if __name__ == '__main__': 132 cfgFilePath = path.join(path.dirname(path.abspath(__file__)), INI_FILENAME) 133 134 defCertFilePath = path.join(PKI_DIR, 'host.pem') 135 defPriKeyFilePath = path.join(PKI_DIR, 'host.pem') 136 137 parser = optparse.OptionParser() 138 parser.add_option("-p", 139 "--port", 140 dest="port", 141 default=5000, 142 type='int', 143 help="port number to run under") 144 145 parser.add_option("-s", 146 "--with-ssl", 147 dest="withSSL", 148 default='True', 149 help="Run with SSL") 150 151 parser.add_option("-c", 152 "--cert-file", 153 dest='certFilePath', 154 default=defCertFilePath, 155 help="SSL Certificate file") 156 157 parser.add_option("-k", 158 "--private-key-file", 159 default=defPriKeyFilePath, 160 dest='priKeyFilePath', 161 help="SSL private key file") 162 163 parser.add_option("-f", 164 "--conf", 165 dest="configFilePath", 166 default=cfgFilePath, 167 help="Configuration file path") 168 169 parser.add_option("-a", 170 "--with-ssl-client-auth", 171 dest="ssl_client_authn", 172 action='store_true', 173 default=True, 174 help="Set client authentication with SSL (requires -s " 175 "option") 176 177 opt = parser.parse_args()[0] 178 cfgFilePath = path.abspath(opt.configFilePath) 179 180 if opt.withSSL.lower() == 'true': 181 ssl_context = SSL.Context(SSL.SSLv23_METHOD) 182 183 ssl_context.set_session_id('oauthserver') 184 ssl_context.use_privatekey_file(opt.priKeyFilePath) 185 ssl_context.use_certificate_file(opt.certFilePath) 186 187 ssl_context.load_verify_locations(None, CACERT_DIR) 188 ssl_context.set_verify_depth(9) 189 190 # Load the application from the Paste ini file configuration 191 fileConfig(cfgFilePath, defaults={'here': path.dirname(cfgFilePath)}) 192 app = loadapp('config:%s' % cfgFilePath) 193 194 if opt.ssl_client_authn: 195 # Wrap the application in middleware to set the SSL client certificate 196 # obtained from the SSL handshake in environ 197 app = OpenSSLVerifyCallbackMiddleware(app) 198 _callback = app.createSSLCallback() 199 200 # Wrap in middleware to simulate Apache environment 201 app = ApacheSSLVariablesMiddleware(app) 202 203 ssl_context.set_verify(SSL.VERIFY_PEER, _callback) 204 205 server = PasteDeployAppServer(app=app, 206 port=opt.port, 207 ssl_context=ssl_context) 208 else: 209 ssl_context = None 210 211 server = PasteDeployAppServer(cfgFilePath=cfgFilePath, 212 port=opt.port, 213 ssl_context=ssl_context) 214 server.start() 20 config_filepath = path.join(path.dirname(path.abspath(__file__)), 21 INI_FILENAME) 22 serve_app(INI_FILENAME) -
trunk/ndg_oauth/ndg_oauth_server/ndg/oauth/server/examples/slcs/slcs_server_app.ini
r8123 r8196 1 1 # 2 # NDG OAuth Server - Pylons development environment configuration 2 # NDG OAuth Server - consisting of 3 # * a generic OAuth Authorisation Server which authenticates users by 4 # username/password on a web form 5 # * a resource server. This is a specialised one which enables delegated 6 # clients to obtain short-lived X.509 certificate credentials. It does this 7 # by using the Contrail Online CA package 3 8 # 4 9 # The %(here)s variable will be replaced with the parent directory of this file … … 23 28 pipeline = BeakerSessionFilter 24 29 repoze_who 25 AuthnForm 26 MyProxyClient 27 OAuth2Authz 28 OAuth2ServerFilterApp 30 AuthenticationFormFilter 31 OAuth2AuthorisationFilter 32 OAuth2ServerFilter 33 OAuth2ResourceServerFilter 34 OnlineCaFilterApp 29 35 30 36 # This filter sets up a server side session linked to a cookie. The session … … 49 55 log_level = debug 50 56 51 [filter:Auth nForm]57 [filter:AuthenticationFormFilter] 52 58 paste.filter_app_factory = ndg.oauth.server.wsgi.authentication_filter:AuthenticationFormMiddleware.filter_app_factory 53 59 authenticationForm.base_url_path = /authentication … … 69 75 authenticationForm.layout.helpIcon = /layout/help.png 70 76 71 72 [filter:MyProxyClient] 73 paste.filter_app_factory = myproxy.server.wsgi.middleware:MyProxyClientMiddleware.filter_app_factory 74 # Default environ key for MyProxy client 75 # myproxy.client.clientEnvKeyName=myproxy.server.wsgi.middleware.MyProxyClientMiddleware.myProxyClient 76 77 # MyProxy server which this MyProxy WSGI app is a client to. Set here to the 78 # fully qualified domain name or else set the MYPROXY_SERVER environment 79 # variable. Setting here overrides any environment variable setting. See the 80 # documentation for the MyProxyClient package for details 81 #myproxy.client.hostname = localhost 82 #myproxy.client.port = 7512 83 84 # CA Certificate directory to enable this application to trust the MyProxy 85 # server that it fronts e.g. set to /etc/grid-security/certificates. For these 86 # tests set to local ca directory 87 myproxy.client.caCertDir = %(here)s/../shared_config/pki/ca 88 89 [filter:OAuth2Authz] 77 [filter:OAuth2AuthorisationFilter] 90 78 # Authorization filter configuration options - defaults are commented out. 91 79 paste.filter_app_factory = ndg.oauth.server.wsgi.authorization_filter:Oauth2AuthorizationMiddleware.filter_app_factory 92 80 oauth2authorization.base_url_path=/client_authorization 93 oauth2authorization.client_authorization_form=%(here)s/ ndg/oauth/server/templates/auth_client_form.html81 oauth2authorization.client_authorization_form=%(here)s/templates/auth_client_form.html 94 82 #oauth2authorization.client_authorizations_key=client_authorizations 95 83 oauth2authorization.client_register=%(here)s/client_register.ini … … 105 93 oauth2authorization.layout.helpIcon = /layout/icons/help.png 106 94 107 [ app:OAuth2Server]108 paste. app_factory = ndg.oauth.server.wsgi.oauth2_server:Oauth2ServerMiddleware.app_factory95 [filter:OAuth2ServerFilter] 96 paste.filter_app_factory = ndg.oauth.server.wsgi.oauth2_server:Oauth2ServerMiddleware.filter_app_factory 109 97 110 98 # OAuth2 server configuration options - defaults are commented out. 111 99 #oauth2server.access_token_lifetime=86400 112 # Allowed values: slcs (default) or bearer (which returns a UUID) 113 oauth2server.access_token_type=slcs 100 # Allowed values: slcs (returns a cert as access token) or bearer (which 101 # returns a UUID). bearer is the default 102 #oauth2server.access_token_type=slcs 114 103 #oauth2server.access_token_type=bearer 115 104 #oauth2server.authorization_grant_lifetime=600 … … 122 111 #oauth2server.client_authorizations_key=client_authorizations 123 112 oauth2server.client_register=%(here)s/client_register.ini 124 #oauth2server.myproxy_client_key=myproxy.server.wsgi.middleware.MyProxyClientMiddleware.myProxyClient125 oauth2server.myproxy_global_password=testpassword126 113 #oauth2server.session_key_name=beaker.session.oauth2server 127 114 #oauth2server.user_identifier_key=REMOTE_USER … … 141 128 #oauth2server.cache.authorizationgrantregister.lock_dir 142 129 143 [filter-app:OAuth2ServerFilterApp] 130 [filter:OAuth2ResourceServerFilter] 131 paste.filter_app_factory = ndg.oauth.server.wsgi.resource_server:Oauth2ResourceServerMiddleware.filter_app_factory 132 oauth2.resource_server.resource_uripaths: /certificate/ 133 134 [app:OnlineCaApp] 135 paste.app_factory = onlineca.server.wsgi.app:OnlineCaApp.app_factory 136 137 # Set an alternative prefix for settings - default is 'onlineca.server.' 138 #prefix: online-ca. 139 140 # Path to CA Python class constructor or factory function 141 onlineca.server.ca_class_factory_path: onlineca.server.impl:CertificateAuthorityImpl 142 143 # onlineca.server.ca_class.* values correspond to settings for the CA class. 144 # The CA class is embedded into the online CA via an interface. It is used to 145 # issue certificates. The settings below apply to the 146 # ca.impl.CertificateAuthority class 147 148 # CA certificate file location 149 onlineca.server.ca_class.cert_filepath: %(here)s/test-ca.crt 150 151 # CA certificate private key file location 152 onlineca.server.ca_class.key_filepath: %(here)s/test-ca.key 153 154 # Password for CA private key file. Omit this option if no password is set 155 #onlineca.server.ca_class.key_passwd: 156 157 # Default number of bits for key pair. Certificate signing requests submitted 158 # with public keys with less than this minimum will be rejected. The default is 159 # 2048 160 onlineca.server.min_key_nbits: 2048 161 162 # Template to set the form for the certificate subject name for output 163 # certificates. This can reference any key name set in environ - in this case, 164 # 'REMOTE_USER' 165 onlineca.server.cert_subject_name_template: /O=NDG/OU=Security/CN=$REMOTE_USER 166 167 # URI path for certificate issuing endpoint. e.g. if online ca app is mounted 168 # at https://myonlineca.somewhere.ac.uk/onlineca and issue_cert_uripath is 169 # /issue_cert/, then the full path would be, 170 # 171 # https://myonlineca.somewhere.ac.uk/onlineca/issue_cert/ 172 # 173 # Default path is /certificate/ 174 #onlineca.server.issue_cert_uripath: /issue-cert/ 175 176 # URI path for trustroots retrieval endpoint. The default path is 177 # /trustroots/ 178 #onlineca.server.trustroots_uripath: /trusted-cas/ 179 180 # Directory where trustroots should be read from and returned via the 181 # trustroots call. It is vital that this is path is carefully selected and 182 # checked. 183 onlineca.server.trustroots_dir: %(here)s/ca/ 184 185 [filter-app:OnlineCaFilterApp] 144 186 use = egg:Paste#httpexceptions 145 187 next = cascade … … 147 189 [composit:cascade] 148 190 use = egg:Paste#cascade 149 app1 = O Auth2Server191 app1 = OnlineCaApp 150 192 app2 = StaticContent 151 193 catch = 404 … … 154 196 use = egg:Paste#static 155 197 document_root = %(here)s/static 156 157 # WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*158 # Debug mode will enable the interactive debugging tool, allowing ANYONE to159 # execute malicious code after an exception is raised.160 #set debug = false161 198 162 199 -
trunk/ndg_oauth/ndg_oauth_server/ndg/oauth/server/examples/slcs/slcs_server_app_serve.py
r8122 r8196 1 from paste.script.serve import ServeCommand 1 #!/usr/bin/env python 2 """NDG OAuth test harness for Short-Lived Credential Service bearer token 3 example 2 4 3 ServeCommand("serve").run(["slcs_server_app.ini"]) 5 """ 6 __author__ = "P J Kershaw" 7 __date__ = "20/11/08" 8 __copyright__ = "(C) 2012 Science and Technology Facilities Council" 9 __contact__ = "Philip.Kershaw@stfc.ac.uk" 10 __revision__ = "$Id:$" 11 from os import path 12 13 from ndg.oauth.server.examples.utils import serve_app 14 15 INI_FILENAME = "slcs_server_app.ini" 16 17 18 if __name__ == '__main__': 19 config_filepath = path.join(path.dirname(path.abspath(__file__)), 20 INI_FILENAME) 21 serve_app(INI_FILENAME) -
trunk/ndg_oauth/ndg_oauth_server/ndg/oauth/server/wsgi/authorization_filter.py
r8057 r8196 21 21 22 22 log = logging.getLogger(__name__) 23 23 24 24 25 class Oauth2AuthorizationMiddleware(object): … … 48 49 propertyDefaults = { 49 50 BASE_URL_PATH_OPTION: 'client_authorization', 50 RENDERER_CLASS_OPTION: 'ndg.oauth.server.lib.render.genshi_renderer.GenshiRenderer', 51 RENDERER_CLASS_OPTION: \ 52 'ndg.oauth.server.lib.render.genshi_renderer.GenshiRenderer', 51 53 SESSION_KEY_OPTION: 'beaker.session.oauth2authorization', 52 54 CLIENT_AUTHORIZATIONS_KEY_OPTION: 'client_authorizations', … … 125 127 if req.path_info.startswith(self.base_path): 126 128 actionPath = req.path_info[len(self.base_path):] 129 127 130 methodName = self.__class__.method.get(actionPath, '') 128 131 if methodName: … … 130 133 action = getattr(self, methodName) 131 134 return action(req, session, start_response) 135 132 136 elif self._app is not None: 133 137 log.debug("Delegating to lower filter/application.") 134 138 self._set_client_authorizations_in_environ(session, environ) 135 139 return self._app(environ, start_response) 140 136 141 else: 137 142 response = "OAuth 2.0 Authorization Filter - Invalid URL" … … 154 159 client_authorizations = session.get(self.CLIENT_AUTHORIZATIONS_SESSION_KEY) 155 160 if client_authorizations: 156 log.debug("_set_client_authorizations_in_environ %s", client_authorizations.__repr__()) 161 log.debug("_set_client_authorizations_in_environ %r", 162 client_authorizations) 157 163 environ[self.client_authorizations_env_key] = client_authorizations 158 164 else: 159 log.debug("%s not found in session", self.CLIENT_AUTHORIZATIONS_SESSION_KEY) 165 log.debug("%s not found in session", 166 self.CLIENT_AUTHORIZATIONS_SESSION_KEY) 160 167 161 168 def authorize(self, req, session, start_response): … … 179 186 user = req.params.get('user') 180 187 original_url = req.params.get('original_url') 181 log.debug("Client authorization request for client_id: %s scope: %s user: %s", client_id, scope, user) 182 183 client_authorizations = session.get(self.CLIENT_AUTHORIZATIONS_SESSION_KEY) 188 log.debug("Client authorization request for client_id: %s scope: %s " 189 "user: %s", client_id, scope, user) 190 191 client_authorizations = session.get( 192 self.CLIENT_AUTHORIZATIONS_SESSION_KEY) 184 193 client_authorized = None 185 194 if client_authorizations: 186 client_authorized = client_authorizations.is_client_authorized_by_user(user, client_id, scope) 195 client_authorized = \ 196 client_authorizations.is_client_authorized_by_user(user, 197 client_id, 198 scope) 199 187 200 if client_authorized is None: 188 201 # No existing decision - let user decide. … … 194 207 } 195 208 session.save() 196 log.debug("Client not authorized by user - returning authorization form.") 209 log.debug("Client not authorized by user - returning authorization " 210 "form.") 197 211 return self._client_auth_form(client_id, scope, req, start_response) 198 212 else: 199 log.debug("Client already %s authorization by user.", ("granted" if client_authorized else "denied")) 213 log.debug("Client already %s authorization by user.", 214 ("granted" if client_authorized else "denied")) 200 215 log.debug("Redirecting to %s", original_url) 201 216 return self._redirect(original_url, start_response) … … 204 219 def _client_auth_form(self, client_id, scope, req, start_response): 205 220 """ 206 Returns a form for the user to enter an authorization de sicion.221 Returns a form for the user to enter an authorization decision. 207 222 208 223 @type client_id: str … … 263 278 log.error("No session context.") 264 279 response = 'Internal server error' 265 start_response(self._get_http_status_string(httplib.INTERNAL_SERVER_ERROR), 266 [('Content-type', 'text/html'), 267 ('Content-length', str(len(response))) 268 ]) 280 status_str = self._get_http_status_string( 281 httplib.INTERNAL_SERVER_ERROR) 282 start_response(status_str, 283 [('Content-type', 'text/html'), 284 ('Content-length', str(len(response))) 285 ]) 269 286 return [response] 270 287 271 if ('submit' in req.params) and ('cancel' not in req.params):288 if 'submit' in req.params and 'cancel' not in req.params: 272 289 log.debug("User authorized client.") 273 290 granted = True … … 277 294 278 295 # Add authorization to those for the user. 279 client_authorizations = session.setdefault(self.CLIENT_AUTHORIZATIONS_SESSION_KEY, ClientAuthorizationRegister()) 296 client_authorizations = session.setdefault( 297 self.CLIENT_AUTHORIZATIONS_SESSION_KEY, 298 ClientAuthorizationRegister()) 280 299 client_id = call_context['client_id'] 281 300 scope = call_context['scope'] 282 301 user = call_context['user'] 283 log.debug("Adding client authorization for client_id: %s scope: %s user: %s", client_id, scope, user) 284 client_authorizations.add_client_authorization(ClientAuthorization(user, client_id, scope, granted)) 302 log.debug("Adding client authorization for client_id: %s scope: %s " 303 "user: %s", client_id, scope, user) 304 305 client_authorization = ClientAuthorization(user, client_id, scope, 306 granted) 307 client_authorizations.add_client_authorization(client_authorization) 308 285 309 session[self.CLIENT_AUTHORIZATIONS_SESSION_KEY] = client_authorizations 286 log.debug("### client_auth: % s", client_authorizations.__repr__())310 log.debug("### client_auth: %r", client_authorizations) 287 311 session.save() 288 312 … … 303 327 """ 304 328 cls = self.__class__ 305 self.base_path = cls._get_config_option(prefix, local_conf, cls.BASE_URL_PATH_OPTION) 306 self.client_register_file = cls._get_config_option(prefix, local_conf, cls.CLIENT_REGISTER_OPTION) 307 self.renderer_class = cls._get_config_option(prefix, local_conf, cls.RENDERER_CLASS_OPTION) 308 self.session_env_key = cls._get_config_option(prefix, local_conf, cls.SESSION_KEY_OPTION) 309 self.client_authorization_form = cls._get_config_option(prefix, local_conf, cls.CLIENT_AUTHORIZATION_FORM_OPTION) 310 self.client_authorizations_env_key = cls._get_config_option(prefix, local_conf, cls.CLIENT_AUTHORIZATIONS_KEY_OPTION) 311 self.user_identifier_env_key = cls._get_config_option(prefix, local_conf, cls.USER_IDENTIFIER_KEY_OPTION) 329 self.base_path = cls._get_config_option( 330 prefix, 331 local_conf, 332 cls.BASE_URL_PATH_OPTION) 333 self.client_register_file = cls._get_config_option( 334 prefix, 335 local_conf, 336 cls.CLIENT_REGISTER_OPTION) 337 self.renderer_class = cls._get_config_option( 338 prefix, 339 local_conf, 340 cls.RENDERER_CLASS_OPTION) 341 self.session_env_key = cls._get_config_option( 342 prefix, local_conf, 343 cls.SESSION_KEY_OPTION) 344 self.client_authorization_form = cls._get_config_option( 345 prefix, 346 local_conf, 347 cls.CLIENT_AUTHORIZATION_FORM_OPTION) 348 self.client_authorizations_env_key = cls._get_config_option(prefix, 349 local_conf, 350 cls.CLIENT_AUTHORIZATIONS_KEY_OPTION) 351 self.user_identifier_env_key = cls._get_config_option( 352 prefix, 353 local_conf, 354 cls.USER_IDENTIFIER_KEY_OPTION) 312 355 313 356 @staticmethod … … 318 361 log.debug("Redirecting to %s", url) 319 362 start_response(self._get_http_status_string(httplib.FOUND), 320 [('Location', url.encode('ascii', 'ignore'))])363 [('Location', url.encode('ascii', 'ignore'))]) 321 364 return [] 322 365 -
trunk/ndg_oauth/ndg_oauth_server/ndg/oauth/server/wsgi/oauth2_server.py
r8195 r8196 67 67 USER_IDENTIFIER_GRANT_DATA_KEY = 'user_identifier' 68 68 69 AUTHORISATION_SERVER_ENVIRON_KEYNAME = 'ndg.server.authorisation.server' 70 69 71 # Configuration option defaults 70 propertyDefaults= {72 PROPERTY_DEFAULTS = { 71 73 ACCESS_TOKEN_LIFETIME_OPTION: 86400, 72 74 ACCESS_TOKEN_TYPE_OPTION: 'bearer', … … 77 79 CLIENT_AUTHORIZATION_URL_OPTION: '/client_authorization/authorize', 78 80 CLIENT_AUTHORIZATIONS_KEY_OPTION: 'client_authorizations', 79 MYPROXY_CLIENT_KEY_OPTION: 'myproxy.server.wsgi.middleware.MyProxyClientMiddleware.myProxyClient', 81 MYPROXY_CLIENT_KEY_OPTION: \ 82 'myproxy.server.wsgi.middleware.MyProxyClientMiddleware.myProxyClient', 80 83 USER_IDENTIFIER_KEY_OPTION: 'REMOTE_USER' 81 84 } … … 177 180 log.debug("Request path_info: %s", req.path_info) 178 181 182 # Set Authorisation Server as key in environ for access by downstream 183 # middleware or app. For example, a resource server can use it to 184 # check access tokens presented to it from clients against ones issued 185 # by the authorisation server 186 environ[self.__class__.AUTHORISATION_SERVER_ENVIRON_KEYNAME 187 ] = self._authorizationServer 188 179 189 # Determine what operation the URL specifies. 180 190 actionPath = None … … 463 473 conf[k[plen:]] = v 464 474 cls = self.__class__ 475 465 476 self.base_path = cls._get_config_option(conf, cls.BASE_URL_PATH_OPTION) 466 self.authorization_grant_lifetime_seconds = cls._get_config_option(conf, cls.AUTHORIZATION_GRANT_LIFETIME_OPTION) 467 self.access_token_lifetime_seconds = cls._get_config_option(conf, cls.ACCESS_TOKEN_LIFETIME_OPTION) 468 self.access_token_type = cls._get_config_option(conf, cls.ACCESS_TOKEN_TYPE_OPTION) 469 self.certificate_request_parameter = cls._get_config_option(conf, cls.CERTIFICATE_REQUEST_PARAMETER_OPTION) 470 self.client_authorization_url = cls._get_config_option(conf, cls.CLIENT_AUTHORIZATION_URL_OPTION) 471 self.client_authentication_method = cls._get_config_option(conf, cls.CLIENT_AUTHENTICATION_METHOD_OPTION) 472 self.client_authorizations_env_key = cls._get_config_option(conf, cls.CLIENT_AUTHORIZATIONS_KEY_OPTION) 473 self.client_register_file = cls._get_config_option(conf, cls.CLIENT_REGISTER_OPTION) 474 self.myproxy_client_env_key = cls._get_config_option(conf, cls.MYPROXY_CLIENT_KEY_OPTION) 475 self.myproxy_global_password = cls._get_config_option(conf, cls.MYPROXY_GLOBAL_PASSWORD_OPTION) 476 self.user_identifier_env_key = cls._get_config_option(conf, cls.USER_IDENTIFIER_KEY_OPTION) 477 self.authorization_grant_lifetime_seconds = cls._get_config_option( 478 conf, cls.AUTHORIZATION_GRANT_LIFETIME_OPTION) 479 self.access_token_lifetime_seconds = cls._get_config_option( 480 conf, cls.ACCESS_TOKEN_LIFETIME_OPTION) 481 self.access_token_type = cls._get_config_option( 482 conf, cls.ACCESS_TOKEN_TYPE_OPTION) 483 self.certificate_request_parameter = cls._get_config_option( 484 conf, cls.CERTIFICATE_REQUEST_PARAMETER_OPTION) 485 self.client_authorization_url = cls._get_config_option( 486 conf, cls.CLIENT_AUTHORIZATION_URL_OPTION) 487 self.client_authentication_method = cls._get_config_option( 488 conf, cls.CLIENT_AUTHENTICATION_METHOD_OPTION) 489 self.client_authorizations_env_key = cls._get_config_option( 490 conf, cls.CLIENT_AUTHORIZATIONS_KEY_OPTION) 491 self.client_register_file = cls._get_config_option( 492 conf, cls.CLIENT_REGISTER_OPTION) 493 self.myproxy_client_env_key = cls._get_config_option( 494 conf, cls.MYPROXY_CLIENT_KEY_OPTION) 495 self.myproxy_global_password = cls._get_config_option( 496 conf, cls.MYPROXY_GLOBAL_PASSWORD_OPTION) 497 self.user_identifier_env_key = cls._get_config_option( 498 conf, cls.USER_IDENTIFIER_KEY_OPTION) 499 477 500 # Return any options that start with the prefix but haven't been read 478 501 # above. … … 481 504 @classmethod 482 505 def _get_config_option(cls, conf, key): 483 value = conf.pop(key, cls. propertyDefaults.get(key, None))506 value = conf.pop(key, cls.PROPERTY_DEFAULTS.get(key, None)) 484 507 log.debug("Oauth2ServerMiddleware configuration %s=%s", key, value) 485 508 return value
Note: See TracChangeset
for help on using the changeset viewer.