我的xacml请求包含两个属性,我想将其作为策略条件的一部分进行比较。
他们是:
urn:oasis:names:tc:xacml:1.0:subject:group-id
urn:oasis:names:tc:xacml:1.0:resource:resource-id
我发现的所有策略示例只比较了一个请求属性(即ResourceAttributeDesignator)和一个硬编码的AttributeValue。
如何比较group-id equals resource-id?
答案 0 :(得分:2)
您需要使用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插件here。