Example #1
0
    def test_to_dict_for_logo_without_lang(self):
        desc = UIInfoDesc()
        desc.add_logo("logo.jpg", 80, 80, None)

        serialized = desc.to_dict()
        ui_info = serialized["service"]["idp"]["ui_info"]
        assert ui_info["logo"] == [{"text": "logo.jpg", "width": 80, "height": 80}]
Example #2
0
    def test_to_dict(self):
        org_desc = OrganizationDesc()
        org_desc.add_display_name("Foo Testing", "en")
        org_desc.add_name("Testing Co.", "en")
        org_desc.add_url("https://test.example.com", "en")

        contact_desc = ContactPersonDesc()
        contact_desc.contact_type = "test"
        contact_desc.given_name = "First"
        contact_desc.sur_name = "Tester"
        contact_desc.add_email_address("*****@*****.**")

        ui_desc = UIInfoDesc()
        ui_desc.add_description("test", "en")
        ui_desc.add_display_name("my company", "en")
        ui_desc.add_logo("http://example.com/logo.jpg", 80, 80, "en")

        desc = MetadataDescription("my_entity")
        desc.organization = org_desc
        desc.add_contact_person(contact_desc)
        desc.ui_info = ui_desc

        serialized = desc.to_dict()
        assert serialized["entityid"] == "my_entity"
        assert serialized["organization"]
        assert serialized["contact_person"]
        assert serialized["service"]["idp"]["ui_info"]
Example #3
0
    def get_metadata_desc(self):
        """
        See super class satosa.backends.backend_base.BackendModule#get_metadata_desc
        :rtype: satosa.metadata_creation.description.MetadataDescription
        """
        entity_descriptions = []

        idp_entities = self.sp.metadata.with_descriptor("idpsso")
        for entity_id, entity in idp_entities.items():
            description = MetadataDescription(urlsafe_b64encode(entity_id.encode("utf-8")).decode("utf-8"))

            # Add organization info
            try:
                organization_info = entity["organization"]
            except KeyError:
                pass
            else:
                organization = OrganizationDesc()
                for name_info in organization_info.get("organization_name", []):
                    organization.add_name(name_info["text"], name_info["lang"])
                for display_name_info in organization_info.get("organization_display_name", []):
                    organization.add_display_name(display_name_info["text"], display_name_info["lang"])
                for url_info in organization_info.get("organization_url", []):
                    organization.add_url(url_info["text"], url_info["lang"])
                description.organization = organization

            # Add contact person info
            try:
                contact_persons = entity["contact_person"]
            except KeyError:
                pass
            else:
                for person in contact_persons:
                    person_desc = ContactPersonDesc()
                    person_desc.contact_type = person.get("contact_type")
                    for address in person.get('email_address', []):
                        person_desc.add_email_address(address["text"])
                    if "given_name" in person:
                        person_desc.given_name = person["given_name"]["text"]
                    if "sur_name" in person:
                        person_desc.sur_name = person["sur_name"]["text"]

                    description.add_contact_person(person_desc)

            # Add UI info
            ui_info = self.sp.metadata.extension(entity_id, "idpsso_descriptor", "{}&UIInfo".format(UI_NAMESPACE))
            if ui_info:
                ui_info = ui_info[0]
                ui_info_desc = UIInfoDesc()
                for desc in ui_info.get("description", []):
                    ui_info_desc.add_description(desc["text"], desc["lang"])
                for name in ui_info.get("display_name", []):
                    ui_info_desc.add_display_name(name["text"], name["lang"])
                for logo in ui_info.get("logo", []):
                    ui_info_desc.add_logo(logo["text"], logo["width"], logo["height"], logo.get("lang"))
                description.ui_info = ui_info_desc

            entity_descriptions.append(description)
        return entity_descriptions
