这是一个很好的问题,有很多好的方法。一个示例将是重写逻辑和表达下列:
- 策略集与第一适用
- 一个组合算法拒绝如果时间是错误
- 否认如果设备是无效
- 拒绝如果IP不在有效范围内
- 一组可能的操作和基于资源的policie s产生许可。
这就是它看起来像在ALFA:
namespace com.axiomatics.example{
policyset global{
apply firstApplicable
policy securityChecks{
apply firstApplicable
rule denyOutsideOfficeHours{
deny
}
rule denyInvalidDevice{
deny
}
rule denyInvalidIP{
deny
}
}
policyset myBusinessPolicies{
apply firstApplicable
/**
* Add your business policies here
*/
}
}
}
这仅仅是脚手架。现在,让我们看看我们需要的属性:
我们不会担心我们如何获得这些值。政策执行点或政策信息点需要担心这一点。
第一条规则将使用currentTime属性。这是ALFA默认属性,定义如下:
attribute currentTime {
id = "urn:oasis:names:tc:xacml:1.0:environment:current-time"
type = time
category = environmentCat
}
更新的规则,现在看起来如下:
rule denyOutsideOfficeHours{
target clause currentTime<"09:00:00":time or currentTime>"17:00:00":time
deny
}
在这个例子中,我们使用静态的下限和上限(上午9点至下午5点分别),但这些也可能是属性,在这种情况下,我们不得不使用条件而不是目标。请注意用于将字符串值转换为相关数据类型的ALFA符号:"17:00:00":time
。
第二条规则如下所示:
rule denyInvalidDevice{
condition not(stringIsIn(stringOneAndOnly(deviceType), stringBag("laptop","desktop")))
deny
}
在这个规则中,我们必须使用一个条件,因为它是不可能的表达目标的负面约束。该条件检查是否存在名为deviceType
的属性,并且它包含单个值,不多也不少。该值不能等于laptop
或desktop
以便拒绝踢入。顺便说一下,XACML中的字符串比较默认情况下区分大小写。
最后一条规则是相似的,我们不得不使用一个条件否定测试。这里我们使用ipAddressRegexpMAtch XACML函数来检查用户的IP(subjectLocalityIpAddress)是否匹配给定的IP地址模式。
rule denyInvalidIP{
condition not(
ipAddressRegexpMatch(
"^(10)\\.(10)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9])\\:([80|443])$",
ipAddressOneAndOnly(subjectLocalityIpAddress)
)
)
deny
}
请注意,反斜杠必须用另一个反斜杠进行转义。这是由于ALFA语法。 XACML策略本身一旦转换为XML,将不包含2个反斜杠字符。
产生的政策都结合在一起如下:
namespace com.axiomatics.example{
import Attributes.*
attribute deviceType{
category = subjectCat
id = "deviceType"
type = string
}
attribute userIP{
category = subjectCat
id = "deviceType"
type = string
}
policyset global{
apply firstApplicable
policy securityChecks{
apply firstApplicable
rule denyOutsideOfficeHours{
target clause currentTime<"09:00:00":time or currentTime>"17:00:00":time
deny
}
rule denyInvalidDevice{
condition not(stringIsIn(stringOneAndOnly(deviceType), stringBag("laptop","desktop")))
deny
}
rule denyInvalidIP{
condition not(
ipAddressRegexpMatch(
"^(10)\\.(10)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9])\\:([80|443])$",
ipAddressOneAndOnly(subjectLocalityIpAddress)
)
)
deny
}
}
policyset myBusinessPolicies{
apply firstApplicable
/**
* Add your business policies here
*/
}
}
}
我希望这有助于。通过Stackoverflow或通过我们的Developer's Blog向我们发送您的问题。
有什么方法可以在不使用Eclipse插件的情况下使用ALFA?例如以编程方式从一个用户界面创建ALFA,然后从ALFA生成XACML而不使用ALFA插件? – 2017-04-14 17:35:20