【问题标题】:XACML policies - Using regex for attribute values inside conditionsXACML 策略 - 对条件内的属性值使用正则表达式
【发布时间】:2017-10-20 00:17:52
【问题描述】:

我想对属性值使用正则表达式来匹配资源名称。比如http://localhost.*/private/team,这样下面的值就匹配了

http://localhost:8080/private/team, http://localhost:8080/abcd/private/team

我有以下政策

    <Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="InStorePolicy" RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable" Version="1.0">
       <Target>
          <AnyOf>
             <AllOf>
                <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                   <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">access</AttributeValue>
                   <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
                </Match>
             </AllOf>
          </AnyOf>
       </Target>
       <Rule Effect="Permit" RuleId="Rule_for_employee">
          <Target>
             <AnyOf>
                <AllOf>
                   <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                           <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">employee</AttributeValue>
                      <AttributeDesignator AttributeId="http://wso2.org/claims/role" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
                   </Match>
                </AllOf>
                <AllOf>
                   <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                      <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">manager</AttributeValue>
                      <AttributeDesignator AttributeId="http://wso2.org/claims/role" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
                   </Match>
                </AllOf>
             </AnyOf>
          </Target>
          <Condition>
             <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of">
                <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
                   <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">private/support</AttributeValue>
                   <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">private/team</AttributeValue>
                </Apply>
                <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
             </Apply>
          </Condition>
       </Rule>
       <Rule Effect="Permit" RuleId="Rule_for_manager">
          <Target>
             <AnyOf>
                <AllOf>
                   <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                           <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">manager</AttributeValue>
                      <AttributeDesignator AttributeId="http://wso2.org/claims/role" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
                   </Match>
                </AllOf>
             </AnyOf>
          </Target>
          <Condition>
             <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of">
                <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
                   <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">private</AttributeValue>
                   <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">private/business</AttributeValue>
                   <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">private/leadership</AttributeValue>
                </Apply>
                <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
             </Apply>
          </Condition>
       </Rule>
       <Rule Effect="Deny" RuleId="Rule_deny_all"/>
    </Policy>        

资源在条件标签内。我试过但无法在条件中添加字符串正则表达式函数。我可以在 string-bag 中添加正则表达式函数吗?还是我必须将其移动到目标?我怎样才能做到这一点?

问候, 阿尔比·莫肯

【问题讨论】:

    标签: authorization access-control xacml abac alfa


    【解决方案1】:

    在您的示例中,您可以简单地使用以下 XACML 函数之一:

    • stringContains (urn:oasis:names:tc:xacml:3.0:function:string-contains)
    • stringEndsWith (urn:oasis:names:tc:xacml:3.0:function:string-ends-with)

    编辑

    这两个函数适用于原子值,例如"a",或"b"。默认情况下,XACML 中的属性是包。这意味着角色是一袋值(可以是 0、1 或更多值——不过是一个袋子)。这意味着如果你想在一个包上使用 stringContains() ,你需要先使用 stringOneAndOnly 将包转换为单个值,或者你需要使用高阶函数。

    stringOneAndOnly

    尝试以下示例(使用 ALFA 表示法)

    // The result SHALL be true if the second string contains the first string, and false otherwise.
    stringContains("manager", stringOneAndOnly(role))
    

    高阶函数

    您也可以使用AnyOfAnyOfAny 应用于stringContains()

    【讨论】:

    • 但是如何将它与 string-bag 一起使用?我需要类似下面的 w3.org/2001/XMLSchema#string">http://localhost.*/private/supportw3.org/2001/XMLSchema#string">http://localhost.*/private/team 有没有从列表中检查字符串的其他方法?
    猜你喜欢
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    • 2018-09-26
    • 2019-08-11
    • 2016-10-20
    • 2014-07-02
    • 2019-09-21
    • 1970-01-01
    相关资源
    最近更新 更多