Browse Source

Use MiddlewareMixin instead

pull/160/head
ariannedee 5 years ago
parent
commit
eb9657d94e
2 changed files with 5 additions and 28 deletions
  1. +2
    -14
      edivorce/apps/core/middleware/basicauth_middleware.py
  2. +3
    -14
      edivorce/apps/core/middleware/bceid_middleware.py

+ 2
- 14
edivorce/apps/core/middleware/basicauth_middleware.py View File

@ -1,12 +1,12 @@
import base64 import base64
import sys
from django.http import HttpResponse from django.http import HttpResponse
from django.conf import settings from django.conf import settings
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.deprecation import MiddlewareMixin
class BasicAuthMiddleware:
class BasicAuthMiddleware(MiddlewareMixin):
""" """
Simple Basic Authentication module to password protect test environments Simple Basic Authentication module to password protect test environments
based on : https://djangosnippets.org/snippets/2468/ based on : https://djangosnippets.org/snippets/2468/
@ -14,18 +14,6 @@ class BasicAuthMiddleware:
implementation allows environment variables to be used to store implementation allows environment variables to be used to store
username + password username + password
""" """
def __init__(self, get_response=None):
self.get_response = get_response
super().__init__()
def __call__(self, request):
response = None
if hasattr(self, 'process_request'):
response = self.process_request(request)
if not response:
response = self.get_response(request)
return response
def process_request(self, request): def process_request(self, request):
# allow all OpenShift health checks # allow all OpenShift health checks


+ 3
- 14
edivorce/apps/core/middleware/bceid_middleware.py View File

@ -4,13 +4,14 @@ from ipaddress import ip_address, ip_network
from django.conf import settings from django.conf import settings
from django.shortcuts import redirect from django.shortcuts import redirect
from django.utils import timezone from django.utils import timezone
from django.utils.deprecation import MiddlewareMixin
from ..models import BceidUser from ..models import BceidUser
login_delta = datetime.timedelta(hours=2) login_delta = datetime.timedelta(hours=2)
class AnonymousUser():
class AnonymousUser:
""" """
Anonymous user, present mainly to provide authentication checks in templates Anonymous user, present mainly to provide authentication checks in templates
""" """
@ -31,7 +32,7 @@ class AnonymousUser():
anonymous_user = AnonymousUser() anonymous_user = AnonymousUser()
class BceidMiddleware: # pylint: disable=too-few-public-methods
class BceidMiddleware(MiddlewareMixin): # pylint: disable=too-few-public-methods
""" """
Simple authentication middleware for operating in the BC Government Simple authentication middleware for operating in the BC Government
OpenShift environment, with SiteMinder integration. OpenShift environment, with SiteMinder integration.
@ -69,18 +70,6 @@ class BceidMiddleware: # pylint: disable=too-few-public-methods
In a local development environment, we generate a guid based on the login In a local development environment, we generate a guid based on the login
name and treat that guid/login name as guid/display name. name and treat that guid/login name as guid/display name.
""" """
def __init__(self, get_response=None):
self.get_response = get_response
super().__init__()
def __call__(self, request):
response = None
if hasattr(self, 'process_request'):
response = self.process_request(request)
if not response:
response = self.get_response(request)
return response
def process_request(self, request): # pylint: disable=too-many-branches def process_request(self, request): # pylint: disable=too-many-branches
""" """
Return None after populating request.user, or necessary redirects. Return None after populating request.user, or necessary redirects.


Loading…
Cancel
Save