【问题标题】:Storing XACML file in JSON using MongoDB for Authzforce使用 MongoDB for Authzforce 以 JSON 格式存储 XACML 文件
【发布时间】:2018-06-27 11:13:00
【问题描述】:

我想使用您在自述文件中提到的 authzforce-ce-core-pdp-engine jar 文件实现 PDP 引擎,但 XML 中的策略文件除外应该是动态的。主要思想类似于文件共享系统,因为一个用户可以将多个文件共享给其他用户,每个文件可能有不同的策略。我正在考虑将策略文件存储在 MySQL 或 MongoDB 等某种数据库中,PDP 将引用它并根据请求决定授予或拒绝访问。

我发现 pdp 核心引擎支持 MongoDB,如 here 所述。

这是我的 pdp 配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Testing parameter 'maxPolicySetRefDepth' -->
<pdp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://authzforce.github.io/core/xmlns/pdp/6.0" xmlns:ext="http://authzforce.github.io/core/xmlns/test/3" version="6.0.0">
   <refPolicyProvider id="refPolicyProvider" xsi:type="ext:MongoDBBasedPolicyProvider" serverHost="localhost" serverPort="27017" dbName="testXACML" collectionName="policies" />
   <rootPolicyProvider id="rootPolicyProvider" xsi:type="StaticRefBasedRootPolicyProvider">
      <policyRef>root-rbac-policyset</policyRef>
   </rootPolicyProvider>
</pdp>

所以现在的问题是如何存储策略 XML 文件,因为它需要使用 MongoDB 存储在 JSON 中?我尝试使用JSON maven dependency 将 XML 转换为 JSON,但在转换回 XML 时遇到了问题。例如,使用this 之类的策略 XML 文件,它将创建如下所示的 JSON 文件:

{"Policy": {
    "xmlns": "urn:oasis:names:tc:xacml:3.0:core:schema:wd-17",
    "Target": "",
    "Description": "Policy for Conformance Test IIA001.",
    "Version": 1,
    "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
    "RuleCombiningAlgId": "urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides",
    "Rule": {
        "Target": {"AnyOf": [
            {"AllOf": {"Match": {
                "AttributeValue": {
                    "DataType": "http://www.w3.org/2001/XMLSchema#string",
                    "content": "Julius Hibbert"
                },
                "AttributeDesignator": {
                    "Category": "urn:oasis:names:tc:xacml:1.0:subject-category:access-subject",
                    "AttributeId": "urn:oasis:names:tc:xacml:1.0:subject:subject-id",
                    "MustBePresent": false,
                    "DataType": "http://www.w3.org/2001/XMLSchema#string"
                },
                "MatchId": "urn:oasis:names:tc:xacml:1.0:function:string-equal"
            }}},
            {"AllOf": {"Match": {
                "AttributeValue": {
                    "DataType": "http://www.w3.org/2001/XMLSchema#anyURI",
                    "content": "http://medico.com/record/patient/BartSimpson"
                },
                "AttributeDesignator": {
                    "Category": "urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
                    "AttributeId": "urn:oasis:names:tc:xacml:1.0:resource:resource-id",
                    "MustBePresent": false,
                    "DataType": "http://www.w3.org/2001/XMLSchema#anyURI"
                },
                "MatchId": "urn:oasis:names:tc:xacml:1.0:function:anyURI-equal"
            }}},
            {"AllOf": [
                {"Match": {
                    "AttributeValue": {
                        "DataType": "http://www.w3.org/2001/XMLSchema#string",
                        "content": "read"
                    },
                    "AttributeDesignator": {
                        "Category": "urn:oasis:names:tc:xacml:3.0:attribute-category:action",
                        "AttributeId": "urn:oasis:names:tc:xacml:1.0:action:action-id",
                        "MustBePresent": false,
                        "DataType": "http://www.w3.org/2001/XMLSchema#string"
                    },
                    "MatchId": "urn:oasis:names:tc:xacml:1.0:function:string-equal"
                }},
                {"Match": {
                    "AttributeValue": {
                        "DataType": "http://www.w3.org/2001/XMLSchema#string",
                        "content": "write"
                    },
                    "AttributeDesignator": {
                        "Category": "urn:oasis:names:tc:xacml:3.0:attribute-category:action",
                        "AttributeId": "urn:oasis:names:tc:xacml:1.0:action:action-id",
                        "MustBePresent": false,
                        "DataType": "http://www.w3.org/2001/XMLSchema#string"
                    },
                    "MatchId": "urn:oasis:names:tc:xacml:1.0:function:string-equal"
                }}
            ]}
        ]},
        "Description": "Julius Hibbert can read or write Bart Simpson's medical record.",
        "RuleId": "urn:oasis:names:tc:xacml:2.0:conformance-test:IIA1:rule",
        "Effect": "Permit"
    },
    "PolicyId": "urn:oasis:names:tc:xacml:2.0:conformance-test:IIA1:policy"
}}

但是当我尝试将它转换回 XML 时,它变成了完全不同的 XML 文件。那么现在如何将 XML 文件存储在 MongoDB 中?另外如何确保 pdp 引擎核心可以找到正确的策略进行比较?我看到README中提到了json适配器,例如this,但我不确定如何正常实现。

【问题讨论】:

  • 您能接受答案吗?

标签: java json mongodb xacml3 authzforce


【解决方案1】:

我在AuthzForce's github 上回答了这个问题。简而言之,David 对格式(xml 内容存储为 JSON 字符串)的看法基本正确。更准确地说,对于 AuthzForce MongoDB 策略提供程序,您必须存储策略,如 unit test classsetupBeforeClass 方法的一部分所示,该方法使用测试策略填充数据库。您将看到我们使用 Jongo 库(在幕后使用 Jackson 对象映射)将 PolicyPOJO Java 对象映射到 Mongodb 集合中的 JSON。所以从PolicyPOJO类中,你几乎可以猜到JSON中策略的存储格式:它是一个JSON对象,具有以下字段(键值对):

  • “id”(字符串):策略(集)ID
  • “version”(字符串):策略(集)版本
  • “type”(字符串):Policy(Set) 类型,即 '{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}Policy'(分别为 '{urn:oasis :names:tc:xacml:3.0:core:schema:wd-17}PolicySet') 用于 XACML 3.0 策略(分别为 PolicySet)
  • “content”(字符串):实际 Policy(Set) 的 XML 文档为字符串(纯文本)

Java 库 (Jongo/Jackson) 自动正确转义 xml 内容以适合 JSON 字符串。但如果您使用其他库/语言,请确保也是如此。

【讨论】:

    【解决方案2】:

    目前没有适用于 XACML 策略的 JSON 格式。 OASIS XACML 技术委员会目前正在考虑这一点。沃特福德理工学院的 Bernard Butler 确实做了一些初步翻译,可能对您有价值。

    我暂时能想到的唯一其他选择是围绕策略创建一个 JSON 包装器,例如

    {
        "policy":"the xml policy contents escaped as valid json value or in base64"
    }
    

    【讨论】:

      猜你喜欢
      • 2020-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 2022-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多