horizon/horizon
Mathieu Gagné 6ae1f5e21d 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

[backport specific notice]
Queens horizon supports Django 1.8 and 1.11.
The key point is Django 2.0 is not supported.
Django 2.0 dropped the legacy Django middleware interface and
the new interface is not supported in Django 1.8.
Thus, this backport changes OpenstackAuthMonkeyPatchMiddleware in
openstack_auth/middlware.py to use the legacy middleware interface.

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

Change-Id: Ib9912090a87b716e7f5710f6f360b0df168ec2e3
(cherry picked from commit 0d16361326)
(cherry picked from commit 8851866aad)
2018-11-20 23:29:58 +09:00
..
browsers Enable to refresh ngdetails view 2018-02-01 20:30:03 +09:00
conf hacking: noqa cleanup in horizon 2017-03-17 19:38:47 +00:00
contrib Fix H405 (multi line docstring) warnings (horizon) 2017-06-09 16:04:57 +00:00
forms comment was wrongly declared 2018-01-25 09:42:55 +08:00
hacking Eliminate mutable default arguments 2015-12-17 09:58:46 +00:00
locale Imported Translations from Zanata 2018-08-09 07:34:39 +00:00
management pull_catalog: avoid internet access during module loading 2017-11-21 11:57:43 +00:00
middleware operation_log: Mask more password fields by default 2018-01-31 22:39:22 +09:00
static Use items per page setting on Angular tables 2018-04-10 11:10:46 +04:00
tables Avoid duplicated message in Batch/DeleteAction 2018-01-23 22:46:25 +09:00
tabs Fix H405 (multi line docstring) warnings (horizon) 2017-06-09 16:04:57 +00:00
templates Horizon UI message when browser cookies disabled 2018-01-29 07:58:41 +00:00
templatetags Use flake8-import-order plugin 2017-07-03 08:02:23 +00:00
test Fix django.contrib.auth.middleware monkey patching 2018-11-20 23:29:58 +09:00
utils Merge "Make @memoize thread-aware" 2017-09-11 21:30:00 +00:00
workflows Switch render() arguments to the new way 2017-06-21 19:32:03 +00:00
__init__.py Revert "Enable to refresh ngdetails view" 2017-08-02 18:31:22 +00:00
base.py Fix Angular errors in openstack_auth 2018-03-17 18:40:50 +09:00
context_processors.py Remove extraneous vim configuration comments 2014-05-06 15:30:10 +08:00
decorators.py Views accessible via url even if user doesn't match policy rules 2018-02-02 21:24:33 +09:00
exceptions.py Correct odd exception message 2018-01-30 13:11:31 +09:00
karma.conf.js Makes the xstatic files lookup dynamic in the tests 2017-07-27 10:01:33 -04:00
loaders.py hacking: noqa cleanup in horizon 2017-03-17 19:38:47 +00:00
messages.py hacking: noqa cleanup in horizon 2017-03-17 19:38:47 +00:00
notifications.py Ensure log messages are not translated 2017-04-11 10:24:01 +00:00
site_urls.py hacking: noqa cleanup in horizon 2017-03-17 19:38:47 +00:00
themes.py Added SELECTABLE_THEMES setting 2017-07-26 11:52:35 +01:00
version.py Remove extraneous vim configuration comments 2014-05-06 15:30:10 +08:00
views.py flake8-import-order: Ensure to place project imports last 2017-09-20 01:19:38 +00:00