コード例 #1
0
ファイル: idp.py プロジェクト: ader1990/keystone
    def _create_attribute_statement(self, user, roles, project):
        """Create an object that represents a SAML AttributeStatement.

        <ns0:AttributeStatement
          xmlns:ns0="urn:oasis:names:tc:SAML:2.0:assertion"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ns0:Attribute Name="openstack_user">
                <ns0:AttributeValue
                  xsi:type="xs:string">test_user</ns0:AttributeValue>
            </ns0:Attribute>
            <ns0:Attribute Name="openstack_roles">
                <ns0:AttributeValue
                  xsi:type="xs:string">admin</ns0:AttributeValue>
                <ns0:AttributeValue
                  xsi:type="xs:string">member</ns0:AttributeValue>
            </ns0:Attribute>
            <ns0:Attribute Name="openstack_projects">
                <ns0:AttributeValue
                  xsi:type="xs:string">development</ns0:AttributeValue>
            </ns0:Attribute>
        </ns0:AttributeStatement>

        :return: XML <AttributeStatement> object

        """
        openstack_user = '******'
        user_attribute = saml.Attribute()
        user_attribute.name = openstack_user
        user_value = saml.AttributeValue()
        user_value.set_text(user)
        user_attribute.attribute_value = user_value

        openstack_roles = 'openstack_roles'
        roles_attribute = saml.Attribute()
        roles_attribute.name = openstack_roles

        for role in roles:
            role_value = saml.AttributeValue()
            role_value.set_text(role)
            roles_attribute.attribute_value.append(role_value)

        openstack_project = 'openstack_project'
        project_attribute = saml.Attribute()
        project_attribute.name = openstack_project
        project_value = saml.AttributeValue()
        project_value.set_text(project)
        project_attribute.attribute_value = project_value

        attribute_statement = saml.AttributeStatement()
        attribute_statement.attribute.append(user_attribute)
        attribute_statement.attribute.append(roles_attribute)
        attribute_statement.attribute.append(project_attribute)
        return attribute_statement
コード例 #2
0
    def _create_attribute_statement(self, user, roles, project):
        """Create an object that represents a SAML AttributeStatement.

        <ns0:AttributeStatement>
            <ns0:Attribute Name="openstack_user">
                <ns0:AttributeValue
                  xsi:type="xs:string">test_user</ns0:AttributeValue>
            </ns0:Attribute>
            <ns0:Attribute Name="openstack_roles">
                <ns0:AttributeValue
                  xsi:type="xs:string">admin</ns0:AttributeValue>
                <ns0:AttributeValue
                  xsi:type="xs:string">member</ns0:AttributeValue>
            </ns0:Attribute>
            <ns0:Attribute Name="openstack_project">
                <ns0:AttributeValue
                  xsi:type="xs:string">development</ns0:AttributeValue>
            </ns0:Attribute>
        </ns0:AttributeStatement>

        :return: XML <AttributeStatement> object

        """
        openstack_user = '******'
        user_attribute = saml.Attribute()
        user_attribute.name = openstack_user
        user_value = saml.AttributeValue()
        user_value.set_text(user)
        user_attribute.attribute_value = user_value

        openstack_roles = 'openstack_roles'
        roles_attribute = saml.Attribute()
        roles_attribute.name = openstack_roles

        for role in roles:
            role_value = saml.AttributeValue()
            role_value.set_text(role)
            roles_attribute.attribute_value.append(role_value)

        openstack_project = 'openstack_project'
        project_attribute = saml.Attribute()
        project_attribute.name = openstack_project
        project_value = saml.AttributeValue()
        project_value.set_text(project)
        project_attribute.attribute_value = project_value

        attribute_statement = saml.AttributeStatement()
        attribute_statement.attribute.append(user_attribute)
        attribute_statement.attribute.append(roles_attribute)
        attribute_statement.attribute.append(project_attribute)
        return attribute_statement
コード例 #3
0
    def test_to_local_name_from_basic(self):
        attr = [saml.Attribute(
                name="urn:mace:dir:attribute-def:eduPersonPrimaryOrgUnitDN")]

        lan = [attribute_converter.to_local_name(self.acs, a) for a in attr]

        assert _eq(lan, ['eduPersonPrimaryOrgUnitDN'])
