|
|
@@ -390,14 +390,17 @@ class JsonMessage(object):
|
|
|
|
|
|
class AuditLoggingMiddleware(object):
|
|
|
|
|
|
- def __init__(self, get_response=None):
|
|
|
+ def __init__(self, get_response):
|
|
|
+ self.get_response = get_response
|
|
|
self.impersonator = SERVER_USER.get()
|
|
|
|
|
|
if not AUDIT_EVENT_LOG_DIR.get():
|
|
|
LOG.info('Unloading AuditLoggingMiddleware')
|
|
|
raise exceptions.MiddlewareNotUsed
|
|
|
|
|
|
- def process_response(self, request, response):
|
|
|
+ def __call__(self, request):
|
|
|
+ response = self.get_response(request)
|
|
|
+
|
|
|
response['audited'] = False
|
|
|
try:
|
|
|
if hasattr(request, 'audit') and request.audit is not None:
|
|
|
@@ -405,6 +408,7 @@ class AuditLoggingMiddleware(object):
|
|
|
response['audited'] = True
|
|
|
except Exception as e:
|
|
|
LOG.error('Could not audit the request: %s' % e)
|
|
|
+
|
|
|
return response
|
|
|
|
|
|
def _log_message(self, request, response=None):
|
|
|
@@ -459,7 +463,8 @@ class HtmlValidationMiddleware(object):
|
|
|
"""
|
|
|
If configured, validate output html for every response.
|
|
|
"""
|
|
|
- def __init__(self):
|
|
|
+ def __init__(self, get_response):
|
|
|
+ self.get_response = get_response
|
|
|
self._logger = logging.getLogger('HtmlValidationMiddleware')
|
|
|
|
|
|
if not _has_tidylib:
|
|
|
@@ -494,8 +499,9 @@ class HtmlValidationMiddleware(object):
|
|
|
'wrap': 0,
|
|
|
}
|
|
|
|
|
|
+ def __call__(self, request):
|
|
|
+ response = self.get_response(request)
|
|
|
|
|
|
- def process_response(self, request, response):
|
|
|
if not _has_tidylib or not self._is_html(request, response):
|
|
|
return response
|
|
|
|
|
|
@@ -531,6 +537,7 @@ class HtmlValidationMiddleware(object):
|
|
|
file(filename + '.info', 'w').write(i18n.smart_str(result))
|
|
|
|
|
|
self._logger.error(result)
|
|
|
+
|
|
|
return response
|
|
|
|
|
|
def _filter_warnings(self, err_list):
|
|
|
@@ -552,15 +559,13 @@ class HtmlValidationMiddleware(object):
|
|
|
|
|
|
class ProxyMiddleware(object):
|
|
|
|
|
|
- def __init__(self, get_response=None):
|
|
|
+ def __init__(self, get_response):
|
|
|
+ self.get_response = get_response
|
|
|
if not 'desktop.auth.backend.AllowAllBackend' in AUTH.BACKEND.get():
|
|
|
LOG.info('Unloading ProxyMiddleware')
|
|
|
raise exceptions.MiddlewareNotUsed
|
|
|
|
|
|
- def process_response(self, request, response):
|
|
|
- return response
|
|
|
-
|
|
|
- def process_request(self, request):
|
|
|
+ def __call__(self, request):
|
|
|
view_func = resolve(request.path)[0]
|
|
|
if view_func in DJANGO_VIEW_AUTH_WHITELIST:
|
|
|
return
|
|
|
@@ -594,6 +599,10 @@ class ProxyMiddleware(object):
|
|
|
LOG.exception('Unexpected error when authenticating')
|
|
|
return
|
|
|
|
|
|
+ response = self.get_response(request)
|
|
|
+
|
|
|
+ return response
|
|
|
+
|
|
|
def clean_username(self, username, request):
|
|
|
"""
|
|
|
Allows the backend to clean the username, if the backend defines a
|
|
|
@@ -614,24 +623,15 @@ class SpnegoMiddleware(object):
|
|
|
http://code.activestate.com/recipes/576992/
|
|
|
"""
|
|
|
|
|
|
- def __init__(self, get_response=None):
|
|
|
+ def __init__(self, get_response):
|
|
|
+ self.get_response = get_response
|
|
|
if not set(AUTH.BACKEND.get()).intersection(
|
|
|
set(['desktop.auth.backend.SpnegoDjangoBackend', 'desktop.auth.backend.KnoxSpnegoDjangoBackend'])
|
|
|
):
|
|
|
LOG.info('Unloading SpnegoMiddleware')
|
|
|
raise exceptions.MiddlewareNotUsed
|
|
|
|
|
|
- def process_response(self, request, response):
|
|
|
- if 'GSS-String' in request.META:
|
|
|
- response['WWW-Authenticate'] = request.META['GSS-String']
|
|
|
- elif 'Return-401' in request.META:
|
|
|
- response = HttpResponse("401 Unauthorized", content_type="text/plain",
|
|
|
- status=401)
|
|
|
- response['WWW-Authenticate'] = 'Negotiate'
|
|
|
- response.status = 401
|
|
|
- return response
|
|
|
-
|
|
|
- def process_request(self, request):
|
|
|
+ def __call__(self, request):
|
|
|
"""
|
|
|
The process_request() method needs to communicate some state to the
|
|
|
process_response() method. The two options for this are to return an
|
|
|
@@ -738,6 +738,18 @@ class SpnegoMiddleware(object):
|
|
|
request.META['Return-401'] = ''
|
|
|
return
|
|
|
|
|
|
+ response = self.get_response(request)
|
|
|
+
|
|
|
+ if 'GSS-String' in request.META:
|
|
|
+ response['WWW-Authenticate'] = request.META['GSS-String']
|
|
|
+ elif 'Return-401' in request.META:
|
|
|
+ response = HttpResponse("401 Unauthorized", content_type="text/plain",
|
|
|
+ status=401)
|
|
|
+ response['WWW-Authenticate'] = 'Negotiate'
|
|
|
+ response.status = 401
|
|
|
+
|
|
|
+ return response
|
|
|
+
|
|
|
def clean_host(self, pattern):
|
|
|
hosts = []
|
|
|
if pattern:
|
|
|
@@ -783,7 +795,7 @@ class HueRemoteUserMiddleware(RemoteUserMiddleware):
|
|
|
unload the middleware if the RemoteUserDjangoBackend is not currently
|
|
|
in use.
|
|
|
"""
|
|
|
- def __init__(self, get_respose=None):
|
|
|
+ def __init__(self, get_response):
|
|
|
if not 'desktop.auth.backend.RemoteUserDjangoBackend' in AUTH.BACKEND.get():
|
|
|
LOG.info('Unloading HueRemoteUserMiddleware')
|
|
|
raise exceptions.MiddlewareNotUsed
|
|
|
@@ -847,13 +859,16 @@ class MetricsMiddleware(MiddlewareMixin):
|
|
|
|
|
|
|
|
|
class ContentSecurityPolicyMiddleware(object):
|
|
|
- def __init__(self, get_response=None):
|
|
|
+ def __init__(self, get_response):
|
|
|
+ self.get_response = get_response
|
|
|
self.secure_content_security_policy = SECURE_CONTENT_SECURITY_POLICY.get()
|
|
|
if not self.secure_content_security_policy:
|
|
|
LOG.info('Unloading ContentSecurityPolicyMiddleware')
|
|
|
raise exceptions.MiddlewareNotUsed
|
|
|
|
|
|
- def process_response(self, request, response):
|
|
|
+ def __call__(self, request):
|
|
|
+ response = self.get_response(request)
|
|
|
+
|
|
|
if self.secure_content_security_policy and not 'Content-Security-Policy' in response:
|
|
|
response["Content-Security-Policy"] = self.secure_content_security_policy
|
|
|
|
|
|
@@ -866,13 +881,17 @@ class MimeTypeJSFileFixStreamingMiddleware(object):
|
|
|
as "text/x-js" and if strict X-Content-Type-Options=nosniff is set then browser fails to
|
|
|
execute javascript file.
|
|
|
"""
|
|
|
- def __init__(self, get_response=None):
|
|
|
+ def __init__(self, get_response):
|
|
|
+ self.get_response = get_response
|
|
|
jsmimetypes = ['application/javascript', 'application/ecmascript']
|
|
|
if mimetypes.guess_type("dummy.js")[0] in jsmimetypes:
|
|
|
LOG.info('Unloading MimeTypeJSFileFixStreamingMiddleware')
|
|
|
raise exceptions.MiddlewareNotUsed
|
|
|
|
|
|
- def process_response(self, request, response):
|
|
|
+ def __call__(self, request):
|
|
|
+ response = self.get_response(request)
|
|
|
+
|
|
|
if request.path_info.endswith('.js'):
|
|
|
response['Content-Type'] = "application/javascript"
|
|
|
+
|
|
|
return response
|