dj2.2: middleware compatibility (#41238)
This commit is contained in:
parent
265db4d4c2
commit
a8ff468ce2
|
@ -4,7 +4,7 @@ from authentic2 import logger
|
|||
|
||||
|
||||
# Add the XForwardedForMiddleware
|
||||
MIDDLEWARE_CLASSES = ('authentic2.middleware.XForwardedForMiddleware',) + MIDDLEWARE_CLASSES
|
||||
MIDDLEWARE = ('authentic2.middleware.XForwardedForMiddleware',) + MIDDLEWARE
|
||||
|
||||
# Debian defaults
|
||||
DEBUG = False
|
||||
|
|
|
@ -13,7 +13,7 @@ with open('/usr/lib/hobo/debian_config_common.py') as fd:
|
|||
exec(fd.read())
|
||||
|
||||
# Add the XForwardedForMiddleware
|
||||
MIDDLEWARE_CLASSES = ('authentic2.middleware.XForwardedForMiddleware',) + MIDDLEWARE_CLASSES
|
||||
MIDDLEWARE = ('authentic2.middleware.XForwardedForMiddleware',) + MIDDLEWARE
|
||||
|
||||
# Add authentic settings loader
|
||||
TENANT_SETTINGS_LOADERS = ('hobo.multitenant.settings_loaders.Authentic',) + TENANT_SETTINGS_LOADERS
|
||||
|
|
|
@ -27,6 +27,7 @@ except ImportError:
|
|||
from binascii import hexlify
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.six.moves.urllib import parse as urlparse
|
||||
|
@ -96,7 +97,7 @@ logging_handler = ThreadTrackingHandler(collector)
|
|||
logging.root.addHandler(logging_handler)
|
||||
|
||||
|
||||
class LoggingCollectorMiddleware(object):
|
||||
class LoggingCollectorMiddleware(MiddlewareMixin):
|
||||
def process_request(self, request):
|
||||
collector.clear_collection()
|
||||
|
||||
|
@ -110,7 +111,7 @@ class LoggingCollectorMiddleware(object):
|
|||
request.exception = exception
|
||||
|
||||
|
||||
class CollectIPMiddleware(object):
|
||||
class CollectIPMiddleware(MiddlewareMixin):
|
||||
def process_response(self, request, response):
|
||||
# only collect IP if session is used
|
||||
if not hasattr(request, 'session') or request.session.is_empty():
|
||||
|
@ -125,7 +126,7 @@ class CollectIPMiddleware(object):
|
|||
return response
|
||||
|
||||
|
||||
class OpenedSessionCookieMiddleware(object):
|
||||
class OpenedSessionCookieMiddleware(MiddlewareMixin):
|
||||
def process_response(self, request, response):
|
||||
# do not emit cookie for API requests
|
||||
if request.path.startswith('/api/'):
|
||||
|
@ -144,7 +145,7 @@ class OpenedSessionCookieMiddleware(object):
|
|||
return response
|
||||
|
||||
|
||||
class RequestIdMiddleware(object):
|
||||
class RequestIdMiddleware(MiddlewareMixin):
|
||||
def process_request(self, request):
|
||||
if not hasattr(request, 'request_id'):
|
||||
request_id_header = getattr(settings, 'REQUEST_ID_HEADER', None)
|
||||
|
@ -159,7 +160,7 @@ class RequestIdMiddleware(object):
|
|||
encoding='ascii')
|
||||
|
||||
|
||||
class StoreRequestMiddleware(object):
|
||||
class StoreRequestMiddleware(MiddlewareMixin):
|
||||
collection = {}
|
||||
|
||||
def process_request(self, request):
|
||||
|
@ -177,7 +178,7 @@ class StoreRequestMiddleware(object):
|
|||
return cls.collection.get(threading.currentThread())
|
||||
|
||||
|
||||
class ViewRestrictionMiddleware(object):
|
||||
class ViewRestrictionMiddleware(MiddlewareMixin):
|
||||
RESTRICTION_SESSION_KEY = 'view-restriction'
|
||||
|
||||
def check_view_restrictions(self, request):
|
||||
|
@ -210,7 +211,7 @@ class ViewRestrictionMiddleware(object):
|
|||
return utils.redirect_and_come_back(request, view)
|
||||
|
||||
|
||||
class XForwardedForMiddleware(object):
|
||||
class XForwardedForMiddleware(MiddlewareMixin):
|
||||
'''Copy the first address from X-Forwarded-For header to the REMOTE_ADDR meta.
|
||||
|
||||
This middleware should only be used if you are sure the header cannot be
|
||||
|
@ -221,7 +222,7 @@ class XForwardedForMiddleware(object):
|
|||
return None
|
||||
|
||||
|
||||
class DisplayMessageBeforeRedirectMiddleware(object):
|
||||
class DisplayMessageBeforeRedirectMiddleware(MiddlewareMixin):
|
||||
'''Verify if messages are currently stored and if there is a redirection to another domain, in
|
||||
this case show an intermediate page.
|
||||
'''
|
||||
|
@ -261,7 +262,7 @@ class DisplayMessageBeforeRedirectMiddleware(object):
|
|||
{'url': url, 'only_info': only_info})
|
||||
|
||||
|
||||
class ServiceAccessControlMiddleware(object):
|
||||
class ServiceAccessControlMiddleware(MiddlewareMixin):
|
||||
def process_exception(self, request, exception):
|
||||
if not isinstance(exception, (utils.ServiceAccessDenied,)):
|
||||
return None
|
||||
|
|
|
@ -87,7 +87,7 @@ TEMPLATES = [
|
|||
]
|
||||
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
MIDDLEWARE = (
|
||||
'authentic2.middleware.StoreRequestMiddleware',
|
||||
'authentic2.middleware.RequestIdMiddleware',
|
||||
'authentic2.middleware.LoggingCollectorMiddleware',
|
||||
|
@ -103,14 +103,14 @@ MIDDLEWARE_CLASSES = (
|
|||
|
||||
DATABASES['default']['ATOMIC_REQUESTS'] = True
|
||||
|
||||
MIDDLEWARE_CLASSES += (
|
||||
MIDDLEWARE += (
|
||||
'authentic2.middleware.DisplayMessageBeforeRedirectMiddleware',
|
||||
'authentic2.middleware.CollectIPMiddleware',
|
||||
'authentic2.middleware.ViewRestrictionMiddleware',
|
||||
'authentic2.middleware.OpenedSessionCookieMiddleware',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = plugins.register_plugins_middleware(MIDDLEWARE_CLASSES)
|
||||
MIDDLEWARE = plugins.register_plugins_middleware(MIDDLEWARE)
|
||||
|
||||
ROOT_URLCONF = 'authentic2.urls'
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import os
|
|||
|
||||
from django.conf import global_settings
|
||||
|
||||
MIDDLEWARE_CLASSES = global_settings.MIDDLEWARE_CLASSES
|
||||
MIDDLEWA_CLASSES = global_settings.MIDDLEWARE
|
||||
|
||||
SECRET_KEY = 'whatever'
|
||||
DATABASES = {
|
||||
|
|
Loading…
Reference in New Issue