<commit_before>import urllib

import authentic.saml.models as models

class SamlBackend(object):
    def service_list(self, request):
        q = models.LibertyServiceProvider.objects.filter(enabled = True, idp_initiated_sso = True)
        list = []
        for service_provider in q:
            liberty_provider = service_provider.liberty_provider
            entity_id = liberty_provider.entity_id
            if liberty_provider.protocol_conformance < 3:
                protocol = 'idff12'
            else:
                protocol = 'saml2'
            uri = '/idp/%s/idp_sso/%s' % (protocol, urllib.quote(entity_id, ''))
            name = liberty_provider.name
            list.append((uri, name))
        return list

    def logout_list(self, request):
        return [ ]

    def can_synchronous_logout(self, django_sessions_keys):
        return True<commit_msg>[idp saml] add logout page generation code for SAML backend<commit_after>import urllib

from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _

import authentic.saml.models as models
import authentic.idp.saml.saml2_endpoints as saml2_endpoints

class SamlBackend(object):
    def service_list(self, request):
        q = models.LibertyServiceProvider.objects.filter(enabled = True, idp_initiated_sso = True)
        list = []
        for service_provider in q:
            liberty_provider = service_provider.liberty_provider
            entity_id = liberty_provider.entity_id
            if liberty_provider.protocol_conformance < 3:
                protocol = 'idff12'
            else:
                protocol = 'saml2'
            uri = '/idp/%s/idp_sso/%s' % (protocol, urllib.quote(entity_id, ''))
            name = liberty_provider.name
            list.append((uri, name))
        return list

    def logout_list(self, request):
        all_sessions = models.LibertySession.objects.filter(
                django_session_key=request.session.session_key)
        provider_ids = set([s.provider_id for s in all_sessions])
        result = []
        for pid in provider_ids:
            name = pid
            try:
                name = models.LibertyProvider.objects.get(entity_id=pid).name
            except models.LibertyProvider.DoesNotExist:
                pass
            code = '<div>'
            code += _('Sending logout to %(pid)s....') % { 'pid': pid }
            code += '<iframe src="%s" marginwidth="0" marginheight="0" \
scrolling="no" style="border: none" width="16" height="16"></iframe></div>' % \
                    reverse(saml2_endpoints.idp_slo, args=[pid])
            result.append(code)
        return result

    def can_synchronous_logout(self, django_sessions_keys):
        return True
{'fraction_non_alphanumeric': 0.0957408081543502, 'fraction_numerical': 0.006188569348380051, 'mean_word_length': 2.351219512195122, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3470528', 'n_tokens_mistral': 814, 'n_tokens_neox': 796, 'n_words': 170}