我想使用 ALFA 语言语法编写一个使用条件语句构建 XACML 函数的规则:“urn:oasis:names:tc:xacml:2.0:function:time-in-range”。出于易于处理义务的原因,我更愿意在条件函数中使用它,而不是在目标表达式中。
这可能吗?我在手册中没有找到任何参考。
在@David Brossard。按照下面的方案,我使用以下 ALFA 代码测试了该策略:
namespace com.ibm.XACML {
import Attributes.*
import attributes.*
import com.ibm.XACML.Attributes.*
attribute currentTime {
id = "urn:oasis:names:tc:xacml:1.0:environment:current-time"
type = time
category = environmentCat
}
function timeInRange = "urn:oasis:names:tc:xacml:2.0:function:time-in-range" : time time time -> boolean
// lowerBound = "09:00:00-03:00"
// upperBound = "18:00:00-03:00"
// current-time = "02:00:00-03:00" decision permit
// current-time = "10:00:00-03:00" decision permit
// current-time = "22:00:00-03:00" decision permit
policy checkTimeInRange{
apply firstApplicable
rule allowWithinRange{
permit
condition timeInRange(timeOneAndOnly(currentTime), timeOneAndOnly(timeBag("09:00:00-03:00":time)), timeOneAndOnly(timeBag("19:00:00-03:00":time)))
}
}
}
语法验证运行正常,但从 WSO2 PDP 代码返回的评估结果中存在错误,为 02:00:00、10:00:00 和 22:00 的所有三个测试提供“许可” :00。
我已经隔离了这个问题。WSO2 Try-It 工具默认生成“字符串”,而 XACML 需要时间数据类型。要修复它,必须提出手动请求,并且@David Brossard 显示的逻辑完美运行。这是一个示例请求,生成一个“许可”。
<Request xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" CombinedDecision="false" ReturnPolicyIdList="false">
<Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment">
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time" IncludeInResult="false">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">11:00:00-03:00</AttributeValue>
</Attribute>
</Attributes>
</Request>
结合条件语句的“TimeInRange”函数非常有帮助。