horizon/openstack_auth
Mathieu Gagné 8851866aad Fix django.contrib.auth.middleware monkey patching
The "request" attribute is not available in
openstack_auth.backend.KeystoneBackend.get_user when session data is restored
and it's the first request to happen after a server restart.

As stated by the function document, the "request" attribute needs to be
monkey-patched by openstack_auth.utils.patch_middleware_get_user
for this function to work properly.

This should happen in openstack_auth.urls at import time. But there is nowhere
in Horizon where this module is imported at startup. It's only introspected
by openstack_dashboard.urls due to AUTHENTICATION_URLS setting.

Without this monkey-patching, the whole authentication mechanism falls back
to "AnonymousUser" and you will get redirected to the login page due
to horizon.exceptions.NotAuthenticated being raised by
horizon.decorators.require_auth as request.user.is_authenticated will be False.

But if a user requests a page under auth/, it will have the side-effect of
monkey-patching django.contrib.auth.middleware as expected. This means that
once this request is completed, all following requests to pages other than
the ones under auth/ will have there sessions properly restored and
you will be properly authenticated.

Therefore this change introduces a dummy middleware which sole purpose is
to perform this monkey-patching as early as possible.

There is also some cleanup to get rid of the previous attempts at
monkeypatching.

Closes-bug: #1764622

Conflicts:
	openstack_dashboard/settings.py
	openstack_dashboard/test/helpers.py

Change-Id: Ib9912090a87b716e7f5710f6f360b0df168ec2e3
(cherry picked from commit 0d16361326)
2018-11-20 21:24:04 +09:00
..
locale Imported Translations from Zanata 2018-09-09 07:50:51 +00:00
plugin Fix log message formatting 2018-07-16 13:18:47 +03:00
tests Fix django.contrib.auth.middleware monkey patching 2018-11-20 21:24:04 +09:00
__init__.py Add Django OpenStack Auth to Horizon 2017-09-27 12:06:57 +01:00
backend.py django2: is_authenticated/is_anonymous is now property only 2018-02-17 01:36:54 +09:00
exceptions.py Add Django OpenStack Auth to Horizon 2017-09-27 12:06:57 +01:00
forms.py Remove the redundant "required=True" 2018-07-23 09:42:41 +08:00
middleware.py Fix django.contrib.auth.middleware monkey patching 2018-11-20 21:24:04 +09:00
models.py Add Django OpenStack Auth to Horizon 2017-09-27 12:06:57 +01:00
policy.py Fix api.keystone.is_cloud_admin/is_domain_admin handling with new policies 2018-01-17 15:14:33 +01:00
urls.py Fix django.contrib.auth.middleware monkey patching 2018-11-20 21:24:04 +09:00
user.py Rework DEFAULT_SERVICE_REGIONS 2018-07-17 13:58:24 +12:00
utils.py Fix django.contrib.auth.middleware monkey patching 2018-11-20 21:24:04 +09:00
views.py support WEBSSO_KEYSTONE_URL 2018-10-29 13:27:11 -07:00