Example #4
0
    def test_to_dict(self):
        desc = UIInfoDesc()
        desc.add_description("test", "en")
        desc.add_display_name("my company", "en")
        desc.add_logo("logo.jpg", 80, 80, "en")

        serialized = desc.to_dict()
        ui_info = serialized["service"]["idp"]["ui_info"]
        assert ui_info["description"] == [{"text": "test", "lang": "en"}]
        assert ui_info["display_name"] == [{"text": "my company", "lang": "en"}]
        assert ui_info["logo"] == [{"text": "logo.jpg", "width": 80, "height": 80, "lang": "en"}]
Example #5
0
    def get_metadata_desc(self):
        """
        See super class satosa.backends.backend_base.BackendModule#get_metadata_desc
        :rtype: satosa.metadata_creation.description.MetadataDescription
        """
        entity_descriptions = []

        idp_entities = self.sp.metadata.with_descriptor("idpsso")
        for entity_id, entity in idp_entities.items():
            description = MetadataDescription(urlsafe_b64encode(entity_id.encode("utf-8")).decode("utf-8"))

            # Add organization info
            try:
                organization_info = entity["organization"]
            except KeyError:
                pass
            else:
                organization = OrganizationDesc()
                for name_info in organization_info.get("organization_name", []):
                    organization.add_name(name_info["text"], name_info["lang"])
                for display_name_info in organization_info.get("organization_display_name", []):
                    organization.add_display_name(display_name_info["text"], display_name_info["lang"])
                for url_info in organization_info.get("organization_url", []):
                    organization.add_url(url_info["text"], url_info["lang"])
                description.organization = organization

            # Add contact person info
            try:
                contact_persons = entity["contact_person"]
            except KeyError:
                pass
            else:
                for person in contact_persons:
                    person_desc = ContactPersonDesc()
                    person_desc.contact_type = person.get("contact_type")
                    for address in person.get('email_address', []):
                        person_desc.add_email_address(address["text"])
                    if "given_name" in person:
                        person_desc.given_name = person["given_name"]["text"]
                    if "sur_name" in person:
                        person_desc.sur_name = person["sur_name"]["text"]

                    description.add_contact_person(person_desc)

            # Add UI info
            ui_info = self.sp.metadata.extension(entity_id, "idpsso_descriptor", "{}&UIInfo".format(UI_NAMESPACE))
            if ui_info:
                ui_info = ui_info[0]
                ui_info_desc = UIInfoDesc()
                for desc in ui_info.get("description", []):
                    ui_info_desc.add_description(desc["text"], desc["lang"])
                for name in ui_info.get("display_name", []):
                    ui_info_desc.add_display_name(name["text"], name["lang"])
                for logo in ui_info.get("logo", []):
                    ui_info_desc.add_logo(logo["text"], logo["width"], logo["height"], logo.get("lang"))
                description.ui_info = ui_info_desc

            entity_descriptions.append(description)
        return entity_descriptions
Example #6
0
 def test_to_dict_with_empty(self):
     desc = UIInfoDesc()
     assert desc.to_dict() == {}
