mirror of https://github.com/jumpserver/jumpserver
stash
parent
44ffd09924
commit
e5f4b8000e
|
@ -45,21 +45,7 @@ class MFAMiddleware:
|
|||
class SessionCookieMiddleware(MiddlewareMixin):
|
||||
|
||||
@staticmethod
|
||||
def process_response(request, response: HttpResponse):
|
||||
key = settings.SESSION_COOKIE_NAME_PREFIX_KEY
|
||||
value = settings.SESSION_COOKIE_NAME_PREFIX
|
||||
if request.COOKIES.get(key) == value:
|
||||
return response
|
||||
response.set_cookie(key, value)
|
||||
return response
|
||||
|
||||
|
||||
class EncryptedMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
@staticmethod
|
||||
def check_key_pair(request, response):
|
||||
def set_cookie_public_key(request, response):
|
||||
pub_key_name = settings.SESSION_RSA_PUBLIC_KEY_NAME
|
||||
public_key = request.session.get(pub_key_name)
|
||||
cookie_key = request.COOKIES.get(pub_key_name)
|
||||
|
@ -73,7 +59,15 @@ class EncryptedMiddleware:
|
|||
request.session[pri_key_name] = private_key
|
||||
response.set_cookie(pub_key_name, public_key_decode)
|
||||
|
||||
def __call__(self, request):
|
||||
response = self.get_response(request)
|
||||
self.check_key_pair(request, response)
|
||||
@staticmethod
|
||||
def set_session_cooke_prefix(request, response):
|
||||
key = settings.SESSION_COOKIE_NAME_PREFIX_KEY
|
||||
value = settings.SESSION_COOKIE_NAME_PREFIX
|
||||
if request.COOKIES.get(key) == value:
|
||||
return response
|
||||
response.set_cookie(key, value)
|
||||
|
||||
def process_response(self, request, response: HttpResponse):
|
||||
self.set_session_cooke_prefix(request, response)
|
||||
self.set_session_cooke_prefix(request, response)
|
||||
return response
|
||||
|
|
|
@ -95,7 +95,6 @@ MIDDLEWARE = [
|
|||
'authentication.backends.cas.middleware.CASMiddleware',
|
||||
'authentication.middleware.MFAMiddleware',
|
||||
'authentication.middleware.SessionCookieMiddleware',
|
||||
'authentication.middleware.EncryptedMiddleware',
|
||||
'simple_history.middleware.HistoryRequestMiddleware',
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in New Issue