1

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

我发现 pdp 核心引擎支持这里提到的 MongoDB 。

这是我的 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 依赖项将 XML 转换为 JSON ,但在转换回 XML 时遇到问题。例如,使用这样的策略 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 引擎核心可以找到正确的策略进行比较?我看到在自述文件中提到了这样的 json 适配器,我不确定如何正常实现它。

4

2 回答 2

2

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

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

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

于 2018-07-06T22:16:55.033 回答
0

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

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

{
    "policy":"the xml policy contents escaped as valid json value or in base64"
}
于 2018-06-28T13:13:07.940 回答