mirror of
https://github.com/ansible/awx.git
synced 2026-05-12 03:47:36 -02:30
Add a new middleware to force-logout local-only users
when the DISABLE_LOCAL_AUTH setting is set. This avoids the ugliness of getting a SuspiciousOperation error for any request/response cycles that are in flight when a user gets bounced.
This commit is contained in:
@@ -7,6 +7,7 @@ import time
|
||||
import urllib.parse
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import logout
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.migrations.executor import MigrationExecutor
|
||||
from django.db import connection
|
||||
@@ -71,6 +72,21 @@ class SessionTimeoutMiddleware(MiddlewareMixin):
|
||||
return response
|
||||
|
||||
|
||||
class DisableLocalAuthMiddleware(MiddlewareMixin):
|
||||
"""
|
||||
Respects the presence of the DISABLE_LOCAL_AUTH setting and forces
|
||||
local-only users to logout when they make a request.
|
||||
"""
|
||||
|
||||
def process_request(self, request):
|
||||
if settings.DISABLE_LOCAL_AUTH:
|
||||
user = request.user
|
||||
if not user.pk:
|
||||
return
|
||||
if not (user.profile.ldap_dn or user.social_auth.exists() or user.enterprise_auth.exists()):
|
||||
logout(request)
|
||||
|
||||
|
||||
def _customize_graph():
|
||||
from awx.main.models import Instance, Schedule, UnifiedJobTemplate
|
||||
|
||||
|
||||
Reference in New Issue
Block a user