Package myproxy :: Package ws :: Package server :: Package wsgi :: Module httpbasicauth :: Class HttpBasicAuthMiddleware
[hide private]

Class HttpBasicAuthMiddleware

source code


HTTP Basic Authentication Middleware

Instance Methods [hide private]
 
__init__(self, app)
Create instance variables
source code
 
parseConfig(self, prefix='', **app_conf)
Parse dictionary of configuration items updating the relevant attributes of this instance
source code
basestring
_getAuthnFuncEnvironKeyName(self)
Get authentication callback function environ key name
source code
 
_setAuthnFuncEnvironKeyName(self, value)
Set authentication callback environ key name
source code
tuple or list
_getRePathMatchList(self)
Get regular expression path match list
source code
 
_setRePathMatchList(self, value)
Set regular expression path match list
source code
basestring
_getRealm(self)
Get realm
source code
 
_setRealm(self, value)
Set realm
source code
bool
_pathMatch(self, environ)
Apply a list of regular expression matching patterns to the contents of environ['PATH_INFO'], if any match, return True.
source code
tuple
_parseCredentials(self, environ)
Extract username and password from HTTP_AUTHORIZATION environ key
source code
iterable
__call__(self, environ, start_response)
Authenticate based HTTP header elements as specified by the HTTP Basic Authentication spec.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
myproxy.server.wsgi.httpbasicauth.HttpBasicAuthMiddleware
filter_app_factory(cls, app, global_conf, prefix='http.auth.basic.', **local_conf)
Function following Paste filter app factory signature
source code
list
setErrorResponse(cls, start_response, msg=None, code=401, contentType=None)
Convenience method to set a simple error response
source code
Class Variables [hide private]
string AUTHN_FUNC_ENV_KEYNAME = 'myproxy.server.wsgi.httpbasicauth.Ht...
key name for referencing Authentication callback function in environ.
string AUTHN_FUNC_ENV_KEYNAME_OPTNAME = 'authnFuncEnvKeyName'
in file option name for setting the Authentication callback environ key
  RE_PATH_MATCH_LIST_OPTNAME = 'rePathMatchList'
string REALM_OPTNAME = 'realm'
ini file option name for setting the HTTP Basic Auth authentication realm
string PARAM_PREFIX = 'http.auth.basic.'
prefix for ini file options
string AUTHENTICATE_HDR_FIELDNAME = 'WWW-Authenticate'
HTTP header field name 'WWW-Authenticate'
string AUTHENTICATE_HDR_FIELDNAME_LOWER = 'www-authenticate'
lowercase version of AUTHENTICATE_HDR_FIELDNAME class variable included for convenience with string matching
string AUTHN_SCHEME_HDR_FIELDNAME = 'Basic'
HTTP Authentication scheme identifier
  AUTHN_SCHEME_HDR_FIELDNAME_LOWER = 'basic'
string FIELD_SEP = ':'
field separator for username/password header string
string AUTHZ_ENV_KEYNAME = 'HTTP_AUTHORIZATION'
WSGI environ key name for HTTP Basic Auth header content
string AUTHN_HDR_FORMAT = '%s realm="%s"'
HTTP Basic Auth format string following RFC2617
Instance Variables [hide private]
function __app
next WSGI app/middleware in call chain
string __authnFuncEnvironKeyName
__authnFuncEnvironKeyName
list __rePathMatchList
list of regular expression patterns used to match incoming requests and enforce HTTP Basic Auth against
string __realm
HTTP Basic Auth authentication realm
Properties [hide private]
  authnFuncEnvironKeyName
key name in environ for the custom authentication function used by this class
  rePathMatchList
List of regular expressions determine the URI paths intercepted by this middleware
  realm
HTTP Authentication realm to set in responses

Inherited from object: __class__

Method Details [hide private]

__init__(self, app)
(Constructor)

source code 

Create instance variables

Parameters:
  • app (function) - next middleware/app in WSGI stack
Overrides: object.__init__

