diff --git a/passbook/providers/saml/models.py b/passbook/providers/saml/models.py index 4a1668b77..560966a44 100644 --- a/passbook/providers/saml/models.py +++ b/passbook/providers/saml/models.py @@ -106,6 +106,16 @@ class SAMLProvider(Provider): except Provider.application.RelatedObjectDoesNotExist: return None + def html_metadata_view(self, request): + """return template and context modal with to view Metadata without downloading it""" + from passbook.providers.saml.views import DescriptorDownloadView + + metadata = DescriptorDownloadView.get_metadata(request, self) + return ( + "saml/idp/admin_metadata_modal.html", + {"provider": self, "metadata": metadata,}, + ) + class Meta: verbose_name = _("SAML Provider") diff --git a/passbook/providers/saml/templates/saml/idp/admin_metadata_modal.html b/passbook/providers/saml/templates/saml/idp/admin_metadata_modal.html new file mode 100644 index 000000000..5795000f1 --- /dev/null +++ b/passbook/providers/saml/templates/saml/idp/admin_metadata_modal.html @@ -0,0 +1,41 @@ +{% load i18n %} +{% load static %} + + + + + + + + +
+ diff --git a/passbook/providers/saml/views.py b/passbook/providers/saml/views.py index 17f2a2f15..c37d07d85 100644 --- a/passbook/providers/saml/views.py +++ b/passbook/providers/saml/views.py @@ -219,22 +219,23 @@ class SLOLogout(CSRFExemptMixin, AccessRequiredView): class DescriptorDownloadView(AccessRequiredView): """Replies with the XML Metadata IDSSODescriptor.""" - def get(self, request: HttpRequest, application: str) -> HttpResponse: - """Replies with the XML Metadata IDSSODescriptor.""" - entity_id = self.provider.issuer + @staticmethod + def get_metadata(request: HttpRequest, provider: SAMLProvider) -> str: + """Return rendered XML Metadata""" + entity_id = provider.issuer slo_url = request.build_absolute_uri( reverse( "passbook_providers_saml:saml-logout", - kwargs={"application": application}, + kwargs={"application": provider.application}, ) ) sso_url = request.build_absolute_uri( reverse( "passbook_providers_saml:saml-login", - kwargs={"application": application}, + kwargs={"application": provider.application}, ) ) - pubkey = strip_pem_header(self.provider.signing_cert.replace("\r", "")).replace( + pubkey = strip_pem_header(provider.signing_cert.replace("\r", "")).replace( "\n", "" ) ctx = { @@ -243,7 +244,12 @@ class DescriptorDownloadView(AccessRequiredView): "slo_url": slo_url, "sso_url": sso_url, } - metadata = render_to_string("saml/xml/metadata.xml", ctx) + return render_to_string("saml/xml/metadata.xml", ctx) + + # pylint: disable=unused-argument + def get(self, request: HttpRequest, application: str) -> HttpResponse: + """Replies with the XML Metadata IDSSODescriptor.""" + metadata = DescriptorDownloadView.get_metadata(request, self.provider) response = HttpResponse(metadata, content_type="application/xml") response["Content-Disposition"] = ( 'attachment; filename="' '%s_passbook_meta.xml"' % self.provider.name