我想编写一个使用条件语句构建XACML函数的规则:使用ALFA语言语法的"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 )都提供了“许可”。
我孤立了这件事。XACML工具默认生成"String“,而WSO2则需要时间数据类型。要修复它,必须放置一个手动请求,@David所显示的逻辑工作得很好。这里有一个样例请求,生成一个“许可”。
<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“函数非常有用。
发布于 2016-03-16 19:46:12
从XACML标准我能读到
urn:oasis:names:tc:xacml:2.0:function:time-in-range 该函数将采用数据类型时间的三个参数,并返回一个布尔值。如果第一个参数位于包含第二个和第三个参数定义的范围内,则它将返回True。否则,它将返回“假”。 不论其价值如何,第三个论点应解释为等于或迟于第二个论点的时间。如果没有为第一个参数提供时区,则应在上下文处理程序中使用默认时区。如果没有为第二个或第三个参数提供时区,则应使用第一个参数中的时区。
阿尔法也有这个功能。它被定义为
function timeInRange = "urn:oasis:names:tc:xacml:2.0:function:time-in-range" : time time time -> boolean要使用它,只需做:
policy checkTimeInRange{
apply firstApplicable
rule allowWithinRange{
permit
condition timeInRange(timeOneAndOnly(currentTime), timeOneAndOnly(lowerBound), timeOneAndOnly(upperBound))
}
}请注意,如果缺少这些值,PDP将使用Indeterminate.进行答复。
https://stackoverflow.com/questions/36024924
复制相似问题