authentik.enterprise.providers.ws_federation.processors.metadata

 1from django.urls import reverse
 2from lxml.etree import SubElement, _Element  # nosec
 3
 4from authentik.common.saml.constants import NS_SAML_METADATA
 5from authentik.enterprise.providers.ws_federation.processors.constants import (
 6    NS_ADDRESSING,
 7    NS_MAP,
 8    NS_WS_FED_PROTOCOL,
 9    NS_WSI,
10)
11from authentik.providers.saml.processors.metadata import MetadataProcessor as BaseMetadataProcessor
12
13
14class MetadataProcessor(BaseMetadataProcessor):
15    def add_children(self, entity_descriptor: _Element):
16        self.add_role_descriptor_sts(entity_descriptor)
17        super().add_children(entity_descriptor)
18
19    def add_endpoint(self, parent: _Element, name: str):
20        endpoint = SubElement(parent, f"{{{NS_WS_FED_PROTOCOL}}}{name}", nsmap=NS_MAP)
21        endpoint_ref = SubElement(endpoint, f"{{{NS_ADDRESSING}}}EndpointReference", nsmap=NS_MAP)
22
23        address = SubElement(endpoint_ref, f"{{{NS_ADDRESSING}}}Address", nsmap=NS_MAP)
24        address.text = self.http_request.build_absolute_uri(
25            reverse(
26                "authentik_providers_ws_federation:wsfed-app-specific",
27                kwargs={
28                    "application_slug": self.provider.application.slug,
29                },
30            )
31        )
32
33    def add_role_descriptor_sts(self, entity_descriptor: _Element):
34        role_descriptor = SubElement(
35            entity_descriptor, f"{{{NS_SAML_METADATA}}}RoleDescriptor", nsmap=NS_MAP
36        )
37        role_descriptor.attrib[f"{{{NS_WSI}}}type"] = "fed:SecurityTokenServiceType"
38        role_descriptor.attrib["protocolSupportEnumeration"] = NS_WS_FED_PROTOCOL
39
40        signing_descriptor = self.get_signing_key_descriptor()
41        if signing_descriptor is not None:
42            role_descriptor.append(signing_descriptor)
43
44        self.add_endpoint(role_descriptor, "SecurityTokenServiceEndpoint")
45        self.add_endpoint(role_descriptor, "PassiveRequestorEndpoint")
15class MetadataProcessor(BaseMetadataProcessor):
16    def add_children(self, entity_descriptor: _Element):
17        self.add_role_descriptor_sts(entity_descriptor)
18        super().add_children(entity_descriptor)
19
20    def add_endpoint(self, parent: _Element, name: str):
21        endpoint = SubElement(parent, f"{{{NS_WS_FED_PROTOCOL}}}{name}", nsmap=NS_MAP)
22        endpoint_ref = SubElement(endpoint, f"{{{NS_ADDRESSING}}}EndpointReference", nsmap=NS_MAP)
23
24        address = SubElement(endpoint_ref, f"{{{NS_ADDRESSING}}}Address", nsmap=NS_MAP)
25        address.text = self.http_request.build_absolute_uri(
26            reverse(
27                "authentik_providers_ws_federation:wsfed-app-specific",
28                kwargs={
29                    "application_slug": self.provider.application.slug,
30                },
31            )
32        )
33
34    def add_role_descriptor_sts(self, entity_descriptor: _Element):
35        role_descriptor = SubElement(
36            entity_descriptor, f"{{{NS_SAML_METADATA}}}RoleDescriptor", nsmap=NS_MAP
37        )
38        role_descriptor.attrib[f"{{{NS_WSI}}}type"] = "fed:SecurityTokenServiceType"
39        role_descriptor.attrib["protocolSupportEnumeration"] = NS_WS_FED_PROTOCOL
40
41        signing_descriptor = self.get_signing_key_descriptor()
42        if signing_descriptor is not None:
43            role_descriptor.append(signing_descriptor)
44
45        self.add_endpoint(role_descriptor, "SecurityTokenServiceEndpoint")
46        self.add_endpoint(role_descriptor, "PassiveRequestorEndpoint")

SAML Identity Provider Metadata Processor

def add_children(self, entity_descriptor: lxml.etree._Element):
16    def add_children(self, entity_descriptor: _Element):
17        self.add_role_descriptor_sts(entity_descriptor)
18        super().add_children(entity_descriptor)
def add_endpoint(self, parent: lxml.etree._Element, name: str):
20    def add_endpoint(self, parent: _Element, name: str):
21        endpoint = SubElement(parent, f"{{{NS_WS_FED_PROTOCOL}}}{name}", nsmap=NS_MAP)
22        endpoint_ref = SubElement(endpoint, f"{{{NS_ADDRESSING}}}EndpointReference", nsmap=NS_MAP)
23
24        address = SubElement(endpoint_ref, f"{{{NS_ADDRESSING}}}Address", nsmap=NS_MAP)
25        address.text = self.http_request.build_absolute_uri(
26            reverse(
27                "authentik_providers_ws_federation:wsfed-app-specific",
28                kwargs={
29                    "application_slug": self.provider.application.slug,
30                },
31            )
32        )
def add_role_descriptor_sts(self, entity_descriptor: lxml.etree._Element):
34    def add_role_descriptor_sts(self, entity_descriptor: _Element):
35        role_descriptor = SubElement(
36            entity_descriptor, f"{{{NS_SAML_METADATA}}}RoleDescriptor", nsmap=NS_MAP
37        )
38        role_descriptor.attrib[f"{{{NS_WSI}}}type"] = "fed:SecurityTokenServiceType"
39        role_descriptor.attrib["protocolSupportEnumeration"] = NS_WS_FED_PROTOCOL
40
41        signing_descriptor = self.get_signing_key_descriptor()
42        if signing_descriptor is not None:
43            role_descriptor.append(signing_descriptor)
44
45        self.add_endpoint(role_descriptor, "SecurityTokenServiceEndpoint")
46        self.add_endpoint(role_descriptor, "PassiveRequestorEndpoint")