【问题标题】:XML (XACML) Syntax Error - String Literal was ExpectedXML (XACML) 语法错误 - 应为字符串文字
【发布时间】:2021-07-04 21:53:02
【问题描述】:

我正在为我的硕士论文编写 XACML 策略,但遇到了明显的语法错误。它突出了第一行;但是,我不确定。我对 XML 很陌生,所以这可能是一个非常愚蠢的错误 :)

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<PolicySet xsi:schemaLocation="urn:oasis:names:tc:xacml:2.0:policy:schema:os 
C:\Users\home\OneDrive\Documents\core-release Authzforce Testing\IIA001" PolicySetId="CAVPolicies" 
PolicyCombiningAlgId="urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:permit-unless- 
deny" xmlns="urn:oasis:names:tc:xacml:2.0:policy:schema:os" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Target xmlns="urn:oasis:names:tc:xacml:2.0:policy:schema:os">

</Target>
<Policy PolicyId=CAV1 RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:permit-unless-deny">
<Target/>
    <Rule RuleId="CAVRSU" Effect="Deny">
        <Description>Vehicles will relay data to a roadside unit upon request. Attempts to read vehicle path histories, applicable lane numbers. 
            Calculates chance of a vehicle committing a stop violation. </Description>
        
    <Condition>
            <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
                <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of">
                    <SubjectAttributeDesignator AttributeId="CommunicationStructure" DataType="http://www.w3.org/2001/XMLSchema#string"/>
                    <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
                        <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">RSU</AttributeValue>
                    </Apply>
                </Apply
                <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of">
                    <ResourceAttributeDesignator AttributeId="CAVData" DataType="http://www.w3.org/2001/XMLSchema#string"/>
                    <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
                        <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Vehicle Path History</AttributeValue>
                    </Apply>
                </Apply>
                <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of">
                    <Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
                    <ActionAttributeDesignator DataType="http://www.w3.org/2001/XMLSchema#string" AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id"/>
                    <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">READ</AttributeValue>
                </Apply>
                <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:or">
                    <Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:boolean-equal"/>
                    <EnvironmentAttributeDesignator DataType="http://www.w3.org/2001/XMLSchema#boolean" AttributeId="VehicleWithinRSURange"/>
                    <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#boolean">True</AttributeValue>
                </Apply>
                </Apply>
            </Apply>
        </Condition>
    </Rule>
</Policy>
</PolicySet>

作为参考,我在 Notepad++ 中编写这些策略,然后在 authforce PDP 中对其进行测试。当我在 authforce 中运行它时,我得到了错误...

“线程“main”中的异常 java.lang.reflect.InvocationTargetException”

非常感谢您对任何事情的任何反馈:)

【问题讨论】:

    标签: xml authorization xacml abac alfa


    【解决方案1】:

    您应该习惯于寻找和使用工具。我怀疑你会得到很多这样的问题的回应 :) 话虽如此,这是你修改后的 xml,它不会给出错误。 在记事本++ 中,您有插件“XML 工具”。如果您安装它,并且如果您尝试保存无效的 xml,则会出现错误。您还可以在您喜欢的浏览器中显示 xml 并获取错误消息。您可以看到您提供的 xml 和我使用 diff 实用程序放在下面的差异,我使用“winmerge (winmerge.com)”

    简而言之,问题是:

    • 额外的“应用”标签

    • 未关闭的“应用”标签

    • policyId 属性值缺少双引号

          <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      
      <PolicySet xsi:schemaLocation="urn:oasis:names:tc:xacml:2.0:policy:schema:os " PolicySetId="CAVPolicies" PolicyCombiningAlgId="urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:permit-unless-deny" xmlns="urn:oasis:names:tc:xacml:2.0:policy:schema:os" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Target xmlns="urn:oasis:names:tc:xacml:2.0:policy:schema:os">
      
      </Target>
      <Policy PolicyId="CAV1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:permit-unless-deny">
      <Target/>
          <Rule RuleId="CAVRSU" Effect="Deny">
              <Description>Vehicles will relay data to a roadside unit upon request. Attempts to read vehicle path histories, applicable lane numbers. 
                  Calculates chance of a vehicle committing a stop violation. </Description>
      
          <Condition>
                  <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
                      <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of">
                          <SubjectAttributeDesignator AttributeId="CommunicationStructure" DataType="http://www.w3.org/2001/XMLSchema#string"/>
                          <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
                              <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">RSU</AttributeValue>
                          </Apply>
                      </Apply>
                      <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of">
                          <ResourceAttributeDesignator AttributeId="CAVData" DataType="http://www.w3.org/2001/XMLSchema#string"/>
                          <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
                              <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">Vehicle Path History</AttributeValue>
                          </Apply>
                      </Apply>
                      <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of">
                          <Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
                          <ActionAttributeDesignator DataType="http://www.w3.org/2001/XMLSchema#string" AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id"/>
                          <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">READ</AttributeValue>
                      </Apply>
                      <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:or">
                          <Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:boolean-equal"/>
                          <EnvironmentAttributeDesignator DataType="http://www.w3.org/2001/XMLSchema#boolean" AttributeId="VehicleWithinRSURange"/>
                          <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#boolean">True</AttributeValue>
                      </Apply>
                      </Apply>
              </Condition>
          </Rule>
      </Policy>
      </PolicySet>
      

    【讨论】:

    • 所有这些实际上都是 XML 错误,正如 Vish 所说,使用适当的 XML 工具将有助于捕获这些错误。
    【解决方案2】:

    @vish 的回答是正确的:您有基本的 XML 错误。您应该使用 XML 验证工具(烘焙到 Notepad ++ 甚至在线,例如 here)。此外,如果您只想编写 XACML。我建议你使用 Eclipse 和 Eclipse 的 ALFA 插件,因为它更容易编写 ALFA(然后直接翻译成 XACML)。

    看看这些文章:

    【讨论】:

    • 我自己说得再好不过了。如果您对 ALFA 有任何疑问,请随时与我联系(如果 David 不在……)。
    • 嗨@MichaelCGood :-)
    猜你喜欢
    • 1970-01-01
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 2014-08-30
    • 2013-11-14
    • 1970-01-01
    相关资源
    最近更新 更多