Example #7
0
def get_metadata_desc_for_oauth_backend(entity_id, config):
    """
    Returns a SAML metadata entity (IdP) descriptor for a configured OAuth/OpenID Connect Backend.
    :param entity_id: If entity_id is None, the id will be retrieved from the config
    :type entity_id: str
    :param config: The backend module config
    :type config: dict[str, Any]
    :return: metadata description
    :rtype: satosa.metadata_creation.description.MetadataDescription
    """
    metadata_description = []
    entity_id = urlsafe_b64encode(entity_id.encode("utf-8")).decode("utf-8")
    description = MetadataDescription(entity_id)

    if "entity_info" in config:
        entity_info = config["entity_info"]

        # Add contact person information
        for contact_person in entity_info.get("contact_person", []):
            person = ContactPersonDesc()
            if "contact_type" in contact_person:
                person.contact_type = contact_person["contact_type"]
            for address in contact_person.get("email_address", []):
                person.add_email_address(address)
            if "given_name" in contact_person:
                person.given_name = contact_person["given_name"]
            if "sur_name" in contact_person:
                person.sur_name = contact_person["sur_name"]

            description.add_contact_person(person)

        # Add organization information
        if "organization" in entity_info:
            organization_info = entity_info["organization"]
            organization = OrganizationDesc()

            for name_info in organization_info.get("organization_name", []):
                organization.add_name(name_info[0], name_info[1])
            for display_name_info in organization_info.get(
                    "organization_display_name", []):
                organization.add_display_name(display_name_info[0],
                                              display_name_info[1])
            for url_info in organization_info.get("organization_url", []):
                organization.add_url(url_info[0], url_info[1])

            description.organization = organization

        # Add ui information
        if "ui_info" in entity_info:
            ui_info = entity_info["ui_info"]
            ui_description = UIInfoDesc()
            for desc in ui_info.get("description", []):
                ui_description.add_description(desc[0], desc[1])
            for name in ui_info.get("display_name", []):
                ui_description.add_display_name(name[0], name[1])
            for logo in ui_info.get("logo", []):
                ui_description.add_logo(logo["image"], logo["width"],
                                        logo["height"], logo["lang"])

            description.ui_info = ui_description

    metadata_description.append(description)
    return metadata_description
Example #8
0
def get_metadata_desc_for_oidc_backend(config, entity_id=None):
    """
    Returns a description of an VOPaaSOpenIdBackend
    :type config: dict[str, Any]
    :type entity_id: str
    :rtype: satosa.metadata_creation.description.MetadataDescription
    :param config: The openid_connect module config
    :param entity_id: If entity_id is None, the id will be retrieved from the config
    :return: A description
    """
    metadata_description = []
    if entity_id is None:
        entity_id = config["op_url"]
    entity_id = urlsafe_b64encode(entity_id.encode("utf-8")).decode("utf-8")
    description = MetadataDescription(entity_id)

    if "op_info" in config:
        op_info = config["op_info"]

        # Add contact person information
        for contact_person in op_info.get("contact_person", []):
            person = ContactPersonDesc()
            if 'contact_type' in contact_person:
                person.contact_type = contact_person['contact_type']
            for address in contact_person.get('email_address', []):
                person.add_email_address(address)
            if 'given_name' in contact_person:
                person.given_name = contact_person['given_name']
            if 'sur_name' in contact_person:
                person.sur_name = contact_person['sur_name']

            description.add_contact_person(person)

        # Add organization information
        if "organization" in op_info:
            organization_info = op_info["organization"]
            organization = OrganizationDesc()

            for name_info in organization_info.get("organization_name", []):
                organization.add_name(name_info[0], name_info[1])
            for display_name_info in organization_info.get(
                    "organization_display_name", []):
                organization.add_display_name(display_name_info[0],
                                              display_name_info[1])
            for url_info in organization_info.get("organization_url", []):
                organization.add_url(url_info[0], url_info[1])

            description.set_organization(organization)

        # Add ui information
        if "ui_info" in op_info:
            ui_info = op_info["ui_info"]
            ui_description = UIInfoDesc()
            for desc in ui_info.get("description", []):
                ui_description.add_description(desc[0], desc[1])
            for name in ui_info.get("display_name", []):
                ui_description.add_display_name(name[0], name[1])
            for logo in ui_info.get("logo", []):
                ui_description.add_logo(logo["image"], logo["width"],
                                        logo["height"], logo["lang"])

            description.set_ui_info(ui_description)

    metadata_description.append(description)
    return metadata_description
