a27e6d7e5a78f8fa50b463ca79185de600f68311
[openstack-build/django_openstack_auth-build.git] / 0004-Prepend-WEBROOT-to-redirect-URL-for-WebSSO.patch
1 From 3e9d6ecf680fd571f9fe068a0fc271bcf19ac278 Mon Sep 17 00:00:00 2001
2 From: Adam Young <ayoung@redhat.com>
3 Date: Tue, 14 Apr 2015 23:44:56 -0400
4 Subject: [PATCH] Prepend WEBROOT to redirect URL for WebSSO
5
6 Change-Id: Ib5c99e3b7b16bfb64b651d2129643d6f53fe7722
7 Closes-Bug: 1444244
8 (cherry picked from commit 85b2aaea489f2e89e36bc08b99216939d8076462)
9 (cherry picked from commit 3f1eb3f3c6e3fbf8bff010d76362558f7e22b721)
10 ---
11  openstack_auth/utils.py | 9 +++++++++
12  openstack_auth/views.py | 2 +-
13  2 files changed, 10 insertions(+), 1 deletion(-)
14
15 diff --git a/openstack_auth/utils.py b/openstack_auth/utils.py
16 index d861010..358f772 100644
17 --- a/openstack_auth/utils.py
18 +++ b/openstack_auth/utils.py
19 @@ -183,6 +183,15 @@ def is_websso_enabled():
20      return websso_enabled and keystonev3_plus
21  
22  
23 +def build_absolute_uri(request, relative_url):
24 +    """Ensure absolute_uri are relative to WEBROOT."""
25 +    webroot = getattr(settings, 'WEBROOT', '')
26 +    if webroot.endswith("/") and relative_url.startswith("/"):
27 +        webroot = webroot[:-1]
28 +
29 +    return request.build_absolute_uri(webroot + relative_url)
30 +
31 +
32  def has_in_url_path(url, sub):
33      """Test if the `sub` string is in the `url` path."""
34      scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
35 diff --git a/openstack_auth/views.py b/openstack_auth/views.py
36 index 8d5a0f5..68a1b08 100644
37 --- a/openstack_auth/views.py
38 +++ b/openstack_auth/views.py
39 @@ -60,7 +60,7 @@ def login(request, template_name=None, extra_context=None, **kwargs):
40          protocol = request.POST.get('auth_type', 'credentials')
41          if utils.is_websso_enabled() and protocol != 'credentials':
42              region = request.POST.get('region')
43 -            origin = request.build_absolute_uri('/auth/websso/')
44 +            origin = utils.build_absolute_uri(request, '/auth/websso/')
45              url = ('%s/auth/OS-FEDERATION/websso/%s?origin=%s' %
46                     (region, protocol, origin))
47              return shortcuts.redirect(url)