2

我正在尝试将我们的数据库模型输入 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
          }
      }
   }
}
4

1 回答 1

2

你有一个很好的问题。

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

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

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

/**
 * 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

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

对评论的回答

按照惯例,您试图避免的复数名称是什么?

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。
于 2018-05-23T18:27:50.393 回答