Проверка политики Xacml в строке - PullRequest
2 голосов
/ 18 октября 2019

Я пытаюсь придумать правило, которое гласит, что строка должна начинаться с ABC, но не должна быть ABC123, ABC456, ABC789.

Я пытаюсь написать эточтобы оценить против мешка строки, любые указатели очень ценятся.

1 Ответ

1 голос
/ 18 октября 2019

Вам понадобятся две вещи:

  1. Проверка, которая соответствует вашему атрибуту (например, a) со значением (ABC)
  2. Условие, которое проверяетодин и тот же атрибут не является ни одним из ABC123, ABC456, ABC789.

Есть (как минимум) два способа сделать это:

  1. Вымог бы написать политику, которая проверяет, что атрибут начинается с ABC, а затем иметь правило, запрещающее доступ, если значение является одним из 3 запрещенных или
  2. . Вы можете написать политику, которая проверяет, что атрибут начинается с ABC и возвращает разрешение, только если значение не является одним из 3 запрещенных.

ALFA Пример

ALFA, сокращенный язык для AuthZ, является упрощенным синтаксисом для XACMLполитики. (Источник: , Википедия )

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>
...