【问题标题】:XACML policy containing XPath expression does not work when published in WSO2 Identity Server 5.0在 WSO2 Identity Server 5.0 中发布时,包含 XPath 表达式的 XACML 策略不起作用
【发布时间】:2014-07-03 07:51:44
【问题描述】:

我尝试了来自http://www.webfarmr.eu/2011/08/xacml-102-xpath-and-xacml/ 的第一个示例,“XPath used in a single XACML request”部分。以防万一这里是 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 请求时,响应会返回许可决定。请注意,该政策尚未发布。

在我发布策略之后,启用它并使用“工具”->“XACML”菜单中的“尝试”选项。结果是“不适用”。

我在“策略管理”和“策略视图”中都没有任何其他策略。

包含 XPath 表达式的 XACML 策略是否需要一些额外的配置?提供的场景有什么问题?

编辑: 在日志中发现这条消息:

[2014-07-03 11:13:25,021]  INFO {org.wso2.balana.finder.AttributeFinder} -  Failed to resolve any values for /book/title/text()

【问题讨论】:

    标签: xpath wso2 wso2is xacml xacml3


    【解决方案1】:

    是的。这是身份服务器中的一个错误。请参考公众号jira。然而,这并不是因为 XPAth 没有在 Balana 中实现,也不是 Balana 的问题。它与 Identity Server 和 Identity Server 未正确初始化 Balana 引擎有关。

    您甚至可以找到附加到公共jira 的修复程序,您可以尝试使用该修复程序。您可以从 here 找到有关使用 Identity Server 的 XPath 示例的更多详细信息

    【讨论】:

    • 谢谢阿塞拉。如果其他人遇到同样的问题 - 最好将提供的 jar 文件放到单独的补丁中(例如 patch0009)。
    【解决方案2】:

    在编写示例时,我忽略了添加命名空间。您需要添加名称空间,然后它应该可以正常工作。例如,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&apos;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, 大卫。

    【讨论】:

    • 不幸的是,即使通过“策略管理”也无法使用。响应描述:org.apache.xpath.domapi.XPathStylesheetDOM3Exception:前缀必须解析为命名空间:ns1 xmlns:ns1 定义在保存后从策略中删除。无论如何,感谢 David 的出色回应和完整的工作(至少在其他服务器中)示例。
    • 那么它看起来像是 WSO2 IS 产品中的一个错误。您可以随时向axiomatics.com申请APS下载
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多