【问题标题】:Xacml policy test occurence of string in string bagXacml 策略测试字符串包中字符串的出现
【发布时间】:2019-10-19 03:14:53
【问题描述】:

我正在尝试提出一个规则,即字符串必须以 ABC 开头,但不能以 ABC123ABC456ABC789 开头。

我正在尝试写这个来评估一个字符串包,任何指针都非常感谢。

【问题讨论】:

    标签: authorization access-control xacml abac alfa


    【解决方案1】:

    你需要两件事:

    1. 将您的属性(例如a)与值(ABC)相匹配的检查
    2. 检查相同属性的条件不是ABC123ABC456ABC789

    有(至少)两种方法可以做到这一点:

    1. 您可以编写一个策略来检查以 ABC 开头的属性,然后制定一个规则,如果该值是 3 个禁止值之一,则拒绝访问或
    2. 您可以编写一个策略来检查以 ABC 开头的属性,并且仅当该值不是 3 个禁止值之一时才返回 permit。

    ALFA 示例

    ALFA 是 AuthZ 的缩写语言,是 XACML 策略的轻量级语法。 (来源:Wikipedia

    namespace com.axiomatics{
        attribute a{
            category = subjectCat
            id = "com.axiomatics.a"
            type = string
        }
        /**
         * This policy allows access if the string starts with ABC but is not ABC123, ABC456, or ABC789
         */
        policy example{
            apply firstApplicable
            /**
             * Deny specific values
             */
            rule denySpecificValues{
                target clause a == "ABC123" or a == "ABC456" or a == "ABC789"
                deny
            }
            /**
             * Allow if the string starts with ABC
             */
            rule startsWithABC{
                target clause stringStartsWith("ABC", a)
                permit
            }
        }
        /**
         * This policy allows access if the string starts with ABC but is not ABC123, ABC456, or ABC789
         */
        policy anotherExample{
            apply firstApplicable
            /**
             * Allow if the string with ABC
             */
            rule startsWithABC{
                target clause stringStartsWith("ABC", a)
                permit
                condition not (a == "ABC123") && not(a == "ABC456") || not(a == "ABC789")
            }
        }
    }
    

    XACML XML 等效项

    <?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/com.axiomatics.example"
        RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable"
        Version="1.0">
        <xacml3:Description>This policy allows access if the string starts with
            ABC but is not ABC123, ABC456, or ABC789</xacml3:Description>
        <xacml3:PolicyDefaults>
            <xacml3:XPathVersion>http://www.w3.org/TR/1999/REC-xpath-19991116
            </xacml3:XPathVersion>
        </xacml3:PolicyDefaults>
        <xacml3:Target />
        <xacml3:Rule Effect="Deny"
            RuleId="com.axiomatics.example.denySpecificValues">
            <xacml3:Description>Deny specific values</xacml3:Description>
            <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">ABC123</xacml3:AttributeValue>
                            <xacml3:AttributeDesignator
                                AttributeId="com.axiomatics.a"
                                Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                                DataType="http://www.w3.org/2001/XMLSchema#string"
                                MustBePresent="false" />
                        </xacml3:Match>
                    </xacml3:AllOf>
                    <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">ABC456</xacml3:AttributeValue>
                            <xacml3:AttributeDesignator
                                AttributeId="com.axiomatics.a"
                                Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                                DataType="http://www.w3.org/2001/XMLSchema#string"
                                MustBePresent="false" />
                        </xacml3:Match>
                    </xacml3:AllOf>
                    <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">ABC789</xacml3:AttributeValue>
                            <xacml3:AttributeDesignator
                                AttributeId="com.axiomatics.a"
                                Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                                DataType="http://www.w3.org/2001/XMLSchema#string"
                                MustBePresent="false" />
                        </xacml3:Match>
                    </xacml3:AllOf>
                </xacml3:AnyOf>
            </xacml3:Target>
        </xacml3:Rule>
        <xacml3:Rule Effect="Permit"
            RuleId="com.axiomatics.example.startsWithABC">
            <xacml3:Description>Allow if the string starts with ABC
            </xacml3:Description>
            <xacml3:Target>
                <xacml3:AnyOf>
                    <xacml3:AllOf>
                        <xacml3:Match
                            MatchId="urn:oasis:names:tc:xacml:3.0:function:string-starts-with">
                            <xacml3:AttributeValue
                                DataType="http://www.w3.org/2001/XMLSchema#string">ABC</xacml3:AttributeValue>
                            <xacml3:AttributeDesignator
                                AttributeId="com.axiomatics.a"
                                Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
                                DataType="http://www.w3.org/2001/XMLSchema#string"
                                MustBePresent="false" />
                        </xacml3:Match>
                    </xacml3:AllOf>
                </xacml3:AnyOf>
            </xacml3:Target>
        </xacml3:Rule>
    </xacml3:Policy>
    

    【讨论】:

    • 感谢您的回复。我必须在一个规则和条件标签中添加这些。我不能检查,因为我检查了 Target 中的其他值。我希望在 Condition 标签中检查这个条件。我可以使用starts-with和all-of-any吗?再次感谢
    • 或者我可以使用正则表达式来检查值包是否以“abc”开头但不等于 abc123 和 abc456 和 abc789。或者我想从值包中删除“abc123”、“abc456”和“abc789”,然后检查是否有任何字符串以“abc”开头,不知道该怎么做。
    猜你喜欢
    • 2020-02-29
    • 2017-12-29
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    • 2012-02-18
    相关资源
    最近更新 更多