WSO2 身份服务器——如何为扩展 PIP 编写 XACML 策略

WSO2 Identity Server – How to write a XACML Policy for an Extended PIP

使用 "RedAttributeFinder" class 的 PIP 扩展代码正在运行。它正确地将其声明注册到 WSO2 PDP 扩展控制台显示中。

我现在开始创建一个 XACML 策略,解决扩展程序提供的 return 动态数据值的字段(例如名为“http://w3.red.com/subject/employeeCountryCode”的字段)。

数据查找的关键字段是:urn:oasis:names:tc:xacml:1.0:resource:resource-id ,它以电子邮件格式映射用户身份。

问题 1:如何在 "RedAttributeFinder" class 调用“getAttributesValues”方法,在 WSO2 的开始注册。是什么触发了 PDP 流程(或其传入请求)的方法调用?

在示例代码以及我的实现中,关键字段是作为 PEP 请求实现的一部分加载的资源 ID。

..
myRequest += "<Attributes Category=\"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\">" + "\n"; 
myRequest += "<Attribute AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject:subject-id\" IncludeInResult=\"false\">" + "\n"; 
myRequest += "<AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">tony@br.red.com</AttributeValue>" + "\n"; 
myRequest += "</Attribute>" + "\n";  
myRequest += "</Attributes>" + "\n"; 
myRequest += "<Attributes Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\">" + "\n"; 
myRequest += "<Attribute AttributeId=\"urn:oasis:names:tc:xacml:1.0:resource:resource-id\" IncludeInResult=\"true\">" + "\n"; 
.. 

这是 "getAttributesValues()" 的关键输入,将 return 国家代码(类似于 WSO2 示例代码中的角色 [blue, silver, gold] 定义[可在此处获得 https://svn.wso2.org/repos/wso2/carbon/platform/trunk/components/identity/org.wso2.carbon.identity.samples.entitlement.pip/ ] .

在示例中,我看到所需的角色值解析,例如 "blue" 是策略目标定义的一部分。

问题 2:目标部分中的这个放置是否需要调用动态 PIP 查找,每个请求一个,或者它也可以放置在目标部分的其他部分吗?政策,例如在规则内?

我能够通过规则定义测试 PEP 到 PDP 的交互,仅通过定义静态变量,接收 "permit",我想更改为从 PIP 实现中获得的动态数据的规则及其扩展,解决代码添加的新字段。

在符合 XACML 标准的标准实现中,只要 PDP 在其策略中找到也由 PIP 发布的属性指示符(这意味着 PIP 必须通告它可以发布的属性),它就会随时调用 PIP提供例如它提供角色、公民身份...)。

PDP 可以选择不调用 PIP 而是使用属性缓存。属性在策略中的位置无关紧要。属性是否用于目标或条件内应该无关紧要 - 至少根据规范 - 这就是 Axiomatics、SunXACML 和 ATT 引擎的工作方式。

干杯, 大卫.

我通过将此行添加到 log4j.properties 文件中,在 WSO2 设置中找到了一个有用的调试选项:

log4j.logger.org.wso2.carbon.identity.entitlement=DEBUG

此命令开始跟踪发送到 PIP 的请求,包括调用 PIP 扩展 class(按属性指示符)和返回数据字段。

这证实了 PDP 以及 Try-It 函数动态调用了 PIP。下面的政策通过确认 PIP 扩展程序的正常运行,提供了预期的 "permit" 和 "deny" 结果。

下面是一个非常简单的策略,该策略使用 PIP 扩展代码进行测试,为名为:employeeCountryCode 的数据变量获取值。

政策

<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"  PolicyId="RedLDAPPolicy1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides" Version="1.0">
<Target>
</Target>
<Rule Effect="Permit" RuleId="Permit-Rule1">
<Target>
<AnyOf>
<AllOf>
<Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">631</AttributeValue>
<AttributeDesignator AttributeId="http://w3.red.com/subject/employeeCountryCode" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true">
</AttributeDesignator>
</Match>
</AllOf>
</AnyOf>
<AnyOf>
<AllOf>
<Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">ldap</AttributeValue>
<AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true">
</AttributeDesignator>
</Match>
</AllOf>
</AnyOf>
<AnyOf>
<AllOf>
<Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">read</AttributeValue>
<AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true">
</AttributeDesignator>
</Match>
</AllOf>
</AnyOf>
</Target>
</Rule>
<Rule Effect="Deny" RuleId="Deny-Rule">
</Rule>
</Policy>

请求

<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:action">
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" IncludeInResult="false">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">read</AttributeValue>
</Attribute>
</Attributes>
<Attributes Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject">
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" IncludeInResult="false">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">tony@br.red.com</AttributeValue>
</Attribute>
</Attributes>
<Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource">
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" IncludeInResult="true">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">ldap</AttributeValue>
</Attribute>
</Attributes>
</Request>