Initial OpenECOMP policy/engine commit
[policy/engine.git] / ECOMP-XACML / src / test / java / org / openecomp / policy / xacml / test / json / RequestDefaultCategoryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-XACML
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.policy.xacml.test.json;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.fail;
25
26 import org.junit.Test;
27
28 import com.att.research.xacml.api.Request;
29 import com.att.research.xacml.std.json.JSONRequest;
30 import com.att.research.xacml.std.json.JSONStructureException;
31 /**
32  * Test JSON Request convert to object - Default Category object tests
33  * 
34  * TO RUN - use jUnit
35  * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
36  * 
37  * NOTE:
38  * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects
39  * and verify that they are correct.  This would involve a lot of coding to get child of child of child and individually verify each property of each element.
40  * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object
41  * and we compare the resulting String to our expected String.
42  * This has two possible sources of error:
43  *      - toString might not include some sub-component, and
44  *      - the initial verification of the resulting string is done by hand and may have been incorrect.
45  * 
46  *
47  */
48 public class RequestDefaultCategoryTest {
49         
50         // The request object output from each test conversion from JSON string
51         Request request;
52
53         
54         /*
55          * Request that uses all fields with both single and multiple  entries
56          */
57         String allFieldsRequest = 
58                         "{\"Request\": {" +
59                                         "\"ReturnPolicyIdList\" : true ," +
60                                         "\"CombinedDecision\" : true ," +
61                                         "\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"," +
62                                         "\"MultiRequests\" : {" +
63                                     "\"RequestReference\": [" +
64                                         "{ " +
65                                                 "\"ReferenceId\" : [\"foo1\",\"bar1\"]" +
66                                         "}," +
67                                         "{" +
68                                                 "\"ReferenceId\" : [\"foo2\",\"bar1\"]" +
69                                         "}]" +   
70                                   "}," +
71
72                                         "\"Category\": [" +
73                                                 "{ " +
74                                                 "\"CategoryId\": \"custom-category\", " +
75                                                 "\"Id\" : \"customId\", " +
76                                                 "\"Attribute\" : [" +
77                                                         "{" +
78                                                                 "\"AttributeId\"                : \"document-id\", " +
79                                                                 "\"DataType\"   : \"integer\", " +
80                                                                 "\"Value\"      : 123 " +
81                                                                 "}, " +
82                                                                 "{" +
83                                                                 "\"AttributeId\"                : \"document-url\", " +
84                                                                 "\"DataType\"   : \"anyURI\", " +
85                                                                 "\"Value\"      : \"http://somewhere.over.the.com/rainbow\" " +
86                                                         "}, " +
87                                                                 "{" +
88                                                                 "\"AttributeId\"                : \"page-list\", " +
89                                                                 "\"Value\"      : [1, 2, 3, 4.5, 3, 2, 1] " +
90                                                         "} " +
91                                                 "]" +
92                                             "}, " +
93                                             "{ " +
94                                                 "\"CategoryId\": \"another-custom-cat\", " +
95                                                 "\"Id\" : \"anotherXmlId\", " +
96                                                 "\"Attribute\" : []" +
97                                             "} " +
98                                         "], " +
99                                             
100                                         "\"AccessSubject\":{ " +
101                                                 "\"Content\" : \"<?xml version=\\\"1.0\\\"?><catalog>" + 
102                                                         "<book id=\\\"bk101\\\"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre>" +
103                                                         "<price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description>"+
104                                                         "</book></catalog>\"," +
105                                                 "\"Attribute\" : []" +
106                                         "}, " +
107                                         
108                                         "\"Resource\" : {" +
109                                                 "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" +
110                                                         "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+
111                                                         "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" +
112
113
114                                         "} " +
115
116                                   
117                         "}}";
118         
119         /*
120          * The following example comes directly from the JSON Profile Spec
121          */
122         String exampleFromSpec = "{ " +
123                         "\"Request\" : { " +
124                                 "\"AccessSubject\" : { " +
125                                         "\"Attribute\": [ " +
126                                                 "{ " +
127                                                         "\"Id\" : \"subject-id\", " +
128                                                         "\"Value\" : \"Andreas\" " +
129                                                 "}, " +
130                                                 "{ " +
131                                                         "\"Id\" : \"location\", " +
132                                                         "\"Value\" : \"Gamla Stan\" " +
133                                                 "} " +
134                                         "] " +
135                                 "}, " +
136                                 "\"Action\" : { " +
137                                         "\"Attribute\":  " +
138                                                 "{ " +
139                                                         "\"Id\" : \"action-id\", " +
140                                                         "\"Value\" : \"http://www.xacml.eu/buy\", " +
141                                                         "\"DataType\" : \"anyURI\" " +
142                                                 "} " +
143                                 "}, " +
144                                 "\"Resource\" : { " +
145                                         "\"Attribute\": [ " +
146                                                 "{ " +
147                                                         "\"Id\" : \"book-title\", " +
148                                                         "\"Value\" : \"Learn German in 90 days\" " +
149                                                 "}, " +
150                                                 "{ " +
151                                                         "\"Id\" : \"currency\", " +
152                                                         "\"Value\" : \"SEK\" " +
153                                                 "}, " +
154                                                 "{ " +
155                                                         "\"Id\" : \"price\", " +
156                                                         "\"Value\" : 123.34 " +
157                                                 "} " +
158                                                 "] " +
159                                         "} " +
160                                 "} " +
161                         "} ";
162
163         
164         /*
165          * The following example comes directly from the JSON Profile Spec (modified to include a "</Catalog>" missing from both examples).
166          * It shows the two ways of handling XPath content, as escaped XML and as Base64 encoding.
167          */
168         String xPathExampleFromSpec = "{ " +
169                         "\"Request\" : { " +
170                                 "\"Resource\" : { " +
171                                         "\"Attribute\": [ " +
172                                                 "{ " +
173                                                         "\"Id\" : \"urn:oasis:names:tc:xacml:3.0:content-selector\", " +
174                                             "\"DataType\" : \"xpathExpression\", " +
175                                             "\"Value\" : { " +
176                                                 "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", " +
177                                                 "\"Namespaces\" : [{ " +
178                                                         "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " +
179                                                         "}, " +
180                                                     "{ " +
181                                                         "\"Prefix\" : \"md\", " +
182                                                         "\"Namespace\" : \"urn:example:med:schemas:record\" " +
183                                                     "} " +
184                                                 "], " +
185                                                 "\"XPath\" : \"md:record/md:patient/md:patientDoB\" " +
186                                             "} " +
187                                         "} " +
188                                         "] " +
189                                 "} " +
190                         "} " +
191                 "} ";
192
193         
194         // test Shorthand Category notation for elements not tested in their own section below.
195         // Categories that are more commonly used are fully tested. 
196         // Given that the functions within the categories are the same irrespective of the name of the category, 
197         // we assume that the contents of the category will work ok once the Shorthand notation is recognized, so all we need to test is the shorthand
198         // The ones that are tested in their own sections are:
199         //              AccessSubject
200         //              Action
201         //              Resource
202         //              Environment 
203         // test Subject
204         @Test
205         public void testCategoryShorthand() {
206         
207                 // RecipientSubject present both as element within Category and as separate RecipientSubject element at same level as Category
208                 try {
209                         request = JSONRequest.load("{\"Request\" : {"
210                                         + "\"Category\": ["
211                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject\", \"Attribute\" : [{" +
212                                                 "\"Id\" : \"document-id\", " +
213                                                 "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
214                                                 "}] }, "
215                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject\", \"Attribute\" : [{" +
216                                                 "\"Id\" : \"document-id\", " +
217                                                 "\"Value\"      : \"aValue\"" +
218                                                 "}] } "
219                                                 + "]," +
220                                         "\"RecipientSubject\" : { " +
221                                                 "\"Attribute\": [ " +
222                                                         "{ " +
223                                                                 "\"Id\" : \"subject-id\", " +
224                                                                 "\"Value\" : \"Andreas\" " +
225                                                         "}, " +
226                                                         "{ " +
227                                                                 "\"Id\" : \"location\", " +
228                                                                 "\"Value\" : \"Gamla Stan\" " +
229                                                         "} " +
230                                                 "] " +
231                                         "} " 
232                                 + " }}");
233                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
234                 } catch (Exception e) {
235                         fail ("Failed convert from JSON to object: " + e);
236                 }
237                 
238                 
239                 // IntermediarySubject present both as element within Category and as separate IntermediarySubject element at same level as Category
240                 try {
241                         request = JSONRequest.load("{\"Request\" : {"
242                                         + "\"Category\": ["
243                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\", \"Attribute\" : [{" +
244                                                 "\"Id\" : \"document-id\", " +
245                                                 "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
246                                                 "}] }, "
247                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\", \"Attribute\" : [{" +
248                                                 "\"Id\" : \"document-id\", " +
249                                                 "\"Value\"      : \"aValue\"" +
250                                                 "}] } "
251                                                 + "]," +
252                                         "\"IntermediarySubject\" : { " +
253                                                 "\"Attribute\": [ " +
254                                                         "{ " +
255                                                                 "\"Id\" : \"subject-id\", " +
256                                                                 "\"Value\" : \"Andreas\" " +
257                                                         "}, " +
258                                                         "{ " +
259                                                                 "\"Id\" : \"location\", " +
260                                                                 "\"Value\" : \"Gamla Stan\" " +
261                                                         "} " +
262                                                 "] " +
263                                         "} " 
264                                 + " }}");
265                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
266                 } catch (Exception e) {
267                         fail ("Failed convert from JSON to object: " + e);
268                 }
269                 
270                 
271                 // Codebase present both as element within Category and as separate Codebase element at same level as Category
272                 try {
273                         request = JSONRequest.load("{\"Request\" : {"
274                                         + "\"Category\": ["
275                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:codebase\", \"Attribute\" : [{" +
276                                                 "\"Id\" : \"document-id\", " +
277                                                 "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
278                                                 "}] }, "
279                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:codebase\", \"Attribute\" : [{" +
280                                                 "\"Id\" : \"document-id\", " +
281                                                 "\"Value\"      : \"aValue\"" +
282                                                 "}] } "
283                                                 + "]," +
284                                         "\"Codebase\" : { " +
285                                                 "\"Attribute\": [ " +
286                                                         "{ " +
287                                                                 "\"Id\" : \"subject-id\", " +
288                                                                 "\"Value\" : \"Andreas\" " +
289                                                         "}, " +
290                                                         "{ " +
291                                                                 "\"Id\" : \"location\", " +
292                                                                 "\"Value\" : \"Gamla Stan\" " +
293                                                         "} " +
294                                                 "] " +
295                                         "} " 
296                                 + " }}");
297                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
298                 } catch (Exception e) {
299                         fail ("Failed convert from JSON to object: " + e);
300                 }
301                 
302                 
303                 
304                 // RequestingMachine present both as element within Category and as separate RequestingMachine element at same level as Category
305                 try {
306                         request = JSONRequest.load("{\"Request\" : {"
307                                         + "\"Category\": ["
308                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine\", \"Attribute\" : [{" +
309                                                 "\"Id\" : \"document-id\", " +
310                                                 "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
311                                                 "}] }, "
312                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine\", \"Attribute\" : [{" +
313                                                 "\"Id\" : \"document-id\", " +
314                                                 "\"Value\"      : \"aValue\"" +
315                                                 "}] } "
316                                                 + "]," +
317                                         "\"RequestingMachine\" : { " +
318                                                 "\"Attribute\": [ " +
319                                                         "{ " +
320                                                                 "\"Id\" : \"subject-id\", " +
321                                                                 "\"Value\" : \"Andreas\" " +
322                                                         "}, " +
323                                                         "{ " +
324                                                                 "\"Id\" : \"location\", " +
325                                                                 "\"Value\" : \"Gamla Stan\" " +
326                                                         "} " +
327                                                 "] " +
328                                         "} " 
329                                 + " }}");
330                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
331                 } catch (Exception e) {
332                         fail ("Failed convert from JSON to object: " + e);
333                 }
334         }
335
336
337
338
339
340         
341
342
343         
344
345
346         
347         
348         
349         
350         
351         // test AccessSubject
352         // Include test for backward compatibility with "Subject"
353         @Test
354         public void testAccessSubjectRequest() {
355                 
356                 // AccessSubject absent
357                 try {
358                         request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" +
359                                 "\"Id\" : \"document-id\", " +
360                                 "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
361                                         "}] } ] }}");
362                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString());
363                 } catch (Exception e) {
364                         fail ("Failed convert from JSON to object: " + e);
365                 }
366                 
367                 // AccessSubject as normal element under Category (with CategoryId==subject category id)
368                 try {
369                         request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" +
370                                 "\"Id\" : \"document-id\", " +
371                                 "\"Value\"      : \"aValue\" " +
372                                         "}] } ] }}");
373                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString());
374                 } catch (Exception e) {
375                         fail ("Failed convert from JSON to object: " + e);
376                 }
377                 
378                 // multiple AccessSubjects under Category
379                 try {
380                         request = JSONRequest.load("{\"Request\" : {\"Category\": ["
381                                         + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" +
382                                         "\"Id\" : \"document-id\", " +
383                                         "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
384                                         "}] }, "
385                                         + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" +
386                                         "\"Id\" : \"document-id\", " +
387                                         "\"Value\"      : \"aValue\"" +
388                                         "}] } "
389                                         + "] }}");
390                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString());
391                 } catch (Exception e) {
392                         fail ("Failed convert from JSON to object: " + e);
393                 }
394                 
395                 // AccessSubject present both as element within Category and as separate AccessSubject element at same level as Category
396                 try {
397                         request = JSONRequest.load("{\"Request\" : {"
398                                         + "\"Category\": ["
399                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" +
400                                                 "\"Id\" : \"document-id\", " +
401                                                 "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
402                                                 "}] }, "
403                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" +
404                                                 "\"Id\" : \"document-id\", " +
405                                                 "\"Value\"      : \"aValue\"" +
406                                                 "}] } "
407                                                 + "]," +
408                                         "\"AccessSubject\" : { " +
409                                                 "\"Attribute\": [ " +
410                                                         "{ " +
411                                                                 "\"Id\" : \"subject-id\", " +
412                                                                 "\"Value\" : \"Andreas\" " +
413                                                         "}, " +
414                                                         "{ " +
415                                                                 "\"Id\" : \"location\", " +
416                                                                 "\"Value\" : \"Gamla Stan\" " +
417                                                         "} " +
418                                                 "] " +
419                                         "} " 
420                                 + " }}");
421                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
422                 } catch (Exception e) {
423                         fail ("Failed convert from JSON to object: " + e);
424                 }
425                 
426                 // AccessSubject present, no other Category element
427                 try {
428                         request = JSONRequest.load("{\"Request\" : {"
429                                         + 
430                                         "\"AccessSubject\" : { " +
431                                                 "\"Attribute\": [ " +
432                                                         "{ " +
433                                                                 "\"Id\" : \"subject-id\", " +
434                                                                 "\"Value\" : \"Andreas\" " +
435                                                         "}, " +
436                                                         "{ " +
437                                                                 "\"Id\" : \"location\", " +
438                                                                 "\"Value\" : \"Gamla Stan\" " +
439                                                         "} " +
440                                                 "] " +
441                                         "} " 
442                                 + " }}");
443                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
444                 } catch (Exception e) {
445                         fail ("Failed convert from JSON to object: " + e);
446                 }
447                 
448                 
449                 // Subject present, no other Category element (Backward Compatibility
450                 try {
451                         request = JSONRequest.load("{\"Request\" : {"
452                                         + 
453                                         "\"Subject\" : { " +
454                                                 "\"Attribute\": [ " +
455                                                         "{ " +
456                                                                 "\"Id\" : \"subject-id\", " +
457                                                                 "\"Value\" : \"Andreas\" " +
458                                                         "}, " +
459                                                         "{ " +
460                                                                 "\"Id\" : \"location\", " +
461                                                                 "\"Value\" : \"Gamla Stan\" " +
462                                                         "} " +
463                                                 "] " +
464                                         "} " 
465                                 + " }}");
466                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
467                 } catch (Exception e) {
468                         fail ("Failed convert from JSON to object: " + e);
469                 }
470                 
471                 // AccessSubject present, 1/multiple other Category element also present
472                 try {
473                         request = JSONRequest.load("{\"Request\" : {"
474                                         + "\"Category\": ["
475                                                 + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" +
476                                                 "\"Id\" : \"document-id\", " +
477                                                 "\"Value\"      : \"aValue\"" +
478                                                 "}] } "
479                                                 + "]," +
480                                         "\"AccessSubject\" : { " +
481                                                 "\"Attribute\": [ " +
482                                                         "{ " +
483                                                                 "\"Id\" : \"subject-id\", " +
484                                                                 "\"Value\" : \"Andreas\" " +
485                                                         "}, " +
486                                                         "{ " +
487                                                                 "\"Id\" : \"location\", " +
488                                                                 "\"Value\" : \"Gamla Stan\" " +
489                                                         "} " +
490                                                 "] " +
491                                         "} " 
492                                 + " }}");
493                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
494                 } catch (Exception e) {
495                         fail ("Failed convert from JSON to object: " + e);
496                 }
497                 
498                 // 2 AccessSubjects - duplicates fail
499                 try {
500                         request = JSONRequest.load("{\"Request\" : {"
501                                         + 
502                                         "\"AccessSubject\" : { " +
503                                                 "\"Attribute\": [ " +
504                                                         "{ " +
505                                                                 "\"Id\" : \"subject-id\", " +
506                                                                 "\"Value\" : \"Andreas\" " +
507                                                         "}, " +
508                                                         "{ " +
509                                                                 "\"Id\" : \"location\", " +
510                                                                 "\"Value\" : \"Gamla Stan\" " +
511                                                         "} " +
512                                                 "] " +
513                                         "} " 
514                                         + 
515                                         "\"AccessSubject\" : { " +
516                                                 "\"Attribute\": [ " +
517                                                         "{ " +
518                                                                 "\"Id\" : \"subject-id\", " +
519                                                                 "\"Value\" : \"Andreas\" " +
520                                                         "}, " +
521                                                         "{ " +
522                                                                 "\"Id\" : \"location\", " +
523                                                                 "\"Value\" : \"Gamla Stan\" " +
524                                                         "} " +
525                                                 "] " +
526                                         "} " 
527                                 + " }}");
528                         fail("Operation should throw exception");
529                 } catch (JSONStructureException e) {
530                         // correct response
531                 } catch (Exception e) {
532                         fail ("Failed convert from JSON to object: " + e);
533                 }
534                 
535                 // AccessSubject with correct Category value
536                 try {
537                         request = JSONRequest.load("{\"Request\" : {"
538                                         + 
539                                         "\"AccessSubject\" : { " +
540                                                 "\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\" ," +
541                                                 "\"Attribute\": [ " +
542                                                         "{ " +
543                                                                 "\"Id\" : \"subject-id\", " +
544                                                                 "\"Value\" : \"Andreas\" " +
545                                                         "}, " +
546                                                         "{ " +
547                                                                 "\"Id\" : \"location\", " +
548                                                                 "\"Value\" : \"Gamla Stan\" " +
549                                                         "} " +
550                                                 "] " +
551                                         "} " 
552                                 + " }}");
553                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
554                 } catch (Exception e) {
555                         fail ("Failed convert from JSON to object: " + e);
556                 }
557                 
558                 // AccessSubject with wrong Category value
559                 try {
560                         request = JSONRequest.load("{\"Request\" : {"
561                                         + 
562                                         "\"AccessSubject\" : { " +
563                                                 "\"CategoryId\" : \"notthesubject\" ," +
564                                                 "\"Attribute\": [ " +
565                                                         "{ " +
566                                                                 "\"Id\" : \"subject-id\", " +
567                                                                 "\"Value\" : \"Andreas\" " +
568                                                         "}, " +
569                                                         "{ " +
570                                                                 "\"Id\" : \"location\", " +
571                                                                 "\"Value\" : \"Gamla Stan\" " +
572                                                         "} " +
573                                                 "] " +
574                                         "} " 
575                                 + " }}");
576                         fail("Operation should throw exception");
577                 } catch (JSONStructureException e) {
578                         // correct response
579                 } catch (Exception e) {
580                         fail ("Failed convert from JSON to object: " + e);
581                 }
582                 
583                 // AccessSubject with array of sub-object AccessSubjects (Multi Decision)
584                 try {
585                         request = JSONRequest.load("{\"Request\" : {"
586                                         + 
587                                         "\"AccessSubject\" : ["
588                                         + "{ " +
589                                                 "\"Attribute\": [ " +
590                                                         "{ " +
591                                                                 "\"Id\" : \"subject-id\", " +
592                                                                 "\"Value\" : \"Andreas\" " +
593                                                         "}, " +
594                                                         "{ " +
595                                                                 "\"Id\" : \"location\", " +
596                                                                 "\"Value\" : \"Gamla Stan\" " +
597                                                         "} " +
598                                                 "] " +
599                                         "}, "
600                                         + "{ " +
601                                         "\"Attribute\": [ " +
602                                                 "{ " +
603                                                         "\"Id\" : \"subject-id\", " +
604                                                         "\"Value\" : \"Arless\" " +
605                                                 "}, " +
606                                                 "{ " +
607                                                         "\"Id\" : \"location\", " +
608                                                         "\"Value\" : \"Somewhere\" " +
609                                                 "} " +
610                                         "] " +
611                                         "}, "
612                                         + "{ " +
613                                         "\"Attribute\": [ " +
614                                                 "{ " +
615                                                         "\"Id\" : \"subject-id\", " +
616                                                         "\"Value\" : \"Barry\" " +
617                                                 "}, " +
618                                                 "{ " +
619                                                         "\"Id\" : \"location\", " +
620                                                         "\"Value\" : \"Elsewhere\" " +
621                                                 "} " +
622                                         "] " +
623                                         "} "
624                                 + "]"
625                                 + " }}");
626                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString());
627                 } catch (Exception e) {
628                         fail ("Failed convert from JSON to object: " + e);
629                 }
630
631         }
632         
633         
634         
635         
636         
637         
638         
639         
640         
641         // Action ... duplicate all AccessSubject tests...
642         // test Action
643         @Test
644         public void testActionRequest() {
645                 
646                 // Action absent
647                 try {
648                         request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" +
649                                 "\"Id\" : \"document-id\", " +
650                                 "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
651                                         "}] } ] }}");
652                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString());
653                 } catch (Exception e) {
654                         fail ("Failed convert from JSON to object: " + e);
655                 }
656                 
657                 // Action as normal element under Category (with CategoryId==subject category id)
658                 try {
659                         request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
660                                 "\"Id\" : \"document-id\", " +
661                                 "\"Value\"      : \"aValue\" " +
662                                         "}] } ] }}");
663                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString());
664                 } catch (Exception e) {
665                         fail ("Failed convert from JSON to object: " + e);
666                 }
667                 
668                 // multiple Actions under Category
669                 try {
670                         request = JSONRequest.load("{\"Request\" : {\"Category\": ["
671                                         + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
672                                         "\"Id\" : \"document-id\", " +
673                                         "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
674                                         "}] }, "
675                                         + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
676                                         "\"Id\" : \"document-id\", " +
677                                         "\"Value\"      : \"aValue\"" +
678                                         "}] } "
679                                         + "] }}");
680                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString());
681                 } catch (Exception e) {
682                         fail ("Failed convert from JSON to object: " + e);
683                 }
684                 
685                 // Action present both as element within Category and as separate Action element at same level as Category
686                 try {
687                         request = JSONRequest.load("{\"Request\" : {"
688                                         + "\"Category\": ["
689                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
690                                                 "\"Id\" : \"document-id\", " +
691                                                 "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
692                                                 "}] }, "
693                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
694                                                 "\"Id\" : \"document-id\", " +
695                                                 "\"Value\"      : \"aValue\"" +
696                                                 "}] } "
697                                                 + "]," +
698                                         "\"Action\" : { " +
699                                                 "\"Attribute\": [ " +
700                                                         "{ " +
701                                                                 "\"Id\" : \"subject-id\", " +
702                                                                 "\"Value\" : \"Andreas\" " +
703                                                         "}, " +
704                                                         "{ " +
705                                                                 "\"Id\" : \"location\", " +
706                                                                 "\"Value\" : \"Gamla Stan\" " +
707                                                         "} " +
708                                                 "] " +
709                                         "} " 
710                                 + " }}");
711                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
712                 } catch (Exception e) {
713                         fail ("Failed convert from JSON to object: " + e);
714                 }
715                 
716                 // Action present, no other Category element
717                 try {
718                         request = JSONRequest.load("{\"Request\" : {"
719                                         + 
720                                         "\"Action\" : { " +
721                                                 "\"Attribute\": [ " +
722                                                         "{ " +
723                                                                 "\"Id\" : \"subject-id\", " +
724                                                                 "\"Value\" : \"Andreas\" " +
725                                                         "}, " +
726                                                         "{ " +
727                                                                 "\"Id\" : \"location\", " +
728                                                                 "\"Value\" : \"Gamla Stan\" " +
729                                                         "} " +
730                                                 "] " +
731                                         "} " 
732                                 + " }}");
733                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
734                 } catch (Exception e) {
735                         fail ("Failed convert from JSON to object: " + e);
736                 }
737                 
738                 // Action present, 1/multiple other Category element also present
739                 try {
740                         request = JSONRequest.load("{\"Request\" : {"
741                                         + "\"Category\": ["
742                                                 + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" +
743                                                 "\"Id\" : \"document-id\", " +
744                                                 "\"Value\"      : \"aValue\"" +
745                                                 "}] } "
746                                                 + "]," +
747                                         "\"Action\" : { " +
748                                                 "\"Attribute\": [ " +
749                                                         "{ " +
750                                                                 "\"Id\" : \"subject-id\", " +
751                                                                 "\"Value\" : \"Andreas\" " +
752                                                         "}, " +
753                                                         "{ " +
754                                                                 "\"Id\" : \"location\", " +
755                                                                 "\"Value\" : \"Gamla Stan\" " +
756                                                         "} " +
757                                                 "] " +
758                                         "} " 
759                                 + " }}");
760                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
761                 } catch (Exception e) {
762                         fail ("Failed convert from JSON to object: " + e);
763                 }
764                 
765                 // 2 Actions - duplicates fail
766                 try {
767                         request = JSONRequest.load("{\"Request\" : {"
768                                         + 
769                                         "\"Action\" : { " +
770                                                 "\"Attribute\": [ " +
771                                                         "{ " +
772                                                                 "\"Id\" : \"subject-id\", " +
773                                                                 "\"Value\" : \"Andreas\" " +
774                                                         "}, " +
775                                                         "{ " +
776                                                                 "\"Id\" : \"location\", " +
777                                                                 "\"Value\" : \"Gamla Stan\" " +
778                                                         "} " +
779                                                 "] " +
780                                         "} " 
781                                         + 
782                                         "\"Action\" : { " +
783                                                 "\"Attribute\": [ " +
784                                                         "{ " +
785                                                                 "\"Id\" : \"subject-id\", " +
786                                                                 "\"Value\" : \"Andreas\" " +
787                                                         "}, " +
788                                                         "{ " +
789                                                                 "\"Id\" : \"location\", " +
790                                                                 "\"Value\" : \"Gamla Stan\" " +
791                                                         "} " +
792                                                 "] " +
793                                         "} " 
794                                 + " }}");
795                         fail("Operation should throw exception");
796                 } catch (JSONStructureException e) {
797                         // correct response
798                 } catch (Exception e) {
799                         fail ("Failed convert from JSON to object: " + e);
800                 }
801                 
802                 // Action with correct Category value
803                 try {
804                         request = JSONRequest.load("{\"Request\" : {"
805                                         + 
806                                         "\"Action\" : { " +
807                                                 "\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:action\" ," +
808                                                 "\"Attribute\": [ " +
809                                                         "{ " +
810                                                                 "\"Id\" : \"subject-id\", " +
811                                                                 "\"Value\" : \"Andreas\" " +
812                                                         "}, " +
813                                                         "{ " +
814                                                                 "\"Id\" : \"location\", " +
815                                                                 "\"Value\" : \"Gamla Stan\" " +
816                                                         "} " +
817                                                 "] " +
818                                         "} " 
819                                 + " }}");
820                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
821                 } catch (Exception e) {
822                         fail ("Failed convert from JSON to object: " + e);
823                 }
824                 
825                 // Action with wrong Category value
826                 try {
827                         request = JSONRequest.load("{\"Request\" : {"
828                                         + 
829                                         "\"Action\" : { " +
830                                                 "\"CategoryId\" : \"notthesubject\" ," +
831                                                 "\"Attribute\": [ " +
832                                                         "{ " +
833                                                                 "\"Id\" : \"subject-id\", " +
834                                                                 "\"Value\" : \"Andreas\" " +
835                                                         "}, " +
836                                                         "{ " +
837                                                                 "\"Id\" : \"location\", " +
838                                                                 "\"Value\" : \"Gamla Stan\" " +
839                                                         "} " +
840                                                 "] " +
841                                         "} " 
842                                 + " }}");
843                         fail("Operation should throw exception");
844                 } catch (JSONStructureException e) {
845                         // correct response
846                 } catch (Exception e) {
847                         fail ("Failed convert from JSON to object: " + e);
848                 }
849                 
850                 // Action with array of sub-object Actions (Multi Decision)
851                 try {
852                         request = JSONRequest.load("{\"Request\" : {"
853                                         + 
854                                         "\"Action\" : ["
855                                         + "{ " +
856                                                 "\"Attribute\": [ " +
857                                                         "{ " +
858                                                                 "\"Id\" : \"subject-id\", " +
859                                                                 "\"Value\" : \"Andreas\" " +
860                                                         "}, " +
861                                                         "{ " +
862                                                                 "\"Id\" : \"location\", " +
863                                                                 "\"Value\" : \"Gamla Stan\" " +
864                                                         "} " +
865                                                 "] " +
866                                         "}, "
867                                         + "{ " +
868                                         "\"Attribute\": [ " +
869                                                 "{ " +
870                                                         "\"Id\" : \"subject-id\", " +
871                                                         "\"Value\" : \"Arless\" " +
872                                                 "}, " +
873                                                 "{ " +
874                                                         "\"Id\" : \"location\", " +
875                                                         "\"Value\" : \"Somewhere\" " +
876                                                 "} " +
877                                         "] " +
878                                         "}, "
879                                         + "{ " +
880                                         "\"Attribute\": [ " +
881                                                 "{ " +
882                                                         "\"Id\" : \"subject-id\", " +
883                                                         "\"Value\" : \"Barry\" " +
884                                                 "}, " +
885                                                 "{ " +
886                                                         "\"Id\" : \"location\", " +
887                                                         "\"Value\" : \"Elsewhere\" " +
888                                                 "} " +
889                                         "] " +
890                                         "} "
891                                 + "]"
892                                 + " }}");
893                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString());
894                 } catch (Exception e) {
895                         fail ("Failed convert from JSON to object: " + e);
896                 }
897
898         }
899         
900         
901         
902         
903         // Resource ... duplicate all AccessSubject tests...
904         // test Resource
905         @Test
906         public void testResourceRequest() {
907                 
908                 // Resource absent
909                 try {
910                         request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" +
911                                 "\"Id\" : \"document-id\", " +
912                                 "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
913                                         "}] } ] }}");
914                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString());
915                 } catch (Exception e) {
916                         fail ("Failed convert from JSON to object: " + e);
917                 }
918                 
919                 // Resource as normal element under Category (with CategoryId==subject category id)
920                 try {
921                         request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
922                                 "\"Id\" : \"document-id\", " +
923                                 "\"Value\"      : \"aValue\" " +
924                                         "}] } ] }}");
925                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString());
926                 } catch (Exception e) {
927                         fail ("Failed convert from JSON to object: " + e);
928                 }
929                 
930                 // multiple Resources under Category
931                 try {
932                         request = JSONRequest.load("{\"Request\" : {\"Category\": ["
933                                         + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
934                                         "\"Id\" : \"document-id\", " +
935                                         "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
936                                         "}] }, "
937                                         + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
938                                         "\"Id\" : \"document-id\", " +
939                                         "\"Value\"      : \"aValue\"" +
940                                         "}] } "
941                                         + "] }}");
942                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString());
943                 } catch (Exception e) {
944                         fail ("Failed convert from JSON to object: " + e);
945                 }
946                 
947                 // Resource present both as element within Category and as separate Resource element at same level as Category
948                 try {
949                         request = JSONRequest.load("{\"Request\" : {"
950                                         + "\"Category\": ["
951                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
952                                                 "\"Id\" : \"document-id\", " +
953                                                 "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
954                                                 "}] }, "
955                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
956                                                 "\"Id\" : \"document-id\", " +
957                                                 "\"Value\"      : \"aValue\"" +
958                                                 "}] } "
959                                                 + "]," +
960                                         "\"Resource\" : { " +
961                                                 "\"Attribute\": [ " +
962                                                         "{ " +
963                                                                 "\"Id\" : \"subject-id\", " +
964                                                                 "\"Value\" : \"Andreas\" " +
965                                                         "}, " +
966                                                         "{ " +
967                                                                 "\"Id\" : \"location\", " +
968                                                                 "\"Value\" : \"Gamla Stan\" " +
969                                                         "} " +
970                                                 "] " +
971                                         "} " 
972                                 + " }}");
973                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
974                 } catch (Exception e) {
975                         fail ("Failed convert from JSON to object: " + e);
976                 }
977                 
978                 // Resource present, no other Category element
979                 try {
980                         request = JSONRequest.load("{\"Request\" : {"
981                                         + 
982                                         "\"Resource\" : { " +
983                                                 "\"Attribute\": [ " +
984                                                         "{ " +
985                                                                 "\"Id\" : \"subject-id\", " +
986                                                                 "\"Value\" : \"Andreas\" " +
987                                                         "}, " +
988                                                         "{ " +
989                                                                 "\"Id\" : \"location\", " +
990                                                                 "\"Value\" : \"Gamla Stan\" " +
991                                                         "} " +
992                                                 "] " +
993                                         "} " 
994                                 + " }}");
995                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
996                 } catch (Exception e) {
997                         fail ("Failed convert from JSON to object: " + e);
998                 }
999                 
1000                 // Resource present, 1/multiple other Category element also present
1001                 try {
1002                         request = JSONRequest.load("{\"Request\" : {"
1003                                         + "\"Category\": ["
1004                                                 + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" +
1005                                                 "\"Id\" : \"document-id\", " +
1006                                                 "\"Value\"      : \"aValue\"" +
1007                                                 "}] } "
1008                                                 + "]," +
1009                                         "\"Resource\" : { " +
1010                                                 "\"Attribute\": [ " +
1011                                                         "{ " +
1012                                                                 "\"Id\" : \"subject-id\", " +
1013                                                                 "\"Value\" : \"Andreas\" " +
1014                                                         "}, " +
1015                                                         "{ " +
1016                                                                 "\"Id\" : \"location\", " +
1017                                                                 "\"Value\" : \"Gamla Stan\" " +
1018                                                         "} " +
1019                                                 "] " +
1020                                         "} " 
1021                                 + " }}");
1022                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
1023                 } catch (Exception e) {
1024                         fail ("Failed convert from JSON to object: " + e);
1025                 }
1026                 
1027                 // 2 Resources - duplicates fail
1028                 try {
1029                         request = JSONRequest.load("{\"Request\" : {"
1030                                         + 
1031                                         "\"Resource\" : { " +
1032                                                 "\"Attribute\": [ " +
1033                                                         "{ " +
1034                                                                 "\"Id\" : \"subject-id\", " +
1035                                                                 "\"Value\" : \"Andreas\" " +
1036                                                         "}, " +
1037                                                         "{ " +
1038                                                                 "\"Id\" : \"location\", " +
1039                                                                 "\"Value\" : \"Gamla Stan\" " +
1040                                                         "} " +
1041                                                 "] " +
1042                                         "} " 
1043                                         + 
1044                                         "\"Resource\" : { " +
1045                                                 "\"Attribute\": [ " +
1046                                                         "{ " +
1047                                                                 "\"Id\" : \"subject-id\", " +
1048                                                                 "\"Value\" : \"Andreas\" " +
1049                                                         "}, " +
1050                                                         "{ " +
1051                                                                 "\"Id\" : \"location\", " +
1052                                                                 "\"Value\" : \"Gamla Stan\" " +
1053                                                         "} " +
1054                                                 "] " +
1055                                         "} " 
1056                                 + " }}");
1057                         fail("Operation should throw exception");
1058                 } catch (JSONStructureException e) {
1059                         // correct response
1060                 } catch (Exception e) {
1061                         fail ("Failed convert from JSON to object: " + e);
1062                 }
1063                 
1064                 // Resource with correct Category value
1065                 try {
1066                         request = JSONRequest.load("{\"Request\" : {"
1067                                         + 
1068                                         "\"Resource\" : { " +
1069                                                 "\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\" ," +
1070                                                 "\"Attribute\": [ " +
1071                                                         "{ " +
1072                                                                 "\"Id\" : \"subject-id\", " +
1073                                                                 "\"Value\" : \"Andreas\" " +
1074                                                         "}, " +
1075                                                         "{ " +
1076                                                                 "\"Id\" : \"location\", " +
1077                                                                 "\"Value\" : \"Gamla Stan\" " +
1078                                                         "} " +
1079                                                 "] " +
1080                                         "} " 
1081                                 + " }}");
1082                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
1083                 } catch (Exception e) {
1084                         fail ("Failed convert from JSON to object: " + e);
1085                 }
1086                 
1087                 // Resource with wrong Category value
1088                 try {
1089                         request = JSONRequest.load("{\"Request\" : {"
1090                                         + 
1091                                         "\"Resource\" : { " +
1092                                                 "\"CategoryId\" : \"notthesubject\" ," +
1093                                                 "\"Attribute\": [ " +
1094                                                         "{ " +
1095                                                                 "\"Id\" : \"subject-id\", " +
1096                                                                 "\"Value\" : \"Andreas\" " +
1097                                                         "}, " +
1098                                                         "{ " +
1099                                                                 "\"Id\" : \"location\", " +
1100                                                                 "\"Value\" : \"Gamla Stan\" " +
1101                                                         "} " +
1102                                                 "] " +
1103                                         "} " 
1104                                 + " }}");
1105                         fail("Operation should throw exception");
1106                 } catch (JSONStructureException e) {
1107                         // correct response
1108                 } catch (Exception e) {
1109                         fail ("Failed convert from JSON to object: " + e);
1110                 }
1111                 
1112                 // Resource with array of sub-object Resources (Multi Decision)
1113                 try {
1114                         request = JSONRequest.load("{\"Request\" : {"
1115                                         + 
1116                                         "\"Resource\" : ["
1117                                         + "{ " +
1118                                                 "\"Attribute\": [ " +
1119                                                         "{ " +
1120                                                                 "\"Id\" : \"subject-id\", " +
1121                                                                 "\"Value\" : \"Andreas\" " +
1122                                                         "}, " +
1123                                                         "{ " +
1124                                                                 "\"Id\" : \"location\", " +
1125                                                                 "\"Value\" : \"Gamla Stan\" " +
1126                                                         "} " +
1127                                                 "] " +
1128                                         "}, "
1129                                         + "{ " +
1130                                         "\"Attribute\": [ " +
1131                                                 "{ " +
1132                                                         "\"Id\" : \"subject-id\", " +
1133                                                         "\"Value\" : \"Arless\" " +
1134                                                 "}, " +
1135                                                 "{ " +
1136                                                         "\"Id\" : \"location\", " +
1137                                                         "\"Value\" : \"Somewhere\" " +
1138                                                 "} " +
1139                                         "] " +
1140                                         "}, "
1141                                         + "{ " +
1142                                         "\"Attribute\": [ " +
1143                                                 "{ " +
1144                                                         "\"Id\" : \"subject-id\", " +
1145                                                         "\"Value\" : \"Barry\" " +
1146                                                 "}, " +
1147                                                 "{ " +
1148                                                         "\"Id\" : \"location\", " +
1149                                                         "\"Value\" : \"Elsewhere\" " +
1150                                                 "} " +
1151                                         "] " +
1152                                         "} "
1153                                 + "]"
1154                                 + " }}");
1155                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString());
1156                 } catch (Exception e) {
1157                         fail ("Failed convert from JSON to object: " + e);
1158                 }
1159
1160         }
1161         
1162         
1163         
1164         
1165         
1166         
1167         // Environment ... duplicate all AccessSubject tests ...
1168         // test Environment
1169         @Test
1170         public void testEnvironmentRequest() {
1171                 
1172                 // Environment absent
1173                 try {
1174                         request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" +
1175                                 "\"Id\" : \"document-id\", " +
1176                                 "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
1177                                         "}] } ] }}");
1178                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString());
1179                 } catch (Exception e) {
1180                         fail ("Failed convert from JSON to object: " + e);
1181                 }
1182                 
1183                 // Environment as normal element under Category (with CategoryId==subject category id)
1184                 try {
1185                         request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
1186                                 "\"Id\" : \"document-id\", " +
1187                                 "\"Value\"      : \"aValue\" " +
1188                                         "}] } ] }}");
1189                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString());
1190                 } catch (Exception e) {
1191                         fail ("Failed convert from JSON to object: " + e);
1192                 }
1193                 
1194                 // multiple Environments under Category
1195                 try {
1196                         request = JSONRequest.load("{\"Request\" : {\"Category\": ["
1197                                         + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
1198                                         "\"Id\" : \"document-id\", " +
1199                                         "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
1200                                         "}] }, "
1201                                         + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
1202                                         "\"Id\" : \"document-id\", " +
1203                                         "\"Value\"      : \"aValue\"" +
1204                                         "}] } "
1205                                         + "] }}");
1206                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString());
1207                 } catch (Exception e) {
1208                         fail ("Failed convert from JSON to object: " + e);
1209                 }
1210                 
1211                 // Environment present both as element within Category and as separate Environment element at same level as Category
1212                 try {
1213                         request = JSONRequest.load("{\"Request\" : {"
1214                                         + "\"Category\": ["
1215                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
1216                                                 "\"Id\" : \"document-id\", " +
1217                                                 "\"Value\"      : [ \"aValue\", \"aValue\", \"aValue\" ] " +
1218                                                 "}] }, "
1219                                                 + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" +
1220                                                 "\"Id\" : \"document-id\", " +
1221                                                 "\"Value\"      : \"aValue\"" +
1222                                                 "}] } "
1223                                                 + "]," +
1224                                         "\"Environment\" : { " +
1225                                                 "\"Attribute\": [ " +
1226                                                         "{ " +
1227                                                                 "\"Id\" : \"subject-id\", " +
1228                                                                 "\"Value\" : \"Andreas\" " +
1229                                                         "}, " +
1230                                                         "{ " +
1231                                                                 "\"Id\" : \"location\", " +
1232                                                                 "\"Value\" : \"Gamla Stan\" " +
1233                                                         "} " +
1234                                                 "] " +
1235                                         "} " 
1236                                 + " }}");
1237                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
1238                 } catch (Exception e) {
1239                         fail ("Failed convert from JSON to object: " + e);
1240                 }
1241                 
1242                 // Environment present, no other Category element
1243                 try {
1244                         request = JSONRequest.load("{\"Request\" : {"
1245                                         + 
1246                                         "\"Environment\" : { " +
1247                                                 "\"Attribute\": [ " +
1248                                                         "{ " +
1249                                                                 "\"Id\" : \"subject-id\", " +
1250                                                                 "\"Value\" : \"Andreas\" " +
1251                                                         "}, " +
1252                                                         "{ " +
1253                                                                 "\"Id\" : \"location\", " +
1254                                                                 "\"Value\" : \"Gamla Stan\" " +
1255                                                         "} " +
1256                                                 "] " +
1257                                         "} " 
1258                                 + " }}");
1259                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
1260                 } catch (Exception e) {
1261                         fail ("Failed convert from JSON to object: " + e);
1262                 }
1263                 
1264                 // Environment present, 1/multiple other Category element also present
1265                 try {
1266                         request = JSONRequest.load("{\"Request\" : {"
1267                                         + "\"Category\": ["
1268                                                 + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" +
1269                                                 "\"Id\" : \"document-id\", " +
1270                                                 "\"Value\"      : \"aValue\"" +
1271                                                 "}] } "
1272                                                 + "]," +
1273                                         "\"Environment\" : { " +
1274                                                 "\"Attribute\": [ " +
1275                                                         "{ " +
1276                                                                 "\"Id\" : \"subject-id\", " +
1277                                                                 "\"Value\" : \"Andreas\" " +
1278                                                         "}, " +
1279                                                         "{ " +
1280                                                                 "\"Id\" : \"location\", " +
1281                                                                 "\"Value\" : \"Gamla Stan\" " +
1282                                                         "} " +
1283                                                 "] " +
1284                                         "} " 
1285                                 + " }}");
1286                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
1287                 } catch (Exception e) {
1288                         fail ("Failed convert from JSON to object: " + e);
1289                 }
1290                 
1291                 // 2 Environments - duplicates fail
1292                 try {
1293                         request = JSONRequest.load("{\"Request\" : {"
1294                                         + 
1295                                         "\"Environment\" : { " +
1296                                                 "\"Attribute\": [ " +
1297                                                         "{ " +
1298                                                                 "\"Id\" : \"subject-id\", " +
1299                                                                 "\"Value\" : \"Andreas\" " +
1300                                                         "}, " +
1301                                                         "{ " +
1302                                                                 "\"Id\" : \"location\", " +
1303                                                                 "\"Value\" : \"Gamla Stan\" " +
1304                                                         "} " +
1305                                                 "] " +
1306                                         "} " 
1307                                         + 
1308                                         "\"Environment\" : { " +
1309                                                 "\"Attribute\": [ " +
1310                                                         "{ " +
1311                                                                 "\"Id\" : \"subject-id\", " +
1312                                                                 "\"Value\" : \"Andreas\" " +
1313                                                         "}, " +
1314                                                         "{ " +
1315                                                                 "\"Id\" : \"location\", " +
1316                                                                 "\"Value\" : \"Gamla Stan\" " +
1317                                                         "} " +
1318                                                 "] " +
1319                                         "} " 
1320                                 + " }}");
1321                         fail("Operation should throw exception");
1322                 } catch (JSONStructureException e) {
1323                         // correct response
1324                 } catch (Exception e) {
1325                         fail ("Failed convert from JSON to object: " + e);
1326                 }
1327                 
1328                 // Environment with correct Category value
1329                 try {
1330                         request = JSONRequest.load("{\"Request\" : {"
1331                                         + 
1332                                         "\"Environment\" : { " +
1333                                                 "\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\" ," +
1334                                                 "\"Attribute\": [ " +
1335                                                         "{ " +
1336                                                                 "\"Id\" : \"subject-id\", " +
1337                                                                 "\"Value\" : \"Andreas\" " +
1338                                                         "}, " +
1339                                                         "{ " +
1340                                                                 "\"Id\" : \"location\", " +
1341                                                                 "\"Value\" : \"Gamla Stan\" " +
1342                                                         "} " +
1343                                                 "] " +
1344                                         "} " 
1345                                 + " }}");
1346                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString());
1347                 } catch (Exception e) {
1348                         fail ("Failed convert from JSON to object: " + e);
1349                 }
1350                 
1351                 // Environment with wrong Category value
1352                 try {
1353                         request = JSONRequest.load("{\"Request\" : {"
1354                                         + 
1355                                         "\"Environment\" : { " +
1356                                                 "\"CategoryId\" : \"notthesubject\" ," +
1357                                                 "\"Attribute\": [ " +
1358                                                         "{ " +
1359                                                                 "\"Id\" : \"subject-id\", " +
1360                                                                 "\"Value\" : \"Andreas\" " +
1361                                                         "}, " +
1362                                                         "{ " +
1363                                                                 "\"Id\" : \"location\", " +
1364                                                                 "\"Value\" : \"Gamla Stan\" " +
1365                                                         "} " +
1366                                                 "] " +
1367                                         "} " 
1368                                 + " }}");
1369                         fail("Operation should throw exception");
1370                 } catch (JSONStructureException e) {
1371                         // correct response
1372                 } catch (Exception e) {
1373                         fail ("Failed convert from JSON to object: " + e);
1374                 }
1375                 
1376                 // Environment with array of sub-object Environments (Multi Decision)
1377                 try {
1378                         request = JSONRequest.load("{\"Request\" : {"
1379                                         + 
1380                                         "\"Environment\" : ["
1381                                         + "{ " +
1382                                                 "\"Attribute\": [ " +
1383                                                         "{ " +
1384                                                                 "\"Id\" : \"subject-id\", " +
1385                                                                 "\"Value\" : \"Andreas\" " +
1386                                                         "}, " +
1387                                                         "{ " +
1388                                                                 "\"Id\" : \"location\", " +
1389                                                                 "\"Value\" : \"Gamla Stan\" " +
1390                                                         "} " +
1391                                                 "] " +
1392                                         "}, "
1393                                         + "{ " +
1394                                         "\"Attribute\": [ " +
1395                                                 "{ " +
1396                                                         "\"Id\" : \"subject-id\", " +
1397                                                         "\"Value\" : \"Arless\" " +
1398                                                 "}, " +
1399                                                 "{ " +
1400                                                         "\"Id\" : \"location\", " +
1401                                                         "\"Value\" : \"Somewhere\" " +
1402                                                 "} " +
1403                                         "] " +
1404                                         "}, "
1405                                         + "{ " +
1406                                         "\"Attribute\": [ " +
1407                                                 "{ " +
1408                                                         "\"Id\" : \"subject-id\", " +
1409                                                         "\"Value\" : \"Barry\" " +
1410                                                 "}, " +
1411                                                 "{ " +
1412                                                         "\"Id\" : \"location\", " +
1413                                                         "\"Value\" : \"Elsewhere\" " +
1414                                                 "} " +
1415                                         "] " +
1416                                         "} "
1417                                 + "]"
1418                                 + " }}");
1419                         assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString());
1420                 } catch (Exception e) {
1421                         fail ("Failed convert from JSON to object: " + e);
1422                 }
1423
1424         }
1425
1426         
1427 }