XML (XACML) 语法错误 - 应为字符串文字

XML (XACML) Syntax Error - String Literal was Expected

我正在为我的硕士论文编写 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 中 运行 这个时,我收到错误...

"Exception in thread "main" java.lang.reflect.InvocationTargetException"

非常感谢任何反馈:)

你应该习惯于寻找和使用工具。我怀疑您对这样的问题会得到很多回应 :) 话虽如此,这是您修改后的 xml,不会出错。 在记事本++中,你有插件“XML Tools”。如果你安装它,并且如果你试图保存无效 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>
    

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

看看这些文章: