我是XACML的新手。我正在使用XACML来表达政策。但除了OASIS XACML Technical Committee中的一些例外,我找不到任何好的例子。
好的,这是我的问题:
我想使用XACML表达政策。用户只有在满足策略时才能访问资源。该政策是一种逻辑表达。例如:
(A4,A5,A6)中的2个指的是只有当A4,A5,A6中的2个或更多为真时才成立。(不是A1)和(A2或A3)和((A4,A5,A6)中的2)
“AllOf”和“AnyOf”可用于表达“AND”和“OR”,但我不知道如何表达“(A4,A5,A6)”和“不是A1”。 / p>
谢谢!
答案 0 :(得分:1)
根据您的要求,您需要使用XACML条件。条件只存在于规则内,因此这意味着您必须将逻辑置于规则之内。
这是因为您需要XACML目标中不允许的功能:n-of。
这也是因为XACML Target不能有负面表达式。表达Not(A1)的唯一方法是通过条件。
原因是XACML处理属性包。所以当你写一个目标时:
role==manager
你实际上说的是:如果用户至少有一个与经理相等的角色......
那么相反的是什么呢?
关于你的2(a,b,c),你可以使用名为n-of的xACML函数(urn:oasis:names:tc:xacml:1.0:function:n-of {{3 }})
/**
* (not A1) and (A2 OR A3) and (2 of (A4, A5,A6))
*/
policy stackoverflow{
apply firstApplicable
rule so{
condition not(A1=="some value") && (A2=="" || A3=="") && nOf(2, stringOneAndOnly(A4)=="value", stringOneAndOnly(A5)=="value", stringOneAndOnly(A6)=="value")
permit
}
}
在上面的示例中,我使用A1到A6字符串属性而不是布尔值来显示如何与值进行比较。请注意,我必须使用stringOneAndOnly函数来确保nOf函数中使用的每个属性都有一个值。
XACML输出如下:
<?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/policing.principles.stackoverflow"
RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
Version="1.0">
<xacml3:Description>(not A1) and (A2 OR A3) and (2 of (A4, A5,A6))</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/policing.principles.stackoverflow.so">
<xacml3:Description />
<xacml3:Target />
<xacml3:Condition>
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:not" >
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of">
<xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
<xacml3:AttributeValue
DataType="http://www.w3.org/2001/XMLSchema#string">some value</xacml3:AttributeValue>
<xacml3:AttributeDesignator
AttributeId="A1"
DataType="http://www.w3.org/2001/XMLSchema#string"
Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
MustBePresent="false"
/>
</xacml3:Apply>
</xacml3:Apply>
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:or">
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of">
<xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
<xacml3:AttributeValue
DataType="http://www.w3.org/2001/XMLSchema#string"></xacml3:AttributeValue>
<xacml3:AttributeDesignator
AttributeId="A2"
DataType="http://www.w3.org/2001/XMLSchema#string"
Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
MustBePresent="false"
/>
</xacml3:Apply>
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of">
<xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
<xacml3:AttributeValue
DataType="http://www.w3.org/2001/XMLSchema#string"></xacml3:AttributeValue>
<xacml3:AttributeDesignator
AttributeId="A3"
DataType="http://www.w3.org/2001/XMLSchema#string"
Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
MustBePresent="false"
/>
</xacml3:Apply>
</xacml3:Apply>
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:n-of" >
<xacml3:AttributeValue
DataType="http://www.w3.org/2001/XMLSchema#integer">2</xacml3:AttributeValue>
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only" >
<xacml3:AttributeDesignator
AttributeId="A4"
DataType="http://www.w3.org/2001/XMLSchema#string"
Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
MustBePresent="false"
/>
</xacml3:Apply>
<xacml3:AttributeValue
DataType="http://www.w3.org/2001/XMLSchema#string">value</xacml3:AttributeValue>
</xacml3:Apply>
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only" >
<xacml3:AttributeDesignator
AttributeId="A5"
DataType="http://www.w3.org/2001/XMLSchema#string"
Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
MustBePresent="false"
/>
</xacml3:Apply>
<xacml3:AttributeValue
DataType="http://www.w3.org/2001/XMLSchema#string">value</xacml3:AttributeValue>
</xacml3:Apply>
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only" >
<xacml3:AttributeDesignator
AttributeId="A6"
DataType="http://www.w3.org/2001/XMLSchema#string"
Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
MustBePresent="false"
/>
</xacml3:Apply>
<xacml3:AttributeValue
DataType="http://www.w3.org/2001/XMLSchema#string">value</xacml3:AttributeValue>
</xacml3:Apply>
</xacml3:Apply>
</xacml3:Apply>
</xacml3:Apply>
</xacml3:Condition>
</xacml3:Rule>
</xacml3:Policy>
---编辑---
表达负面情况,例如不(性别= =男性),您有两种选择:
在前一种情况下,您可以编写以下内容:
policy checkGender{
apply firstApplicable
rule male{
target clause gender=="male"
permit
}
rule female{
target clause gender=="female"
permit
}
/**
* Optionally add a catch all case
*/
rule other{
target clause ... // Here you'd have to define other checks you are interested in
}
}
在后一种情况下,您需要写一个负面条件。为此,您需要使用XACML条件。由于XACML条件仅存在于规则内部,因此您需要深入到XACML规则级别。
policy checkGender{
apply firstApplicable
rule notMale{
condition not(gender=="male")
permit
}
}