Example #9
0
    def get_metadata_desc(self):
        """
        See super class vopaas.backends.backend_base.VOPaaSBackendModule#get_metadata_desc
        :rtype: satosa.metadata_creation.description.MetadataDescription
        """
        # TODO Only get IDPs
        metadata_desc = []
        for metadata_file in self.sp.metadata.metadata:
            metadata_file = self.sp.metadata.metadata[metadata_file]
            entity_ids = []

            if metadata_file.entity_descr is None:
                for entity_descr in metadata_file.entities_descr.entity_descriptor:
                    entity_ids.append(entity_descr.entity_id)
            else:
                entity_ids.append(metadata_file.entity_descr.entity_id)

            entity = metadata_file.entity
            for entity_id in entity_ids:

                description = MetadataDescription(
                    urlsafe_b64encode(entity_id.encode("utf-8")).decode("utf-8"))

                # Add organization info
                try:
                    organization = OrganizationDesc()
                    organization_info = entity[entity_id]['organization']

                    for name_info in organization_info.get("organization_name", []):
                        organization.add_name(name_info["text"], name_info["lang"])
                    for display_name_info in organization_info.get("organization_display_name", []):
                        organization.add_display_name(display_name_info["text"],
                                                      display_name_info["lang"])
                    for url_info in organization_info.get("organization_url", []):
                        organization.add_url(url_info["text"], url_info["lang"])

                    description.set_organization(organization)
                except:
                    pass

                # Add contact person info
                try:
                    contact_persons = entity[entity_id]['contact_person']
                    for cont_pers in contact_persons:
                        person = ContactPersonDesc()

                        if 'contact_type' in cont_pers:
                            person.contact_type = cont_pers['contact_type']
                        for address in cont_pers.get('email_address', []):
                            person.add_email_address(address["text"])
                        if 'given_name' in cont_pers:
                            person.given_name = cont_pers['given_name']['text']
                        if 'sur_name' in cont_pers:
                            person.sur_name = cont_pers['sur_name']['text']

                        description.add_contact_person(person)
                except KeyError:
                    pass

                # Add ui info
                try:
                    for idpsso_desc in entity[entity_id]["idpsso_descriptor"]:
                        # TODO Can have more than one ui info?
                        ui_elements = idpsso_desc["extensions"]["extension_elements"]
                        ui_info = UIInfoDesc()

                        for element in ui_elements:
                            if not element["__class__"] == "%s&UIInfo" % UI_NAMESPACE:
                                continue
                            for desc in element.get("description", []):
                                ui_info.add_description(desc["text"], desc["lang"])
                            for name in element.get("display_name", []):
                                ui_info.add_display_name(name["text"], name["lang"])
                            for logo in element.get("logo", []):
                                ui_info.add_logo(logo["text"], logo["width"], logo["height"],
                                                 logo["lang"])

                        description.set_ui_info(ui_info)
                except KeyError:
                    pass

                metadata_desc.append(description)
        return metadata_desc
Example #10
0
def get_metadata_desc_for_oidc_backend(config, entity_id=None):
    """
    Returns a description of an VOPaaSOpenIdBackend
    :type config: dict[str, Any]
    :type entity_id: str
    :rtype: satosa.metadata_creation.description.MetadataDescription
    :param config: The openid_connect module config
    :param entity_id: If entity_id is None, the id will be retrieved from the config
    :return: A description
    """
    metadata_description = []
    if entity_id is None:
        entity_id = config["op_url"]
    entity_id = urlsafe_b64encode(entity_id.encode("utf-8")).decode("utf-8")
    description = MetadataDescription(entity_id)

    if "op_info" in config:
        op_info = config["op_info"]

        # Add contact person information
        for contact_person in op_info.get("contact_person", []):
            person = ContactPersonDesc()
            if 'contact_type' in contact_person:
                person.contact_type = contact_person['contact_type']
            for address in contact_person.get('email_address', []):
                person.add_email_address(address)
            if 'given_name' in contact_person:
                person.given_name = contact_person['given_name']
            if 'sur_name' in contact_person:
                person.sur_name = contact_person['sur_name']

            description.add_contact_person(person)

        # Add organization information
        if "organization" in op_info:
            organization_info = op_info["organization"]
            organization = OrganizationDesc()

            for name_info in organization_info.get("organization_name", []):
                organization.add_name(name_info[0], name_info[1])
            for display_name_info in organization_info.get("organization_display_name", []):
                organization.add_display_name(display_name_info[0], display_name_info[1])
            for url_info in organization_info.get("organization_url", []):
                organization.add_url(url_info[0], url_info[1])

            description.set_organization(organization)

        # Add ui information
        if "ui_info" in op_info:
            ui_info = op_info["ui_info"]
            ui_description = UIInfoDesc()
            for desc in ui_info.get("description", []):
                ui_description.add_description(desc[0], desc[1])
            for name in ui_info.get("display_name", []):
                ui_description.add_display_name(name[0], name[1])
            for logo in ui_info.get("logo", []):
                ui_description.add_logo(logo["image"], logo["width"], logo["height"], logo["lang"])

            description.set_ui_info(ui_description)

    metadata_description.append(description)
    return metadata_description
