views: improve display of authentication failures

This commit is contained in:
Benjamin Dauvergne 2014-05-02 15:58:29 +02:00
parent 565d7a07f2
commit 6b8dcc5e78
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,24 @@
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<div id="mellon-authentication-failure" class="mellon-message">
<h2>{% trans "Authentication failed" %}</h2>
<p>
{% blocktrans %}The authentication has failed, you can return to
the <a href="{{ next_url }}">last page</a> you where.
{% endblocktrans %}
</p>
<dl id="mellon-authentication-failure-details">
<dt>{% trans "Issuer" %}</dt>
<dd>{{ issuer }}</dd>
{% if status_message %}
<dt>{% trans "Message" %}</dt>
<dd>{{ status_message }}</dd>
{% endif %}
<dt>{% trans "Codes" %}</dt>
<dd><tt>{{ status_codes|join:", " }}</tt></dd>
</dl>
</div>
{% endblock %}

View File

@ -32,6 +32,24 @@ class LoginView(View):
try:
login.processAuthnResponseMsg(request.POST['SAMLResponse'])
login.acceptSso()
except lasso.ProfileStatusNotSuccessError, e:
status_codes = []
status = login.response.status
a = status
while a.statusCode:
status_codes.append(a.statusCode.value)
a = a.statusCode
log.warning('SAML authentication failed, codes: %r',
status_codes)
if status.statusMessage:
log.warning('SAML authentication failed, message: %r',
status.statusMessage)
return render(request, 'mellon/authentication_failed.html', {
'status_message': status.statusMessage,
'status_codes': status_codes,
'issuer': login.remoteProviderId,
'next_url': login.msgRelayState or settings.LOGIN_REDIRECT_URL,
})
except lasso.Error, e:
return HttpResponseBadRequest('error processing the authentication '
'response: %r' % e)