浏览代码

HUE-8663 [core] Fix SAML TemplateDoesNotExist

Ying Chen 7 年之前
父节点
当前提交
48da58019c

+ 1 - 1
desktop/core/ext-py/djangosaml2-0.16.11/djangosaml2/acs_failures.py

@@ -11,7 +11,7 @@ from django.shortcuts import render
 
 def template_failure(request, status=403, **kwargs):
     """ Renders a SAML-specific template with general authentication error description. """
-    return render(request, 'djangosaml2/login_error.html', status=status)
+    return render(request, 'djangosaml2/login_error.html', status=status, using='django')
 
 
 def exception_failure(request, exc_class=PermissionDenied, **kwargs):

+ 6 - 6
desktop/core/ext-py/djangosaml2-0.16.11/djangosaml2/views.py

@@ -133,7 +133,7 @@ def login(request,
             logger.debug('User is already logged in')
             return render(request, authorization_error_template, {
                     'came_from': came_from,
-                    })
+                    }, using='django')
 
     selected_idp = request.GET.get('idp', None)
     conf = get_config(config_loader_path, request)
@@ -145,7 +145,7 @@ def login(request,
         return render(request, wayf_template, {
                 'available_idps': idps.items(),
                 'came_from': came_from,
-                })
+                }, using='django')
 
     # choose a binding to try first
     sign_requests = getattr(conf, '_sp_authn_requests_signed', False)
@@ -213,7 +213,7 @@ def login(request,
                         'SAMLRequest': saml_request,
                         'RelayState': came_from,
                         },
-                    })
+                    }, using='django')
             except TemplateDoesNotExist:
                 pass
 
@@ -349,7 +349,7 @@ def echo_attributes(request,
     except AttributeError:
         return HttpResponse("No active SAML identity found. Are you sure you have logged in via SAML?")
 
-    return render(request, template, {'attributes': identity[0]})
+    return render(request, template, {'attributes': identity[0]}, using='django')
 
 
 @login_required
@@ -443,7 +443,7 @@ def do_logout_service(request, data, binding, config_loader_path=None, next_page
                 'The session does not contain the subject id for user %s. Performing local logout',
                 request.user)
             auth.logout(request)
-            return render(request, logout_error_template, status=403)
+            return render(request, logout_error_template, status=403, using='django')
         else:
             http_info = client.handle_logout_request(
                 data['SAMLRequest'],
@@ -467,7 +467,7 @@ def finish_logout(request, response, next_page=None):
         return django_logout(request, next_page=next_page)
     else:
         logger.error('Unknown error during the logout')
-        return render(request, "djangosaml2/logout_error.html", {})
+        return render(request, "djangosaml2/logout_error.html", {}, using='django')
 
 
 def metadata(request, config_loader_path=None, valid_for=None):

+ 1 - 0
desktop/core/src/desktop/settings.py

@@ -234,6 +234,7 @@ TEMPLATES = [
     'BACKEND': 'django.template.backends.django.DjangoTemplates',
     'DIRS': [
       get_desktop_root("core/templates/debug_toolbar"),
+      get_desktop_root("core/templates/djangosaml2"),
     ],
     'NAME': 'django',
     'APP_DIRS': True,

+ 16 - 0
desktop/core/src/desktop/templates/djangosaml2/auth_error.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+  </head>
+  <body>
+    <h1>Authorization error</h1>
+    <p>You are already logged in and you are trying to go to the login page again.</p>
+
+    <p>You may have been redirected here when trying to access some content
+      that required extra privileges that you do not have.</p>
+
+    <p>Please <a href="{% url 'saml2_logout' %}">logout</a> and login as a different user</p>
+  </body>
+</html>

+ 18 - 0
desktop/core/src/desktop/templates/djangosaml2/echo_attributes.html

@@ -0,0 +1,18 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+  </head>
+  <body>
+    <h1>SAML attributes</h1>
+    <dl>
+      {% for attribute, value in attributes.items %}
+      <dt>{{ attribute }}:</dt>
+      <dd>{{ value|join:", " }}</dd>
+      {% endfor %}
+    </dl>
+
+    <p><a href="{% url 'saml2_logout' %}">Log out</a></p>
+  </body>
+</html>

+ 15 - 0
desktop/core/src/desktop/templates/djangosaml2/example_post_binding_form.html

@@ -0,0 +1,15 @@
+<script type="text/javascript">
+	window.onload = function(){
+		document.SSO_Login.submit();
+	};
+</script>
+<p>
+You're being redirected to a SSO login page.
+Please click the button below if you're not redirected automatically within a few seconds.
+</p>
+<form method="post" action="{{ target_url }}" name="SSO_Login">
+	{% for key, value in params.items %}
+	    <input type="hidden" name="{{ key|safe }}" value="{{ value|safe }}" />
+	{% endfor %}
+    <input type="submit" value="Log in" />
+</form>

+ 13 - 0
desktop/core/src/desktop/templates/djangosaml2/login_error.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+  </head>
+  <body>
+    <h1>Authentication Error.</h1>
+
+    <h2>Access Denied.</h2>
+
+  </body>
+</html>

+ 17 - 0
desktop/core/src/desktop/templates/djangosaml2/logout_error.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+  </head>
+  <body>
+    <h1>Logout error</h1>
+    <p>Your Identity Provider ask this system to do a global logout but your federated session is lost.</p>
+
+    <p>Even if your local session in this system has been closed, you have probably open sessions in other systems.</p>
+
+    <p>In order to prevent illicit use of your personal information, please close your browser window and/or remove your cookies from your browser.</p>
+
+    <p>Sorry for this inconvenience.</p>
+  </body>
+</html>

+ 16 - 0
desktop/core/src/desktop/templates/djangosaml2/wayf.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+  </head>
+  <body>
+    <h1>Where are you from?</h1>
+    <p>Please select your <strong>Identity Provider</strong> from the following list:</p>
+    <ul>
+      {% for url, name in available_idps %}
+      <li><a href="{% url 'saml2_login' %}?idp={{ url }}{% if came_from %}&next={{ came_from }}{% endif %}">{{ name }}</a></li>
+      {% endfor %}
+    </ul>
+  </body>
+</html>