Example #11
0
    def get_metadata_desc(self):
        """
        See super class vopaas.backends.backend_base.VOPaaSBackendModule#get_metadata_desc
        :rtype: satosa.metadata_creation.description.MetadataDescription
        """
        # TODO Only get IDPs
        metadata_desc = []
        for metadata_file in self.sp.metadata.metadata:
            metadata_file = self.sp.metadata.metadata[metadata_file]
            entity_ids = []

            if metadata_file.entity_descr is None:
                for entity_descr in metadata_file.entities_descr.entity_descriptor:
                    entity_ids.append(entity_descr.entity_id)
            else:
                entity_ids.append(metadata_file.entity_descr.entity_id)

            entity = metadata_file.entity
            for entity_id in entity_ids:

                description = MetadataDescription(
                    urlsafe_b64encode(
                        entity_id.encode("utf-8")).decode("utf-8"))

                # Add organization info
                try:
                    organization = OrganizationDesc()
                    organization_info = entity[entity_id]['organization']

                    for name_info in organization_info.get(
                            "organization_name", []):
                        organization.add_name(name_info["text"],
                                              name_info["lang"])
                    for display_name_info in organization_info.get(
                            "organization_display_name", []):
                        organization.add_display_name(
                            display_name_info["text"],
                            display_name_info["lang"])
                    for url_info in organization_info.get(
                            "organization_url", []):
                        organization.add_url(url_info["text"],
                                             url_info["lang"])

                    description.set_organization(organization)
                except:
                    pass

                # Add contact person info
                try:
                    contact_persons = entity[entity_id]['contact_person']
                    for cont_pers in contact_persons:
                        person = ContactPersonDesc()

                        if 'contact_type' in cont_pers:
                            person.contact_type = cont_pers['contact_type']
                        for address in cont_pers.get('email_address', []):
                            person.add_email_address(address["text"])
                        if 'given_name' in cont_pers:
                            person.given_name = cont_pers['given_name']['text']
                        if 'sur_name' in cont_pers:
                            person.sur_name = cont_pers['sur_name']['text']

                        description.add_contact_person(person)
                except KeyError:
                    pass

                # Add ui info
                try:
                    for idpsso_desc in entity[entity_id]["idpsso_descriptor"]:
                        # TODO Can have more than one ui info?
                        ui_elements = idpsso_desc["extensions"][
                            "extension_elements"]
                        ui_info = UIInfoDesc()

                        for element in ui_elements:
                            if not element[
                                    "__class__"] == "%s&UIInfo" % UI_NAMESPACE:
                                continue
                            for desc in element.get("description", []):
                                ui_info.add_description(
                                    desc["text"], desc["lang"])
                            for name in element.get("display_name", []):
                                ui_info.add_display_name(
                                    name["text"], name["lang"])
                            for logo in element.get("logo", []):
                                ui_info.add_logo(logo["text"], logo["width"],
                                                 logo["height"], logo["lang"])

                        description.set_ui_info(ui_info)
                except KeyError:
                    pass

                metadata_desc.append(description)
        return metadata_desc