filter_app_factory(cls, app, global_conf, prefix='http.auth.basic.', **local_conf)
Class Method

source code 

Function following Paste filter app factory signature

Parameters:
  • app (callable following WSGI interface) - next middleware/application in the chain
  • global_conf (dict) - PasteDeploy global configuration dictionary
  • prefix (basestring) - prefix for configuration items
  • local_conf (dict) - PasteDeploy application specific configuration dictionary
Returns: myproxy.server.wsgi.httpbasicauth.HttpBasicAuthMiddleware
an instance of this middleware

parseConfig(self, prefix='', **app_conf)

source code 

Parse dictionary of configuration items updating the relevant attributes of this instance

Parameters:
  • prefix (basestring) - prefix for configuration items
  • app_conf (dict) - PasteDeploy application specific configuration dictionary

_getAuthnFuncEnvironKeyName(self)

source code 

Get authentication callback function environ key name

Returns: basestring
callback function environ key name

_setAuthnFuncEnvironKeyName(self, value)

source code 

Set authentication callback environ key name

Parameters:
  • value (basestring) - callback function environ key name

_getRePathMatchList(self)

source code 

Get regular expression path match list

Returns: tuple or list
list of regular expressions used to match incoming request paths and apply HTTP Basic Auth to

_setRePathMatchList(self, value)

source code 

Set regular expression path match list

Parameters:
  • value (tuple or list) - list of regular expressions used to match incoming request paths and apply HTTP Basic Auth to

_getRealm(self)

source code 

Get realm

Returns: basestring
HTTP Authentication realm to set in responses

_setRealm(self, value)

source code 

Set realm

Parameters:
  • value (basestring) - HTTP Authentication realm to set in responses

_pathMatch(self, environ)

source code 

Apply a list of regular expression matching patterns to the contents of environ['PATH_INFO'], if any match, return True. This method is used to determine whether to apply SSL client authentication

Parameters:
  • environ (dict) - WSGI environment variables dictionary
Returns: bool
True if request path matches the regular expression list set, False otherwise

_parseCredentials(self, environ)

source code 

Extract username and password from HTTP_AUTHORIZATION environ key

Parameters:
  • environ (dict) - WSGI environ dict
Returns: tuple
username and password. If the key is not set or the auth method is not basic return a two element tuple with elements both set to None

__call__(self, environ, start_response)
(Call operator)

source code 

Authenticate based HTTP header elements as specified by the HTTP Basic Authentication spec.

Parameters:
  • environ (dict-like type) - WSGI environ
  • start_response (function) - WSGI start response function
Returns: iterable
response
Raises:

setErrorResponse(cls, start_response, msg=None, code=401, contentType=None)
Class Method

source code 

Convenience method to set a simple error response

Parameters:
  • start_response (function) - standard WSGI callable to set the HTTP header
  • msg (basestring) - optional error message
  • code (int) - standard HTTP error response code
  • contentType (basestring) - set 'Content-type' HTTP header field - defaults to 'text/plain'
Returns: list
HTTP error response

Class Variable Details [hide private]

AUTHN_FUNC_ENV_KEYNAME

key name for referencing Authentication callback function in environ. Upstream middleware must set this.
Type:
string
Value:
'myproxy.server.wsgi.httpbasicauth.HttpBasicAuthMiddleware.authenticat\
e'

Property Details [hide private]

authnFuncEnvironKeyName

key name in environ for the custom authentication function used by this class

Get Method:
_getAuthnFuncEnvironKeyName(self) - Get authentication callback function environ key name
Set Method:
_setAuthnFuncEnvironKeyName(self, value) - Set authentication callback environ key name

rePathMatchList

List of regular expressions determine the URI paths intercepted by this middleware

Get Method:
_getRePathMatchList(self) - Get regular expression path match list
Set Method:
_setRePathMatchList(self, value) - Set regular expression path match list

realm

HTTP Authentication realm to set in responses

Get Method:
_getRealm(self) - Get realm
Set Method:
_setRealm(self, value) - Set realm