Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate the XACML Request from a template #1

Open
cdanger opened this issue Feb 13, 2018 · 0 comments
Open

Generate the XACML Request from a template #1

cdanger opened this issue Feb 13, 2018 · 0 comments
Assignees
Labels
Accepted enhancement New feature or request Feature Request good first issue Good for newcomers

Comments

@cdanger
Copy link
Member

cdanger commented Feb 13, 2018

The idea is to use XACML request template to generate the actual XACML request to PDP at runtime. For each access request, the variables used in the template (e.g. user ID, user roles, action ID, resource ID) are resolved at runtime in the context of the request.
For this, you can use one of many Python template engines listed here for instance:
https://wiki.python.org/moin/Templating

For example, if you want the SDK to send XACML/JSON requests, using Jinja template engine, the app developer/admin would provide a XACML request template file looking like this:

{
	"Request":
	{
		"Category":
		[
			{
				"CategoryId": 
"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject",
				"Attribute":
				[
					{
						"AttributeId": "urn:oasis:names:tc:xacml:1.0:subject:subject-id",
						"Value": "{{ user_id }}"
					}
                                         {% if user_roles %}
                                         ,

					{
						"AttributeId": "urn:oasis:names:tc:xacml:2.0:subject:role",
						"Value":
                                                 [
                                                 {% for role in user_roles %}
                                                    "{{ role }}"
                                                    {% if not loop.last %}
                                                    ,
                                                    {% endif %}
                                                 {% endfor %}
                                                 ]
					}
                                         {% endif %}
				]
			},

			{
				"CategoryId": 
"urn:oasis:names:tc:xacml:3.0:attribute-category:action",
				"Attribute":
				[
					{
						"AttributeId": "urn:oasis:names:tc:xacml:1.0:action:action-id",
						"Value": "{{ method_name }}",
					}
				]
			},

			{
				"CategoryId": 
"urn:oasis:names:tc:xacml:3.0:attribute-category:resource",
				"Attribute":
				[
					{
						"AttributeId": 
"urn:oasis:names:tc:xacml:1.0:resource:resource-id",
						"Value": "{{ url }}"
					}
				]
			}
		]
	}
}

When using the SDK API, the developer just needs to call a method template.render( [variables] ), the input variables being in a dict, e.g. {"user_id" = "bob", "method_name" = "read", ...}.

You may find valid XACML/JSON Request samples in xacml-json-model project.

More examples of JSON templating with Python's Jinja:
http://sasheldon.com/blog/2013/12/14/simplifying-json-response-mocks-with-jinja/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted enhancement New feature or request Feature Request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants