我尝试了http://www.webfarmr.eu/2011/08/xacml-102-xpath-and-xacml/中的第一个示例,“单个XACML请求中使用的XPath”部分。以防万一是XACML政策:
<?xml version="1.0" encoding="UTF-8"?><xacml3:Policy xmlns:xacml3="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="xpath-target-single-req" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides" Version="1">
<xacml3:Description/>
<xacml3:PolicyDefaults><xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116</xacml3:XPathVersion></xacml3:PolicyDefaults>
<xacml3:Target>
<xacml3:AnyOf>
<xacml3:AllOf>
<xacml3:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<xacml3:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Gulliver's travels</xacml3:AttributeValue>
<xacml3:AttributeSelector Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false" Path="/book/title/text()"/>
</xacml3:Match>
<xacml3:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than">
<xacml3:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#integer">18</xacml3:AttributeValue>
<xacml3:AttributeDesignator AttributeId="age" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#integer" MustBePresent="false"/>
</xacml3:Match>
</xacml3:AllOf>
</xacml3:AnyOf>
</xacml3:Target>
<xacml3:Rule Effect="Permit" RuleId="allow-read">
<xacml3:Description/>
<xacml3:Target/>
</xacml3:Rule>
</xacml3:Policy>
当我使用“策略管理”页面中的“尝试”选项并评估我的XACML请求时 - 响应将返回Permit决策。请注意,该政策尚未发布。
之后,我发布了该策略,启用它并使用Tools-&gt; XACML菜单中的“Try”选项。结果是“NotApplicable”。
我在政策管理和政策视图中都没有任何其他政策。
包含XPath表达式的XACML策略是否需要一些额外的配置?提供的方案有什么问题?
编辑: 在日志中找到此消息:
[2014-07-03 11:13:25,021] INFO {org.wso2.balana.finder.AttributeFinder} - Failed to resolve any values for /book/title/text()
答案 0 :(得分:2)
是。这是Identity Server中的错误。请参阅公开jira。但是,这并不是因为Balana
中没有实现XPAth,而Balana
没有问题。它与Identity Server和Identity Server无法正确初始化Balana
引擎有关。
答案 1 :(得分:1)
当我编写示例时,我忽略了添加命名空间。您需要添加名称空间,然后它应该工作正常。例如,XACML策略变为:
<xacml3:Policy xmlns:xacml3="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="xpath-target-single-req" Version="1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides">
<xacml3:PolicyDefaults><xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116</xacml3:XPathVersion></xacml3:PolicyDefaults>
<xacml3:Target>
<xacml3:AnyOf>
<xacml3:AllOf>
<xacml3:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<xacml3:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Gulliver's travels</xacml3:AttributeValue>
<xacml3:AttributeSelector Path="/ns1:book/ns1:title/text()" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" xmlns:ns1="http://example.com"/>
</xacml3:Match>
<xacml3:Match MatchId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than">
<xacml3:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#integer">18</xacml3:AttributeValue>
<xacml3:AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="age" DataType="http://www.w3.org/2001/XMLSchema#integer" MustBePresent="false"/>
</xacml3:Match>
</xacml3:AllOf>
</xacml3:AnyOf>
</xacml3:Target>
<xacml3:Rule RuleId="allow-read" Effect="Permit">
<xacml3:Target/>
</xacml3:Rule>
</xacml3:Policy>
XACML请求变为
<xacml-ctx:Request ReturnPolicyIdList="true" CombinedDecision="false" xmlns:xacml-ctx="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
<xacml-ctx:Attributes Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" >
<xacml-ctx:Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" IncludeInResult="true">
<xacml-ctx:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Joe</xacml-ctx:AttributeValue>
</xacml-ctx:Attribute>
<xacml-ctx:Attribute AttributeId="age" IncludeInResult="true">
<xacml-ctx:AttributeValue DataType="http://www.w3.org/2001/XMLSchema#integer">14</xacml-ctx:AttributeValue>
</xacml-ctx:Attribute>
</xacml-ctx:Attributes>
<xacml-ctx:Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" >
<xacml-ctx:Content><book xmlns="http://example.com">
<title>Gulliver's travels</title>
<isbn>xx-yy-zz</isbn>
<publisher>Axiomatics</publisher>
</book> </xacml-ctx:Content>
</xacml-ctx:Attributes>
<xacml-ctx:Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment" >
</xacml-ctx:Attributes>
<xacml-ctx:Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" >
</xacml-ctx:Attributes>
</xacml-ctx:Request>
请注意,我添加了命名空间定义(ns1,http://example.com)。完全限定XPath表达式非常重要。
如果它仍然不适合你,可能是Balana(WSO2IS)没有完全实现属性选择器。我在Axiomatics Policy Server中对它进行了测试,它运行正常。
HTH, 大卫。