代码之家  ›  专栏  ›  技术社区  ›  Albie Morken

XACML策略-获取“不确定”响应

  •  1
  • Albie Morken  · 技术社区  · 7 年前

    我试图探索WSO2中的XACML。我在WSO2 IS 5.3.0中使用以下策略

        <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"></AttributeDesignator>
                    </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://test.org/claim/role" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator>
                       </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"></AttributeDesignator>
                       </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"></AttributeDesignator>
                 </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"></AttributeDesignator>
                       </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"></AttributeDesignator>
                 </Apply>
              </Condition>
           </Rule>
           <Rule Effect="Deny" RuleId="Rule_deny_all"></Rule>
        </Policy>        
    

    我创建了具有经理和员工角色的用户。但是当我使用具有以下值的“Tryit”时,我得到了“不确定”

    主题:员工1, 资源:/私人/团队

    -阿尔比·莫肯

    1 回复  |  直到 2 年前
        1
  •  2
  •   David Brossard    7 年前

    我使用Axiomatics策略服务器尝试了您的策略,我相信我可能已经找到了您问题的根本原因。您的某些属性标记为 MustBePresent . 这是一个可选标志,如果设置为true,则如果属性没有值,则会使计算返回不确定。

    访问审查

    以下是授予访问权限的三种不同方式:

    1. stringAtLeastOneMemberOf(stringBag("private/support" , "private/team") , Attributes.resource.resource_id ) AND "access" == Attributes.action.action_id AND "Employee" == http://test.org/claim/role

    2. "Manager" == http://wso2.org/claims/role AND stringAtLeastOneMemberOf(stringBag("private/support" , "private/team") , Attributes.resource.resource_id ) AND "access" == Attributes.action.action_id

    3. "Manager" == http://wso2.org/claims/role AND "access" == Attributes.action.action_id AND stringAtLeastOneMemberOf(stringBag("private" , "private/business" , "private/leadership") , Attributes.resource.resource_id )

    ALFA ,授权的缩写语言。

    政策审查

    这是您的策略在策略编辑器中的外观。

    Axiomatics Policy Editor

    顺便说一句,你的政策中有几件奇怪的事情:

    1. 您使用了两个相似但不同的属性标识符( http://wso2.org/claims/role http://test.org/claim/role ). 这是故意的吗?
    2. 我不确定是否需要将属性标记为 必须在场 . 我通常不会,但这可能是一种偏好。
    3. 当一个简单的目标可以实现时,您可以使用条件

    之前

    The rule before update

    之后

    以下内容比前者更容易阅读。

    The rule with a combined target

    样本请求/响应

    以下示例利用了XACML的JSON配置文件( Wikipedia | Blog post )

    {
        "Request": {
            "AccessSubject": {
                "Attribute": [
                    {
                        "AttributeId": "http://test.org/claim/role",
                        "Value": "Employee"
                    }
                ]
            },
            "Resource": {
                "Attribute": [
                    {
                        "AttributeId": "urn:oasis:names:tc:xacml:1.0:resource:resource-id",
                        "Value": "private/support"
                    }
                ]
            },
            "Action": {
                "Attribute": [
                    {
                        "AttributeId": "urn:oasis:names:tc:xacml:1.0:action:action-id",
                        "Value": "access"
                    }
                ]
            },
            "Environment": {
                "Attribute": []
            }
        }
    }
    

    和匹配的响应

    {
      "Response" : {
        "Decision" : "Permit",
        "Status" : {
          "StatusCode" : {
            "Value" : "urn:oasis:names:tc:xacml:1.0:status:ok",
            "StatusCode" : {
              "Value" : "urn:oasis:names:tc:xacml:1.0:status:ok"
            }
          }
        }
      }
    }