gpt4 book ai didi

java - 使用 MongoDB for Authzforce 将 XACML 文件存储在 JSON 中

转载 作者:行者123 更新时间:2023-11-30 02:07:04 26 4
gpt4 key购买 nike

我想使用 authzforce-ce-core-pdp-engine jar 文件来实现 PDP 引擎,就像您在 README 中提到的那样,但 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但我不知道如何正常实现。

最佳答案

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

  • “id”(字符串):策略(集)ID
  • “version”(字符串):策略(集)版本
  • “type”(字符串):策略(集)类型,即 '{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”(字符串):实际策略(集)的 XML 文档作为字符串(纯文本)

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

关于java - 使用 MongoDB for Authzforce 将 XACML 文件存储在 JSON 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51061338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com