【问题标题】:1:n relationships and complex attribute types in ALFAALFA 中的 1:n 关系和复杂属性类型
【发布时间】:2018-05-23 09:46:00
【问题描述】:

我正在尝试将我们的数据库模型输入 ALFA,以检查 ALFA 和 XACML 的功能。

以下属性是否可能?那么规则会如何呢?

1:n 按字符串列表

namespace com.mycompany {
   namespace resources {
       namespace patient {
                attribute trustedDoctorIds{
                    category = resourceCat
                    id = "trustedDoctorIds"
                    type = list<string> //maybe it should be bag[string]
                }                
       }
   }
}

1:n 按复杂类型列表

namespace com.mycompany {
   namespace resources {
       namespace patient {
                attribute trustedDoctors{
                    category = resourceCat
                    id = "trustedDoctors"
                    type = list<doctor> //maybe it should be bag[doctor]
                } 
       }
   }

   namespace subjects {
      namespace doctor {
          attribute id {
                    category = subjectCat
                    id = "id"
                    type = string
          }
          attribute lastname {
                    category = subjectCat
                    id = "lastname"
                    type = string
          }
      }
   }
}

【问题讨论】:

    标签: xacml abac alfa


    【解决方案1】:

    你有一个很好的问题。

    默认情况下,ALFA 和 XACML 中的所有属性都是多值的。属性是一组值而不是单个值。这意味着当您定义以下内容时,

                attribute trustedDoctorIds{
                    category = resourceCat
                    id = "trustedDoctorIds"
                    type = string
                }     
    

    这意味着属性具有字符串类型,并且可以是多值的。您可以选择在属性定义上方的 cmets 中表达基数信息,例如

    /**
     * This attribute, trustedDoctorIds, contains the list of doctors a patient 
     *trusts. The list can have 0 or more values.
     */
    

    该策略将根据所使用的功能传达多少值。

    例如,你可以写一个条件来说明

    stringOneAndOnly(trustedDoctorIds)==stringOneAndOnly(userId)
    

    在这种情况下,您将强制每个属性具有一个值且仅具有一个值。如果您有 0 个或超过 1 个值,则 XACML 策略的评估将产生 Indeterminate

    在 XACML(或 ALFA)目标中,当您编写时:

    trustedDoctorIds == "Joe"
    

    您是说:如果trustedDoctorIds 中至少有一个值等于'Joe'...

    在 ALFA 条件下,当您编写时

    trustedDoctorIds==userId
    

    您是说:*如果trustedDoctorIds 中的至少一个值等于userId 中的至少一个值

    注意:我总是尽可能地为我的属性使用单数名称。这是一个约定,而不是硬性限制。记住属性的基数将有助于以后的策略测试。

    对 cme​​ts 的回答

    按照惯例,您会尽量避免使用复数名称?

    WelltrustedDoctorId***s*** 在我看来相当复数。我会使用trustedDoctorId,除非您知道该属性必须始终是多值的。

    所以,这应该是可能的:在我的请求中,我提供了 resource.patient.trustedDoctorIds=="2,13,67" 和 subject.doctor.id=="6"。那么规则在 ALFA 中会是什么样子?嗯。比如“resource.patient.trustedDoctorIds.contains(subject.doctor.id) permit”

    规则如下所示:

    stringIsIn(stringOneAndOnly(subject.doctor.id),resource.patient.trustedDoctorIds)
    

    确保您在请求中提供多个值,而不是一个包含逗号分隔值的值。发送 [1,2,3] 而不是 "1,2,3"。

    进一步修改

    因此,通过 [2,13,67],结果按预期拒绝,而不是像“2,13,67”和医生 ID==6 那样允许。我特意选择了那个例子,因为 stringIsIn 函数会导致不必要的结果为真,因为 6 包含在 67 中

    不要混淆stringIsIn()stringContains()

    • stringIsIn(a, b) 接受 2 个参数 a 和 b,其中 a 是原子值,b 是值包。 stringIsIn(a, b) 如果 a 的值在 b 的值包中,则返回 true。
    • stringContains(a, b) 接受 2 个参数 a 和 b,它们都是字符串类型的原子值。如果在 b 中找到字符串值 a,则返回 true。
    例子:
    • 如果用户的单一国籍等于瑞典或德国,stringIsIn(stringOneAndOnly(userCitizenship), stringBag("Swedish", "German")) 返回 true。
    • stringContains("a", "alfa") 如果第二个字符串包含第一个字符串,则返回 true。所以在这个例子中它返回 true。

    【讨论】:

    • 按照惯例,您尽量避免使用复数名称?
    • 所以,这应该是可能的:在我的请求中,我提供了 resource.patient.trustedDoctorIds=="2,13,67" 和 subject.doctor.id=="6"。那么规则在 ALFA 中会是什么样子?嗯。比如“resource.patient.trustedDoctorIds.contains(subject.doctor.id) permit”
    • 因此,通过 [2,13,67],结果按预期被拒绝,而不是像“2,13,67”和医生 ID==6 那样允许。我特意选择了这个例子,因为 stringIsIn 函数会导致不必要的结果为真,因为 6 包含在 67 中
    • 我假设我的第二个示例“1:n 按复杂类型列表”不受支持
    • 感谢您对博客的推荐。我知道我已经使用过的那个和你的 youtube 教程。现在我要问一些尚未回答我的问题,以获得完整的画面。 SO 最适合这种问答形式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    • 2020-02-14
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    相关资源
    最近更新 更多