1

我想使用 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”函数非常有帮助。

4

1 回答 1

1

XACML 标准我可以阅读

urn:oasis:names:tc:xacml:2.0:function:time-in-range

此函数应采用数据类型time的三个参数并应返回一个boolean。如果第一个参数落在由第二个和第三个参数定义的范围内,它应该返回True 。否则,它将返回“False”。

无论其值如何,第三个参数都应被解释为等于或晚于第二个参数的时间少于 24 小时。如果没有为第一个参数提供时区,它应该在上下文处理程序中使用默认时区。如果没有为第二个或第三个参数提供时区,则它们应使用第一个参数中的时区。

ALFA 也有这个功能。它被定义为

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

于 2016-03-16T19:46:12.437 回答