2

我的 xacml 请求包含两个属性,我想将它们作为策略条件的一部分进行比较。

他们是:

urn:oasis:names:tc:xacml:1.0:subject:group-id
urn:oasis:names:tc:xacml:1.0:resource:resource-id

我发现的所有策略示例仅将一个请求属性(即 ResourceAttributeDesignator)与硬编码的 AttributeValue 进行比较。

如何比较该组 ID 等于资源 ID?

4

1 回答 1

4

您需要使用 XACML 条件。策略集、策略和规则都具有 XACML 目标,您可以使用这些目标将属性与值进行比较,例如role=='manager'. 规则还具有 XACML Condition 元素,您可以使用它进行更高级的比较,包括比较两个属性。

这是一个示例(使用 ALFA 表示法):

namespace stackoverflow{

    attribute groupId{
        category = subjectCat
        id = "urn:oasis:names:tc:xacml:1.0:subject:group-id"
        type = string
    }

    attribute resourceId{
        category = resourceCat
        id = "urn:oasis:names:tc:xacml:1.0:resource:resource-id"
        type = string
    }

    policy example{

        apply firstApplicable
        rule checkGroup{
            condition groupId==resourceId
            permit
        }
    }
}

这是 XACML 3.0 中的输出:

<?xml version="1.0" encoding="UTF-8"?>
 <!--This file was generated by the ALFA Plugin for Eclipse from Axiomatics AB (http://www.axiomatics.com). 
 Any modification to this file will be lost upon recompilation of the source ALFA file-->
<xacml3:Policy xmlns:xacml3="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
    PolicyId="http://axiomatics.com/alfa/identifier/stackoverflow.example"
    RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
    Version="1.0">
    <xacml3:Description />
    <xacml3:PolicyDefaults>
        <xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116</xacml3:XPathVersion>
    </xacml3:PolicyDefaults>
    <xacml3:Target />
    <xacml3:Rule 
            Effect="Permit"
            RuleId="http://axiomatics.com/alfa/identifier/stackoverflow.example.checkGroup">
        <xacml3:Description />
        <xacml3:Target />
        <xacml3:Condition>
            <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of-any">
                <xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
                <xacml3:AttributeDesignator 
                    AttributeId="urn:oasis:names:tc:xacml:1.0:subject:group-id"
                    DataType="http://www.w3.org/2001/XMLSchema#string"
                    Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                    MustBePresent="false"
                />
                <xacml3:AttributeDesignator 
                    AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id"
                    DataType="http://www.w3.org/2001/XMLSchema#string"
                    Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
                    MustBePresent="false"
                />
            </xacml3:Apply>
        </xacml3:Condition>
    </xacml3:Rule>
</xacml3:Policy>

您可以在此处下载 ALFA 插件。

于 2014-05-16T18:06:21.563 回答