コード例 #4
0
 def test_ava_fro_1(self):
 
     attr = [saml.Attribute(friendly_name="surName", 
             name="urn:oid:2.5.4.4",
             name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
         saml.Attribute(friendly_name="efternamn", 
             name="urn:oid:2.5.4.42",
             name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
         saml.Attribute(friendly_name="titel", 
             name="urn:oid:2.5.4.12",
             name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri")]
         
     result = attribute_converter.ava_fro(self.acs, attr)
     
     print result
     assert result == {'givenName': [], 'sn': [], 'title': []}
コード例 #5
0
ファイル: test_30_metadata.py プロジェクト: evansd/pysaml2
def test_make_list_of_strings():
    attr = saml.Attribute()
    vals = ["foo", "bar"]
    make_vals(vals, saml.AttributeValue, attr, "attribute_value")
    assert attr.keyswv() == ["attribute_value"]
    print attr.attribute_value
    assert _eq([val.text for val in attr.attribute_value], vals)
コード例 #6
0
ファイル: idp.py プロジェクト: weiqiLee/keystone
        def _build_attribute(attribute_name, attribute_values):
            attribute = saml.Attribute()
            attribute.name = attribute_name

            for value in attribute_values:
                attribute_value = saml.AttributeValue()
                attribute_value.set_text(value)
                attribute.attribute_value.append(attribute_value)

            return attribute
コード例 #7
0
 def test_to_local_name(self):
 
     attr = [
         saml.Attribute(
             friendly_name="surName",
             name="urn:oid:2.5.4.4",
             name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
         saml.Attribute(
             friendly_name="efternamn",
             name="urn:oid:2.5.4.42",
             name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
         saml.Attribute(
             friendly_name="titel",
             name="urn:oid:2.5.4.12",
             name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri")]
             
     lan = [attribute_converter.to_local_name(self.acs, a) for a in attr]
     
     assert _eq(lan, ['sn', 'givenName', 'title'])
コード例 #8
0
    def test_to_local_name_from_basic(self):
        attr = [
            saml.Attribute(
                name="urn:mace:dir:attribute-def:eduPersonPrimaryOrgUnitDN",
                name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:basic")
        ]

        lan = [attribute_converter.to_local_name(self.acs, a) for a in attr]

        assert _eq(lan, ['eduPersonPrimaryOrgUnitDN'])
コード例 #9
0
def test_valid_instance():
    attr_statem = saml.AttributeStatement()
    text = [
        "value of test attribute",
        "value1 of test attribute",
        "value2 of test attribute",
        "value1 of test attribute2",
        "value2 of test attribute2",
    ]

    attr_statem.attribute.append(saml.Attribute())
    attr_statem.attribute.append(saml.Attribute())
    attr_statem.attribute[0].name = "testAttribute"
    attr_statem.attribute[0].name_format = saml.NAME_FORMAT_URI
    attr_statem.attribute[0].friendly_name = "test attribute"
    attr_statem.attribute[0].attribute_value.append(saml.AttributeValue())
    attr_statem.attribute[0].attribute_value[0].text = text[0]

    attr_statem.attribute[1].name = "testAttribute2"
    attr_statem.attribute[1].name_format = saml.NAME_FORMAT_UNSPECIFIED
    attr_statem.attribute[1].friendly_name = text[2]
    attr_statem.attribute[1].attribute_value.append(saml.AttributeValue())
    attr_statem.attribute[1].attribute_value[0].text = text[2]

    assert valid_instance(attr_statem)

    response = samlp.Response()
    response.id = "response id"
    response.in_response_to = "request id"
    response.version = saml2.VERSION
    response.issue_instant = "2007-09-14T01:05:02Z"
    response.destination = "http://www.example.com/Destination"
    response.consent = saml.CONSENT_UNSPECIFIED
    response.issuer = saml.Issuer()
    response.status = samlp.Status()
    response.assertion.append(saml.Assertion())

    with raises(MustValueError):
        valid_instance(response)
コード例 #10
0
ファイル: s_utils.py プロジェクト: dolph/pysaml2
def do_attribute(val, typ, key):
    attr = saml.Attribute()
    attrval = do_ava(val, typ)
    if attrval:
        attr.attribute_value = attrval

    if isinstance(key, basestring):
        attr.name = key
    elif isinstance(key, tuple):  # 3-tuple or 2-tuple
        try:
            (name, nformat, friendly) = key
        except ValueError:
            (name, nformat) = key
            friendly = ""
        if name:
            attr.name = name
        if format:
            attr.name_format = nformat
        if friendly:
            attr.friendly_name = friendly
    return attr