我正在以一个非常新的人的身份从事xacml的工作,并且正在制定一些政策。当然,我遇到了问题,通常我会先向Java中抛出一些print.ln语句,以开始弄清楚代码将到达(或不到达)的位置,但是我在OASIS文档中看不到任何内容XACML进行打印或调试。

因此,我想知道是否有办法做到这一点,或者我是否可以投入一些东西来弄清楚在策略/规则评估中某事在何处或为什么起作用。

特定的问题是我正在从策略规则中获得许可,似乎评估“ P”与“ PI”相同,然后为其返回许可。

    <Condition>
        <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of">
            <Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal" />
            <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">PI</AttributeValue>
            <AttributeDesignator
                AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id"
                Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true" />
        </Apply>
    </Condition>


我认为这可能是该函数:any-of和字符串等于函数导致它在这里评估真实条件,但是我不确定。我正在与另一个人一起工作,他似乎坚持认为这不是问题,但我没有完整的代码来解决。

但是仍然有一种打印方法会很棒,特别是因为我想知道当运行不同的算法(如第一个适用的算法)时,我的评估结果如何。

最佳答案

您所追求的与OASIS XACML规范无关,与您所使用的引擎无关。您必须告诉Balana打印语句/跟踪。 Axiomatics Policy Server为您提供了这种可能性:您可以模拟评估并追溯显示发生了什么,获得的结果以及原因的踪迹。

您的代码段说,如果urn:oasis:names:tc:xacml:1.0:subject:subject-id至少有一个值(由于标志MustBePresent设置为true),它将返回true,并且这些值之一必须等于PI

例如,如果您具有以下策略(与您的策略相同,但包含在RulePolicy中:

ALFA表示法(wikipedia

namespace example{

    import Attributes.*

    policy simpleCondition{
        apply firstApplicable
        rule simpleCondition{
            condition "PI"==subjectId
            permit
        }

    }
}


XACML 3.0表示法

<?xml version="1.0" encoding="UTF-8"?>
 <!--This file was generated by the ALFA Plugin for Eclipse from Axiomatics AB (http://www.axiomatics.com).
 Any modification to this file will be lost upon recompilation of the source ALFA file-->
<xacml3:Policy xmlns:xacml3="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
    PolicyId="http://axiomatics.com/alfa/identifier/example.simpleCondition"
    RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
    Version="1.0">
    <xacml3:Description />
    <xacml3:PolicyDefaults>
        <xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116</xacml3:XPathVersion>
    </xacml3:PolicyDefaults>
    <xacml3:Target />
    <xacml3:Rule
            Effect="Permit"
            RuleId="http://axiomatics.com/alfa/identifier/example.simpleCondition.simpleCondition">
        <xacml3:Description />
        <xacml3:Target />
        <xacml3:Condition>
            <xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:any-of">
                <xacml3:Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
                <xacml3:AttributeValue
                    DataType="http://www.w3.org/2001/XMLSchema#string">PI</xacml3:AttributeValue>
                <xacml3:AttributeDesignator
                    AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id"
                    DataType="http://www.w3.org/2001/XMLSchema#string"
                    Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                    MustBePresent="false"
                />
            </xacml3:Apply>
        </xacml3:Condition>
    </xacml3:Rule>
</xacml3:Policy>


使用公理政策管理点(PAP)测试政策

构建一个XACML请求以测试您的用例。

空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: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:Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" >
   </xacml-ctx:Attributes>
   <xacml-ctx:Attributes Category="http://axiomatics.com/xacml/attribute-category/none" >
   </xacml-ctx:Attributes>
</xacml-ctx:Request>


由于MustBePresent标志,此请求导致不确定。

XACML请求带有错误的主题ID

<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="http://axiomatics.com/xacml/attribute-category/none" >
   </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:resource" >
   </xacml-ctx:Attributes>
   <xacml-ctx:Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" >
   </xacml-ctx:Attributes>
   <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">Not PI</xacml-ctx:AttributeValue>
      </xacml-ctx:Attribute>
   </xacml-ctx:Attributes>
</xacml-ctx:Request>


该请求导致NotApplicable。

具有正确主题ID PI的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="http://axiomatics.com/xacml/attribute-category/none" >
   </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:resource" >
   </xacml-ctx:Attributes>
   <xacml-ctx:Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" >
   </xacml-ctx:Attributes>
   <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">PI</xacml-ctx:AttributeValue>
      </xacml-ctx:Attribute>
   </xacml-ctx:Attributes>
</xacml-ctx:Request>


此请求导致获得许可。

这是公理政策管理点中的评估轨迹:

关于java - 如何使用Java获取XACML控制台打印,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31417006/

10-10 14:56