简体   繁体   English

使用 Authzforce 在 XACML 中表示复杂数据类型

[英]Representing complex data types in XACML using Authzforce

I am new to XACML and I would be grateful if you can help me with one problem I encountered.我是 XACML 的新手,如果您能帮助我解决我遇到的一个问题,我将不胜感激。 I use AuthzForce Core PDP (version 17.1.2).我使用 AuthzForce Core PDP(版本 17.1.2)。 I am wondering what is the correct approach of representing complex data types in XACML.我想知道在 XACML 中表示复杂数据类型的正确方法是什么。

Example例子

Access should be granted if PIP response contains any person whose name is present in names array from request and salary of that person is higher than salary provided in request.如果 PIP 响应包含任何姓名出现在请求中的名称数组中且该人的薪水高于请求中提供的薪水的人,则应授予访问权限。

Request要求

names = ["Eric", "Kyle"]
salary = 1500

PIP response PIP 响应

[
  {
    "name": "Kyle",
    "salary": 1000
  },
  {
    "name": "Kenny",
    "salary": 2000
  },
  {
    "name": "Eric",
    "salary": 4000
  },
  {
    "name": "Stan",
    "salary": 3000
  }
]

Access will be granted because PIP response contains person with name Eric and his salary is higher than 1500.将授予访问权限,因为 PIP 响应包含名为 Eric 的人员,并且他的薪水高于 1500。

My implementation To represent PIP response I ended up with creating custom type by extending StringParseableValue class from AuthzForce.我的实现为了表示 PIP 响应,我最终通过从 AuthzForce 扩展 StringParseableValue class 创建了自定义类型。 For above mentioned logic I use attribute designator in xml and have coresponding attribute provider (class extending BaseNamedAttributeProvider) in Java performing PIP call.对于上述逻辑,我在 xml 中使用属性指示符,并在执行 PIP 调用的 Java 中具有相应的属性提供程序(扩展 BaseNamedAttributeProvider 的类)。

I also wrote two custom functions:我还写了两个自定义函数:

  1. Find people with higher salary than provided in one param (returns filtered list)查找薪水高于一个参数中提供的人(返回过滤列表)
  2. Get person name (returns string) And using those functions and standard function I wrote policy and it works.获取人名(返回字符串)并使用这些函数和标准 function 我编写了策略并且它有效。

However my solution seems to be overcomplicated.但是,我的解决方案似乎过于复杂。 I suppose what I did can be achieved by using only standard functions.我想我所做的可以通过仅使用标准函数来实现。 Additionally if I wanted to define hardcoded bag of people inside other policy single element would look like this:此外,如果我想在其他策略单个元素中定义硬编码的人员包,则如下所示:

<AttributeValue DataType="person">name=Eric@@@salary=4000</AttributeValue>

There is always possibility that parsing of such strings might fail.总是有可能解析此类字符串可能会失败。

So my question is: What is a good practice of representing complex types like my PIP response in XACML using Authzforce?所以我的问题是:使用 Authzforce 在 XACML 中表示像我的 PIP 响应这样的复杂类型的良好做法是什么? Sometimes I might need to pass more complex data in the request and I saw example in XACML specification showing passing such data inside <Content> element.有时我可能需要在请求中传递更复杂的数据,我在 XACML 规范中看到了显示在<Content>元素中传递此类数据的示例。

Creating a new XACML data-type - and consequently new XACML function(s) to handle that new data-type - seems a bit overkill indeed.创建一个新的 XACML 数据类型 - 并因此创建新的 XACML 函数来处理该新数据类型 - 确实似乎有点矫枉过正。 Instead, you may improve your PIP (Attribute Provider) a little bit, so that it returns only the results for the employees named in the Request, and only their salaries (extracting them from the JSON using JSON path) returned as a bag of integers.相反,您可以稍微改进您的 PIP(属性提供程序),以便它只返回请求中指定的员工的结果,并且只返回他们的薪水(使用 Z0ECD11C1D7A287401D148A2 从 JSON 中提取它们)返回一个整数包 7222FZD148A2 .

Then, assuming this PIP result is set to the attribute employee_salaries in your policy (bag of integers) for instance, and min_salary is the salary in the Request, it is just a matter of applying any-of(integer-less-than, min_salary, employee_salaries) in a Condition.然后,假设此 PIP 结果设置为策略中的属性employee_salaries (整数包),并且min_salary是请求中的薪水,只需应用any-of(integer-less-than, min_salary, employee_salaries)在一个条件。 (I'm using short names for the functions by convenience, please refer to the XACML 3.0 standard for the full identifiers.) (为方便起见,我为函数使用了短名称,请参阅 XACML 3.0 标准以获取完整标识符。)

Tips to improve the PIP:改进 PIP 的提示:

  1. One issue here is performance (scalability, response time / size...) because if you have hundreds even thousands of employees, it is overkill to get the whole list from the REST service over and over, all the more as you need only a small subset (the names in the Request).这里的一个问题是性能(可扩展性、响应时间/大小......),因为如果您有成百上千的员工,那么一遍又一遍地从 REST 服务获取整个列表是多余的,因为您只需要一个小子集(请求中的名称)。 Instead, you may have some way to request the REST service to return only a specific employees, using query parameters;相反,您可以通过某种方式使用查询参数请求 REST 服务仅返回特定员工; an example using RSQL (but this depends on the REST service API):使用RSQL的示例(但这取决于 REST 服务 API):
HTTP GET http://rest-service.example.com/employees?search=names=in=($employee_names)

... where you set the $employee_names variable to (a comma-separated list of) the employee names from the Request (eg Eric,Kyle ). ...您将$employee_names变量设置为(以逗号分隔的)请求中的员工姓名(例如Eric,Kyle )。 You can get these in your AttributeProvider implementation, from the EvaluationContext argument of the overriden get(...) method ( EvaluationContext#getNamedAttributeValue(...) ).您可以在 AttributeProvider 实现中从被覆盖的get(...)方法 ( EvaluationContext#getNamedAttributeValue(...) ) 的EvaluationContext参数中获取这些信息。

Then you can use a JSON path library (as you did) to extract the salaries from the JSON response (so you have only the salaries of the employees named in the Request), using this JSON path for instance (tested with Jayway ):然后,您可以使用 JSON 路径库(如您所做的那样)从 JSON 响应中提取薪水(因此您只有请求中指定的员工的薪水),使用此 Z0ECD11C1D7A287401D148A23BB 路径的Z0ECD11C1D7A287401D148A23BB

$[*].salary
  1. If the previous option is not possible, ie you have no way of filtering employees on the REST API, you can always do this filtering in your AttributeProvider implementation with the JSON path library, using this JSON path for instance (tested with Jayway against your PIP response): If the previous option is not possible, ie you have no way of filtering employees on the REST API, you can always do this filtering in your AttributeProvider implementation with the JSON path library, using this JSON path for instance (tested with Jayway against your PIP回复):
$[?(@.name in [$employee_names])].salary

... where you set the $employee_names variable like in the previous way, getting the names from the EvaluationContext . ...您像以前一样设置$employee_names变量,从EvaluationContext获取名称。 So the actual JSONpath after variable replacement would be something like:因此,变量替换后的实际 JSONpath 将类似于:

$[?(@.name in [Eric,Kyle])].salary

(You may add quotes to each name to be safe.) (您可以为每个名称添加引号以确保安全。)

All things considered, if you still prefer to go for new XACML data-type (and functions), and since you seem to have done most of the work (impressive btw), I have a suggestion - if doable without to much extra work - to generalize the Person data-type to more generic JSON object datatype that could be reused in any use case dealing with JSON.考虑到所有因素,如果您仍然更喜欢 go 来获得新的 XACML 数据类型(和函数),并且由于您似乎已经完成了大部分工作(令人印象深刻的顺便说一句),我有一个建议 - 如果可以在没有太多额外工作的情况下 -将 Person 数据类型推广到更通用的 JSON object 数据类型,可以在处理 JSON 的任何用例中重用。 Then see whether the extra functions could be done with a generic JSONPath evaluation function applied to the new JSON object data-type.然后查看是否可以通过将通用 JSONPath 评估 function 应用于新的 JSON object 数据类型来完成额外的功能。 This would provide a JSON equivalent to the standard XML/XPath data-type and functions we already have in XACML, and this kind of contribution would benefit the AuthzForce community greatly.这将提供一个 JSON 等效于我们在 XACML 中已有的标准 XML/XPath 数据类型和函数,这种贡献将使 AuthzForce 社区受益匪浅。

For the JSON object data-type, actually you can use the one in the testutils module as an example: CustomJsonObjectBasedAttributeValue which has been used to test support of JSON objects for the GeoXACML extension.对于 JSON object 数据类型,实际上您可以使用 testutils 模块中的一个示例: CustomJsonObjectBasedAttributeValue ,它已用于测试 Z0ECD11C1D7A287401D148A23ZACMLA 扩展的对象支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM