GithubHelp home page GithubHelp logo

Comments (4)

ihsanhaikalz avatar ihsanhaikalz commented on August 19, 2024

Also how can I store the policy XML files as it needs to be stored in JSON with MongoDB? I tried to convert XML to JSON using JSON maven dependency, but I have a problem of converting back to XML. For example with the policy XML file like this it will create the JSON file something like this:

{"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"
}}

but when I try to convert it back to XML it becomes entirely different XML file like this:

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

So now how can I store the XML file in MongoDB? Also how to ensure that pdp engine core could find the correct policy to be compared? I saw there is a mentioned about the json adapter in README like this but I am not sure how to implement it normally.

from core.

cdanger avatar cdanger commented on August 19, 2024

Similar question on the restful-pdp project. Please check it out. Basically, in the code we use the jongo library which relies on Jackson to map the PolicyPojo class to JSON. The XML content of the policy corresponds to the PolicyPojo's content string field, therefore simply mapped to JSON string.

Quote:

At the moment, the best way to understand how to use the MongoDbRefPolicyProvider - and how policies must be set up in MongoDB for this - is to look at the corresponding test class, esp. the setupBeforeClass method. As the code shows in Java, each policy should be inserted as a PolicyPojo in the Mongo collection specified by your policy provider's configuration (pdp.xml). So if you reused the example of pdp.xml blindly, this is the collection policies in the database Test. The code shows how to create the PolicyPojo from a XACML Policy(Set) document.

from core.

cdanger avatar cdanger commented on August 19, 2024

From the PolicyPOJO class, you can pretty much guess the storage format of policies in JSON: it is a JSON object with the following fields (key-value pairs):

  • "id" (string): the Policy(Set) ID
  • "version" (string): the Policy(Set) version
  • "type" (string): the Policy(Set) type, i.e. '{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') for XACML 3.0 Policy (resp. PolicySet)
  • "content" (string): the actual Policy(Set)'s XML document as string (plain text)

The xml content is automatically escaped properly by the Java library (Jongo/Jackson) to fit in a JSON string. But if you use another library/language, make sure it is the case as well.

from core.

cdanger avatar cdanger commented on August 19, 2024

No further comment from OP for 15 days. Closing.

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.