get idp name from mdui:displayname (hack)

This commit is contained in:
Thomas NOËL 2013-12-24 13:16:26 +01:00
parent 12e181eccc
commit 705fb7ca09
1 changed files with 37 additions and 11 deletions

View File

@ -9,7 +9,9 @@ output a merge of idp + geo informations from discojuice
import os
os.environ['DJANGO_SETTINGS_MODULE'] = "settings"
from authentic2.saml.common import get_idp_list_sorted
from authentic2.saml.models import LibertyProvider
from xml.etree import ElementTree as ET
from operator import itemgetter
import sys
import json
import math
@ -46,18 +48,42 @@ for geofile in sys.argv[1:]:
geo_idps.update(geo2idp(geofile))
print """{% extends "login0.html" %}
{% block idps %}
"""
def get_ui_displayname(provider):
def get_first_child(xml, child):
for c in xml:
if c.tag.endswith(child):
return c
return None
xml = ET.fromstring(provider.metadata.encode('utf-8'))
for tag in ('IDPSSODescriptor', 'Extensions', 'UIInfo', 'DisplayName'):
xml = get_first_child(xml, tag)
if xml is None:
return provider.name
return xml.text
n = 0
for idp in get_idp_list_sorted():
idps = []
for provider in LibertyProvider.objects.all():
n += 1
entity_id = idp['entity_id']
name = idp['name']
geo = geo_idps.get(entity_id, {}).get('geo', { 'lat': 47.0 + 2.0*math.sin(n), 'lon': 2.5 + 3.0*math.cos(n) })
href = '/sso?' + urllib.urlencode([('entity_id', entity_id)])
li = u'<li><a href="%s" class="idplink" data-lat="%s" data-lon="%s" data-entityid="%s" data-filtertext="%s">%s</a></li>' % \
(href, geo['lat'], geo['lon'], entity_id, name, name)
geo = geo_idps.get(provider.entity_id, {}).get('geo',
{'lat': 47.0+2.0*math.sin(n), 'lon': 2.5+3.0*math.cos(n)})
idps.append({
'entityid': provider.entity_id,
'name': get_ui_displayname(provider),
'lat': geo['lat'],
'lon': geo['lon'],
'href': '/sso?' + urllib.urlencode([('entity_id', provider.entity_id)]),
})
print """{% extends "login0.html" %}
{% block idps %}"""
for idp in sorted(idps, key=itemgetter('name')):
li = u'<li><a href="%(href)s" class="idplink" ' \
'data-lat="%(lat)s" data-lon="%(lon)s" ' \
'data-entityid="%(entityid)s" ' \
'data-filtertext="%(name)s">%(name)s</a></li>' % idp
print li.encode("utf-8")
print "{% endblock %}"