2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.policy.pdp.test.std.dom;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.fail;
26 import java.text.ParseException;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.Collection;
30 import java.util.List;
32 import org.junit.Test;
34 import com.att.research.xacml.api.Attribute;
35 import com.att.research.xacml.api.AttributeValue;
36 import com.att.research.xacml.api.Decision;
37 import com.att.research.xacml.api.Identifier;
38 import com.att.research.xacml.api.XACML3;
39 import com.att.research.xacml.std.IdentifierImpl;
40 import com.att.research.xacml.std.StdAttribute;
41 import com.att.research.xacml.std.StdAttributeCategory;
42 import com.att.research.xacml.std.StdAttributeValue;
43 import com.att.research.xacml.std.StdIdReference;
44 import com.att.research.xacml.std.StdMutableAdvice;
45 import com.att.research.xacml.std.StdMutableAttribute;
46 import com.att.research.xacml.std.StdMutableAttributeAssignment;
47 import com.att.research.xacml.std.StdMutableMissingAttributeDetail;
48 import com.att.research.xacml.std.StdMutableObligation;
49 import com.att.research.xacml.std.StdMutableResponse;
50 import com.att.research.xacml.std.StdMutableResult;
51 import com.att.research.xacml.std.StdMutableStatus;
52 import com.att.research.xacml.std.StdMutableStatusDetail;
53 import com.att.research.xacml.std.StdStatusCode;
54 import com.att.research.xacml.std.StdVersion;
55 import com.att.research.xacml.std.datatypes.DataTypes;
56 import com.att.research.xacml.std.datatypes.StringNamespaceContext;
57 import com.att.research.xacml.std.datatypes.XPathExpressionWrapper;
58 import com.att.research.xacml.std.dom.DOMResponse;
59 import com.att.research.xacml.std.dom.DOMStructureException;
62 * Test DOM XML Responses
65 * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
67 * This class was copied from the JSON tests. At this time only the first two methods have been revised to work with XML.
68 * The second method includes multiple instances of all possible fields and has been manually verified.
69 * The remaining methods have not been converted because:
70 * - "conversion" consists of replacing the JSON strings with XML
71 * - the replacement would consist of copying the XML from the JUnit output and doing a String replace
72 * - there would be little examination of the (long) XML strings, so their validity would be questionable
73 * so the benefit for the cost of doing that work is not clear.
77 public class DOMResponseTest {
81 StdMutableResponse response;
83 StdMutableResult result;
85 StdMutableStatus status;
88 // Note: Initially test responses without Obligations, Associated Advice, Attributes, or PolicyIdentifier
92 public void testEmptyAndDecisions() {
95 xmlResponse = DOMResponse.toString(null, false);
96 fail("Operation should throw exception");
97 } catch (DOMStructureException e) {
99 } catch (Exception e) {
100 fail ("Failed convert from object to XML: " + e);
103 // empty response (no Result object)
104 response = new StdMutableResponse();
106 xmlResponse = DOMResponse.toString(response, false);
107 fail("Operation should throw exception");
108 } catch (DOMStructureException e) {
110 } catch (Exception e) {
111 fail ("Failed convert from object to XML: " + e);
115 // just decision, no status
116 response = new StdMutableResponse();
117 result = new StdMutableResult();
118 result.setDecision(Decision.PERMIT);
119 response.add(result);
121 xmlResponse = DOMResponse.toString(response, false);
122 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision></Result></Response>", xmlResponse);
123 } catch (Exception e) {
124 fail("operation failed, e="+e);
127 // just status (empty), no decision
128 response = new StdMutableResponse();
129 result = new StdMutableResult();
130 status = new StdMutableStatus();
131 result.setStatus(status);
132 response.add(result);
134 xmlResponse = DOMResponse.toString(response, false);
135 fail("Operation should throw exception");
136 } catch (DOMStructureException e) {
138 } catch (Exception e) {
139 fail ("Failed convert from object to XML: " + e);
142 // just status (non-empty), no decision
143 response = new StdMutableResponse();
144 result = new StdMutableResult();
145 status = new StdMutableStatus();
146 status.setStatusCode(StdStatusCode.STATUS_CODE_OK);
147 result.setStatus(status);
148 response.add(result);
150 xmlResponse = DOMResponse.toString(response, false);
151 fail("Operation should throw exception");
152 } catch (DOMStructureException e) {
154 } catch (Exception e) {
155 fail ("Failed convert from object to XML: " + e);
159 // test other decisions without Status
161 response = new StdMutableResponse();
162 result = new StdMutableResult();
163 result.setDecision(Decision.DENY);
164 response.add(result);
166 xmlResponse = DOMResponse.toString(response, false);
167 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Deny</Decision></Result></Response>", xmlResponse);
168 } catch (Exception e) {
169 fail("operation failed, e="+e);
172 response = new StdMutableResponse();
173 result = new StdMutableResult();
174 result.setDecision(Decision.NOTAPPLICABLE);
175 response.add(result);
177 xmlResponse = DOMResponse.toString(response, false);
178 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>NotApplicable</Decision></Result></Response>", xmlResponse);
179 } catch (Exception e) {
180 fail("operation failed, e="+e);
183 response = new StdMutableResponse();
184 result = new StdMutableResult();
185 result.setDecision(Decision.INDETERMINATE);
186 response.add(result);
188 xmlResponse = DOMResponse.toString(response, false);
189 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision></Result></Response>", xmlResponse);
190 } catch (Exception e) {
191 fail("operation failed, e="+e);
194 response = new StdMutableResponse();
195 result = new StdMutableResult();
196 result.setDecision(Decision.INDETERMINATE_DENY);
197 response.add(result);
199 xmlResponse = DOMResponse.toString(response, false);
200 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{D}</Decision></Result></Response>", xmlResponse);
201 } catch (Exception e) {
202 fail("operation failed, e="+e);
205 response = new StdMutableResponse();
206 result = new StdMutableResult();
207 result.setDecision(Decision.INDETERMINATE_DENYPERMIT);
208 response.add(result);
210 xmlResponse = DOMResponse.toString(response, false);
211 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{DP}</Decision></Result></Response>", xmlResponse);
212 } catch (Exception e) {
213 fail("operation failed, e="+e);
216 response = new StdMutableResponse();
217 result = new StdMutableResult();
218 result.setDecision(Decision.INDETERMINATE_PERMIT);
219 response.add(result);
221 xmlResponse = DOMResponse.toString(response, false);
222 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{P}</Decision></Result></Response>", xmlResponse);
223 } catch (Exception e) {
224 fail("operation failed, e="+e);
228 // test Multiple Decisions - success
229 response = new StdMutableResponse();
230 result = new StdMutableResult();
231 result.setDecision(Decision.PERMIT);
232 response.add(result);
233 StdMutableResult result2 = new StdMutableResult();
234 result2.setDecision(Decision.DENY);
235 response.add(result2);
237 xmlResponse = DOMResponse.toString(response, false);
238 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision></Result><Result><Decision>Deny</Decision></Result></Response>", xmlResponse);
239 } catch (Exception e) {
240 fail("operation failed, e="+e);
244 // test Multiple Decisions - one success and one error
245 response = new StdMutableResponse();
246 result = new StdMutableResult();
247 result.setDecision(Decision.PERMIT);
248 response.add(result);
249 result2 = new StdMutableResult();
250 result2.setDecision(Decision.INDETERMINATE);
251 response.add(result2);
253 xmlResponse = DOMResponse.toString(response, false);
254 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision></Result><Result><Decision>Indeterminate</Decision></Result></Response>", xmlResponse);
255 } catch (Exception e) {
256 fail("operation failed, e="+e);
263 // Test with every field filled in with multiple values where appropriate
265 public void testAllFieldsResponse() {
267 // fully-loaded multiple response
269 StdMutableResponse response = new StdMutableResponse();
270 // create a Status object
271 StdMutableStatus status = new StdMutableStatus(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
272 status.setStatusMessage("some status message");
273 StdMutableStatusDetail statusDetailIn = new StdMutableStatusDetail();
274 StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail();
275 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "doh"));
276 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_INTEGER.getId(), "5432"));
277 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh"));
278 mad.setAttributeId(XACML3.ID_ACTION_PURPOSE);
279 mad.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION);
280 mad.setDataTypeId(XACML3.ID_DATATYPE_STRING);
281 mad.setIssuer("an Issuer");
282 statusDetailIn.addMissingAttributeDetail(mad);
283 status.setStatusDetail(statusDetailIn);
284 // create a single result object
285 StdMutableResult result = new StdMutableResult(status);
287 result.setDecision(Decision.INDETERMINATE);
288 // put the Result into the Response
289 response.add(result);
292 // create a new Result with a different Decision
293 status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK);
294 result = new StdMutableResult(status);
295 result.setDecision(Decision.DENY);
297 StdMutableObligation obligation = new StdMutableObligation();
298 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
299 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
300 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
302 "obligation-issuer1",
303 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
304 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
305 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
307 "obligation-issuer2",
308 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Ned")));
309 result.addObligation(obligation);
310 obligation = new StdMutableObligation();
311 obligation.setId(XACML3.ID_SUBJECT_CATEGORY_INTERMEDIARY_SUBJECT);
312 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
313 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
315 "obligation-issuer3",
316 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Maggie")));
317 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
318 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
320 "obligation-issuer4",
321 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Homer")));
322 result.addObligation(obligation);
325 StdMutableAdvice advice = new StdMutableAdvice();
326 advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
327 advice.addAttributeAssignment(new StdMutableAttributeAssignment(
328 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
331 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu")));
332 advice.addAttributeAssignment(new StdMutableAttributeAssignment(
335 "advice-issuerNoCategory",
336 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Crusty")));
337 result.addAdvice(advice);
340 response.add(result);
343 // create a new Result with a different Decision
344 // add Child/minor status codes within the main status
345 StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode"));
346 StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode);
347 StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode);
348 StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode);
350 status = new StdMutableStatus(statusCode);
353 result = new StdMutableResult(status);
354 result.setDecision(Decision.PERMIT);
359 // add attribute list in result
360 Identifier categoryIdentifier = new IdentifierImpl("firstCategory");
361 Attribute[] attrList = {
362 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true),
363 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false),
364 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true),
365 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true),
366 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true),
367 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), null, true) };
368 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(attrList)));
369 categoryIdentifier = new IdentifierImpl("secondCategory");
370 Attribute[] secondAttrList = {
371 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true),
372 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false),
373 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) };
374 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList)));
377 // add PolicyIdentifierList to result
378 StdIdReference policyIdentifier1 = null;
379 StdIdReference policyIdentifier2 = null;
380 StdIdReference policySetIdentifier1 = null;
381 StdIdReference policySetIdentifier2 = null;
383 policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3"));
384 policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion"));
385 policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0"));
386 policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion"));
387 } catch (ParseException e1) {
388 fail("creating policyIds, e="+e1);
391 result.addPolicyIdentifier(policyIdentifier1);
392 result.addPolicyIdentifier(policyIdentifier2);
394 result.addPolicySetIdentifier(policySetIdentifier1);
395 result.addPolicySetIdentifier(policySetIdentifier2);
397 response.add(result);
399 // convert Response to XML
401 xmlResponse = DOMResponse.toString(response, false);
402 //System.out.println(xmlResponse);
403 //System.out.println(DOMResponse.toString(response, true));
404 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusMessage>some status message</StatusMessage><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:action\" AttributeId=\"urn:oasis:names:tc:xacml:2.0:action:purpose\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\" Issuer=\"an Issuer\"><AttributeValue>doh</AttributeValue><AttributeValue>5432</AttributeValue><AttributeValue>meh</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result><Result><Decision>Deny</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Ned</AttributeAssignment></Obligation><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Maggie</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Homer</AttributeAssignment></Obligation></Obligations><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Crusty</AttributeAssignment></Advice></AssociatedAdvice></Result><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"><StatusCode Value=\"child1StatusCode\"><StatusCode Value=\"childChildStatusCode\"><StatusCode Value=\"childChildChildStatusCode\"/></StatusCode></StatusCode></StatusCode></Status><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent3\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent4\" Issuer=\"DIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent5\" Issuer=\"EIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrNoIssuer\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes><Attributes Category=\"secondCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent12\" Issuer=\"AIssue2\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu2</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent32\" Issuer=\"CIssue2\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Der2</AttributeValue></Attribute></Attributes><PolicyIdentifierList><PolicyIdReference Version=\"1.2.3\">idRef1</PolicyIdReference><PolicyIdReference>idRef2_NoVersion</PolicyIdReference><PolicySetIdReference Version=\"4.5.6.7.8.9.0\">idSetRef1</PolicySetIdReference><PolicySetIdReference>idSetRef2_NoVersion</PolicySetIdReference></PolicyIdentifierList></Result></Response>", xmlResponse);
405 } catch (Exception e) {
406 fail("operation failed, e="+e);
413 // combinations of Status values with Decision values
415 public void testDecisionStatusMatch() {
416 // the tests in this method use different values and do not change structures, so we can re-use the objects
417 response = new StdMutableResponse();
418 result = new StdMutableResult();
419 status = new StdMutableStatus();
420 result.setStatus(status);
421 response.add(result);
424 status.setStatusCode(StdStatusCode.STATUS_CODE_OK);
425 result.setDecision(Decision.PERMIT);
427 xmlResponse = DOMResponse.toString(response, false);
428 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status></Result></Response>", xmlResponse);
429 } catch (Exception e) {
430 fail("operation failed, e="+e);
432 result.setDecision(Decision.DENY);
434 xmlResponse = DOMResponse.toString(response, false);
435 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Deny</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status></Result></Response>", xmlResponse);
436 } catch (Exception e) {
437 fail("operation failed, e="+e);
439 result.setDecision(Decision.NOTAPPLICABLE);
441 xmlResponse = DOMResponse.toString(response, false);
442 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>NotApplicable</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status></Result></Response>", xmlResponse);
443 } catch (Exception e) {
444 fail("operation failed, e="+e);
446 result.setDecision(Decision.INDETERMINATE);
448 xmlResponse = DOMResponse.toString(response, false);
449 fail("Operation should throw exception");
450 } catch (DOMStructureException e) {
452 } catch (Exception e) {
453 fail ("Failed convert from object to XML: " + e);
455 result.setDecision(Decision.INDETERMINATE_DENY);
457 xmlResponse = DOMResponse.toString(response, false);
458 fail("Operation should throw exception");
459 } catch (DOMStructureException e) {
461 } catch (Exception e) {
462 fail ("Failed convert from object to XML: " + e);
464 result.setDecision(Decision.INDETERMINATE_DENYPERMIT);
466 xmlResponse = DOMResponse.toString(response, false);
467 fail("Operation should throw exception");
468 } catch (DOMStructureException e) {
470 } catch (Exception e) {
471 fail ("Failed convert from object to XML: " + e);
473 result.setDecision(Decision.INDETERMINATE_PERMIT);
475 xmlResponse = DOMResponse.toString(response, false);
476 fail("Operation should throw exception");
477 } catch (DOMStructureException e) {
479 } catch (Exception e) {
480 fail ("Failed convert from object to XML: " + e);
488 // StatusCode = SyntaxError
489 status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR);
490 result.setDecision(Decision.PERMIT);
492 xmlResponse = DOMResponse.toString(response, false);
493 fail("Operation should throw exception");
494 } catch (DOMStructureException e) {
496 } catch (Exception e) {
497 fail ("Failed convert from object to XML: " + e);
499 result.setDecision(Decision.DENY);
501 xmlResponse = DOMResponse.toString(response, false);
502 fail("Operation should throw exception");
503 } catch (DOMStructureException e) {
505 } catch (Exception e) {
506 fail ("Failed convert from object to XML: " + e);
508 result.setDecision(Decision.NOTAPPLICABLE);
510 xmlResponse = DOMResponse.toString(response, false);
511 fail("Operation should throw exception");
512 } catch (DOMStructureException e) {
514 } catch (Exception e) {
515 fail ("Failed convert from object to XML: " + e);
517 result.setDecision(Decision.INDETERMINATE);
519 xmlResponse = DOMResponse.toString(response, false);
520 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/></Status></Result></Response>", xmlResponse);
521 } catch (Exception e) {
522 fail("operation failed, e="+e);
524 result.setDecision(Decision.INDETERMINATE_DENY);
526 xmlResponse = DOMResponse.toString(response, false);
527 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{D}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/></Status></Result></Response>", xmlResponse);
528 } catch (Exception e) {
529 fail("operation failed, e="+e);
531 result.setDecision(Decision.INDETERMINATE_DENYPERMIT);
533 xmlResponse = DOMResponse.toString(response, false);
534 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{DP}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/></Status></Result></Response>", xmlResponse);
535 } catch (Exception e) {
536 fail("operation failed, e="+e);
538 result.setDecision(Decision.INDETERMINATE_PERMIT);
540 xmlResponse = DOMResponse.toString(response, false);
541 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{P}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/></Status></Result></Response>", xmlResponse);
542 } catch (Exception e) {
543 fail("operation failed, e="+e);
547 // StatusCode = ProcessingError
548 status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR);
549 result.setDecision(Decision.PERMIT);
551 xmlResponse = DOMResponse.toString(response, false);
552 fail("Operation should throw exception");
553 } catch (DOMStructureException e) {
555 } catch (Exception e) {
556 fail ("Failed convert from object to XML: " + e);
558 result.setDecision(Decision.DENY);
560 xmlResponse = DOMResponse.toString(response, false);
561 fail("Operation should throw exception");
562 } catch (DOMStructureException e) {
564 } catch (Exception e) {
565 fail ("Failed convert from object to XML: " + e);
567 result.setDecision(Decision.NOTAPPLICABLE);
569 xmlResponse = DOMResponse.toString(response, false);
570 fail("Operation should throw exception");
571 } catch (DOMStructureException e) {
573 } catch (Exception e) {
574 fail ("Failed convert from object to XML: " + e);
576 result.setDecision(Decision.INDETERMINATE);
578 xmlResponse = DOMResponse.toString(response, false);
579 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/></Status></Result></Response>", xmlResponse);
580 } catch (Exception e) {
581 fail("operation failed, e="+e);
583 result.setDecision(Decision.INDETERMINATE_DENY);
585 xmlResponse = DOMResponse.toString(response, false);
586 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{D}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/></Status></Result></Response>", xmlResponse);
587 } catch (Exception e) {
588 fail("operation failed, e="+e);
590 result.setDecision(Decision.INDETERMINATE_DENYPERMIT);
592 xmlResponse = DOMResponse.toString(response, false);
593 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{DP}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/></Status></Result></Response>", xmlResponse);
594 } catch (Exception e) {
595 fail("operation failed, e="+e);
597 result.setDecision(Decision.INDETERMINATE_PERMIT);
599 xmlResponse = DOMResponse.toString(response, false);
600 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{P}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/></Status></Result></Response>", xmlResponse);
601 } catch (Exception e) {
602 fail("operation failed, e="+e);
607 // StatusCode = MissingAttribute
608 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
609 result.setDecision(Decision.PERMIT);
611 xmlResponse = DOMResponse.toString(response, false);
612 fail("Operation should throw exception");
613 } catch (DOMStructureException e) {
615 } catch (Exception e) {
616 fail ("Failed convert from object to XML: " + e);
618 result.setDecision(Decision.DENY);
620 xmlResponse = DOMResponse.toString(response, false);
621 fail("Operation should throw exception");
622 } catch (DOMStructureException e) {
624 } catch (Exception e) {
625 fail ("Failed convert from object to XML: " + e);
627 result.setDecision(Decision.NOTAPPLICABLE);
629 xmlResponse = DOMResponse.toString(response, false);
630 fail("Operation should throw exception");
631 } catch (DOMStructureException e) {
633 } catch (Exception e) {
634 fail ("Failed convert from object to XML: " + e);
636 result.setDecision(Decision.INDETERMINATE);
638 xmlResponse = DOMResponse.toString(response, false);
639 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/></Status></Result></Response>", xmlResponse);
640 } catch (Exception e) {
641 fail("operation failed, e="+e);
643 result.setDecision(Decision.INDETERMINATE_DENY);
645 xmlResponse = DOMResponse.toString(response, false);
646 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{D}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/></Status></Result></Response>", xmlResponse);
647 } catch (Exception e) {
648 fail("operation failed, e="+e);
650 result.setDecision(Decision.INDETERMINATE_DENYPERMIT);
652 xmlResponse = DOMResponse.toString(response, false);
653 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{DP}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/></Status></Result></Response>", xmlResponse);
654 } catch (Exception e) {
655 fail("operation failed, e="+e);
657 result.setDecision(Decision.INDETERMINATE_PERMIT);
659 xmlResponse = DOMResponse.toString(response, false);
660 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{P}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/></Status></Result></Response>", xmlResponse);
661 } catch (Exception e) {
662 fail("operation failed, e="+e);
669 // tests related to Status and its components
671 public void testStatus() {
672 // Status with no StatusCode - error
673 response = new StdMutableResponse();
674 result = new StdMutableResult();
675 status = new StdMutableStatus();
676 result.setStatus(status);
677 result.setDecision(Decision.PERMIT);
678 response.add(result);
680 xmlResponse = DOMResponse.toString(response, false);
681 fail("Operation should throw exception");
682 } catch (DOMStructureException e) {
684 } catch (Exception e) {
685 fail ("Failed convert from object to XML: " + e);
688 // Status with StatusMessage when OK
689 response = new StdMutableResponse();
690 result = new StdMutableResult();
691 status = new StdMutableStatus();
692 status.setStatusCode(StdStatusCode.STATUS_CODE_OK);
693 status.setStatusMessage("I'm ok, you're ok");
694 result.setStatus(status);
695 result.setDecision(Decision.PERMIT);
696 response.add(result);
698 xmlResponse = DOMResponse.toString(response, false);
699 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse);
700 } catch (Exception e) {
701 fail("operation failed, e="+e);
704 // Status with StatusDetail when OK
705 response = new StdMutableResponse();
706 result = new StdMutableResult();
707 status = new StdMutableStatus();
708 status.setStatusCode(StdStatusCode.STATUS_CODE_OK);
709 StdMutableStatusDetail statusDetail = new StdMutableStatusDetail();
710 status.setStatusDetail(statusDetail);
711 result.setStatus(status);
712 result.setDecision(Decision.PERMIT);
713 response.add(result);
715 xmlResponse = DOMResponse.toString(response, false);
716 fail("Operation should throw exception");
717 } catch (DOMStructureException e) {
719 } catch (Exception e) {
720 fail ("Failed convert from object to XML: " + e);
723 // Status with StatusMessage when SyntaxError
724 response = new StdMutableResponse();
725 result = new StdMutableResult();
726 status = new StdMutableStatus();
727 status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR);
728 status.setStatusMessage("I'm ok, you're ok");
729 result.setStatus(status);
730 result.setDecision(Decision.INDETERMINATE);
731 response.add(result);
733 xmlResponse = DOMResponse.toString(response, false);
734 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse);
735 } catch (Exception e) {
736 fail("operation failed, e="+e);
739 // Status with empty StatusDetail when SyntaxError
740 response = new StdMutableResponse();
741 result = new StdMutableResult();
742 status = new StdMutableStatus();
743 status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR);
744 statusDetail = new StdMutableStatusDetail();
745 status.setStatusDetail(statusDetail);
746 result.setStatus(status);
747 result.setDecision(Decision.INDETERMINATE);
748 response.add(result);
750 xmlResponse = DOMResponse.toString(response, false);
751 fail("Operation should throw exception");
752 } catch (DOMStructureException e) {
754 } catch (Exception e) {
755 fail ("Failed convert from object to XML: " + e);
759 // Status with StatusMessage when ProcessingError
760 response = new StdMutableResponse();
761 result = new StdMutableResult();
762 status = new StdMutableStatus();
763 status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR);
764 status.setStatusMessage("I'm ok, you're ok");
765 result.setStatus(status);
766 result.setDecision(Decision.INDETERMINATE);
767 response.add(result);
769 xmlResponse = DOMResponse.toString(response, false);
770 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse);
771 } catch (Exception e) {
772 fail("operation failed, e="+e);
775 // Status with empty StatusDetail when ProcessingError
776 response = new StdMutableResponse();
777 result = new StdMutableResult();
778 status = new StdMutableStatus();
779 status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR);
780 statusDetail = new StdMutableStatusDetail();
781 status.setStatusDetail(statusDetail);
782 result.setStatus(status);
783 result.setDecision(Decision.INDETERMINATE);
784 response.add(result);
786 xmlResponse = DOMResponse.toString(response, false);
787 fail("Operation should throw exception");
788 } catch (DOMStructureException e) {
790 } catch (Exception e) {
791 fail ("Failed convert from object to XML: " + e);
795 // Status with StatusMessage when MissingAttribute
796 response = new StdMutableResponse();
797 result = new StdMutableResult();
798 status = new StdMutableStatus();
799 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
800 status.setStatusMessage("I'm ok, you're ok");
801 result.setStatus(status);
802 result.setDecision(Decision.INDETERMINATE);
803 response.add(result);
805 xmlResponse = DOMResponse.toString(response, false);
806 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse);
807 } catch (Exception e) {
808 fail("operation failed, e="+e);
811 // Status with empty StatusDetail when MissingAttribute
812 response = new StdMutableResponse();
813 result = new StdMutableResult();
814 status = new StdMutableStatus();
815 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
816 statusDetail = new StdMutableStatusDetail();
817 status.setStatusDetail(statusDetail);
818 result.setStatus(status);
819 result.setDecision(Decision.INDETERMINATE);
820 response.add(result);
822 xmlResponse = DOMResponse.toString(response, false);
823 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail></StatusDetail></Status></Result></Response>", xmlResponse);
824 } catch (Exception e) {
825 fail("operation failed, e="+e);
830 // Status with StatusDetail with empty detail when MissingAttribute
831 response = new StdMutableResponse();
832 result = new StdMutableResult();
833 status = new StdMutableStatus();
834 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
835 statusDetail = new StdMutableStatusDetail();
836 StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail();
837 statusDetail.addMissingAttributeDetail(mad);
838 status.setStatusDetail(statusDetail);
839 result.setStatus(status);
840 result.setDecision(Decision.INDETERMINATE);
841 response.add(result);
843 xmlResponse = DOMResponse.toString(response, false);
844 fail("Operation should throw exception");
845 } catch (DOMStructureException e) {
847 } catch (Exception e) {
848 fail ("Failed convert from object to XML: " + e);
851 // Status with StatusDetail with valid detail with no value when MissingAttribute
852 response = new StdMutableResponse();
853 result = new StdMutableResult();
854 status = new StdMutableStatus();
855 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
856 statusDetail = new StdMutableStatusDetail();
857 mad = new StdMutableMissingAttributeDetail();
858 mad.setAttributeId(new IdentifierImpl("mad"));
859 mad.setCategory(XACML3.ID_ACTION);
860 mad.setDataTypeId(DataTypes.DT_STRING.getId());
861 statusDetail.addMissingAttributeDetail(mad);
862 status.setStatusDetail(statusDetail);
863 result.setStatus(status);
864 result.setDecision(Decision.INDETERMINATE);
865 response.add(result);
867 xmlResponse = DOMResponse.toString(response, false);
868 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse);
869 } catch (Exception e) {
870 fail("operation failed, e="+e);
873 // Status with StatusDetail with valid detail with value when MissingAttribute
874 response = new StdMutableResponse();
875 result = new StdMutableResult();
876 status = new StdMutableStatus();
877 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
878 statusDetail = new StdMutableStatusDetail();
879 mad = new StdMutableMissingAttributeDetail();
880 mad.setAttributeId(new IdentifierImpl("mad"));
881 mad.setCategory(XACML3.ID_ACTION);
882 mad.setDataTypeId(DataTypes.DT_STRING.getId());
883 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh"));
884 statusDetail.addMissingAttributeDetail(mad);
885 status.setStatusDetail(statusDetail);
886 result.setStatus(status);
887 result.setDecision(Decision.INDETERMINATE);
888 response.add(result);
890 xmlResponse = DOMResponse.toString(response, false);
891 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"><AttributeValue>meh</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse);
892 } catch (Exception e) {
893 fail("operation failed, e="+e);
896 // Status with StatusDetail with array valid detail with value when MissingAttribute
897 response = new StdMutableResponse();
898 result = new StdMutableResult();
899 status = new StdMutableStatus();
900 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
901 statusDetail = new StdMutableStatusDetail();
902 mad = new StdMutableMissingAttributeDetail();
903 mad.setAttributeId(new IdentifierImpl("mad"));
904 mad.setCategory(XACML3.ID_ACTION);
905 mad.setDataTypeId(DataTypes.DT_STRING.getId());
906 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh"));
907 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "nu?"));
908 statusDetail.addMissingAttributeDetail(mad);
909 status.setStatusDetail(statusDetail);
910 result.setStatus(status);
911 result.setDecision(Decision.INDETERMINATE);
912 response.add(result);
914 xmlResponse = DOMResponse.toString(response, false);
915 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"><AttributeValue>meh</AttributeValue><AttributeValue>nu?</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse);
916 } catch (Exception e) {
917 fail("operation failed, e="+e);
921 // Status with StatusDetail with valid detail with Integer value when MissingAttribute
922 response = new StdMutableResponse();
923 result = new StdMutableResult();
924 status = new StdMutableStatus();
925 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
926 statusDetail = new StdMutableStatusDetail();
927 mad = new StdMutableMissingAttributeDetail();
928 mad.setAttributeId(new IdentifierImpl("mad"));
929 mad.setCategory(XACML3.ID_ACTION);
930 mad.setDataTypeId(DataTypes.DT_STRING.getId());
931 mad.addAttributeValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111));
932 statusDetail.addMissingAttributeDetail(mad);
933 status.setStatusDetail(statusDetail);
934 result.setStatus(status);
935 result.setDecision(Decision.INDETERMINATE);
936 response.add(result);
938 xmlResponse = DOMResponse.toString(response, false);
939 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"><AttributeValue>1111</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse);
940 } catch (Exception e) {
941 fail("operation failed, e="+e);
944 // Status with StatusDetail with array valid detail with Integer value when MissingAttribute
945 response = new StdMutableResponse();
946 result = new StdMutableResult();
947 status = new StdMutableStatus();
948 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
949 statusDetail = new StdMutableStatusDetail();
950 mad = new StdMutableMissingAttributeDetail();
951 mad.setAttributeId(new IdentifierImpl("mad"));
952 mad.setCategory(XACML3.ID_ACTION);
953 mad.setDataTypeId(DataTypes.DT_STRING.getId());
954 mad.addAttributeValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111));
955 mad.addAttributeValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 2222));
956 statusDetail.addMissingAttributeDetail(mad);
957 status.setStatusDetail(statusDetail);
958 result.setStatus(status);
959 result.setDecision(Decision.INDETERMINATE);
960 response.add(result);
962 xmlResponse = DOMResponse.toString(response, false);
963 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"><AttributeValue>1111</AttributeValue><AttributeValue>2222</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse);
964 } catch (Exception e) {
965 fail("operation failed, e="+e);
968 // StringNamespaceContext snc = new StringNamespaceContext();
970 // snc.add("defaultURI");
971 // snc.add("md", "referenceForMD");
972 // } catch (Exception e) {
973 // fail("unable to create NamespaceContext e="+e);
975 // XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record");
977 //TODO - assume that we will never try to pass back an XPathExpression in a MissingAttributeDetail - it doesn't make sense and is unclear how to put into XML
978 // // Status with StatusDetail with valid detail with XPathExpression value when MissingAttribute
979 // response = new StdMutableResponse();
980 // result = new StdMutableResult();
981 // status = new StdMutableStatus();
982 // status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
983 // statusDetail = new StdMutableStatusDetail();
984 // mad = new StdMutableMissingAttributeDetail();
985 // mad.setAttributeId(new IdentifierImpl("mad"));
986 // mad.setCategory(XACML3.ID_ACTION);
987 // mad.setDataTypeId(DataTypes.DT_STRING.getId());
988 // mad.addAttributeValue(new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId")));
989 // statusDetail.addMissingAttributeDetail(mad);
990 // status.setStatusDetail(statusDetail);
991 // result.setStatus(status);
992 // result.setDecision(Decision.INDETERMINATE);
993 // response.add(result);
995 // xmlResponse = DOMResponse.toString(response, false);
996 // assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<MissingAttributeDetail><AttributeValue>1111</AttributeValue><Category>urn:oasis:names:tc:xacml:1.0:action</Category><AttributeId>mad</AttributeId><DataType>http://www.w3.org/2001/XMLSchema#string</DataType></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", xmlResponse);
997 // } catch (Exception e) {
998 // fail("operation failed, e="+e);
1001 // // Status with StatusDetail with array valid detail with XPathExpression value when MissingAttribute
1002 // response = new StdMutableResponse();
1003 // result = new StdMutableResult();
1004 // status = new StdMutableStatus();
1005 // status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
1006 // statusDetail = new StdMutableStatusDetail();
1007 // mad = new StdMutableMissingAttributeDetail();
1008 // mad.setAttributeId(new IdentifierImpl("mad"));
1009 // mad.setCategory(XACML3.ID_ACTION);
1010 // mad.setDataTypeId(DataTypes.DT_STRING.getId());
1011 // mad.addAttributeValue(new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId1")));
1012 // mad.addAttributeValue(new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId2")));
1013 // statusDetail.addMissingAttributeDetail(mad);
1014 // status.setStatusDetail(statusDetail);
1015 // result.setStatus(status);
1016 // result.setDecision(Decision.INDETERMINATE);
1017 // response.add(result);
1019 // xmlResponse = DOMResponse.toString(response, false);
1020 // assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<MissingAttributeDetail><AttributeValue>1111</AttributeValue><AttributeValue>2222</AttributeValue><Category>urn:oasis:names:tc:xacml:1.0:action</Category><AttributeId>mad</AttributeId><DataType>http://www.w3.org/2001/XMLSchema#string</DataType></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", xmlResponse);
1021 // } catch (Exception e) {
1022 // fail("operation failed, e="+e);
1025 //TODO - try with other data types, esp XPathExpression
1027 // Status with StatusDetail with array valid detail with value when SyntaxError
1028 response = new StdMutableResponse();
1029 result = new StdMutableResult();
1030 status = new StdMutableStatus();
1031 status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR);
1032 statusDetail = new StdMutableStatusDetail();
1033 mad = new StdMutableMissingAttributeDetail();
1034 mad.setAttributeId(new IdentifierImpl("mad"));
1035 mad.setCategory(XACML3.ID_ACTION);
1036 mad.setDataTypeId(DataTypes.DT_STRING.getId());
1037 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh"));
1038 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "nu?"));
1039 statusDetail.addMissingAttributeDetail(mad);
1040 status.setStatusDetail(statusDetail);
1041 result.setStatus(status);
1042 result.setDecision(Decision.INDETERMINATE);
1043 response.add(result);
1045 xmlResponse = DOMResponse.toString(response, false);
1046 fail("Operation should throw exception");
1047 } catch (DOMStructureException e) {
1049 } catch (Exception e) {
1050 fail ("Failed convert from object to XML: " + e);
1053 // Status with StatusDetail with array valid detail with value when ProcessingError
1054 response = new StdMutableResponse();
1055 result = new StdMutableResult();
1056 status = new StdMutableStatus();
1057 status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR);
1058 statusDetail = new StdMutableStatusDetail();
1059 mad = new StdMutableMissingAttributeDetail();
1060 mad.setAttributeId(new IdentifierImpl("mad"));
1061 mad.setCategory(XACML3.ID_ACTION);
1062 mad.setDataTypeId(DataTypes.DT_STRING.getId());
1063 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh"));
1064 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "nu?"));
1065 statusDetail.addMissingAttributeDetail(mad);
1066 status.setStatusDetail(statusDetail);
1067 result.setStatus(status);
1068 result.setDecision(Decision.INDETERMINATE);
1069 response.add(result);
1071 xmlResponse = DOMResponse.toString(response, false);
1072 fail("Operation should throw exception");
1073 } catch (DOMStructureException e) {
1075 } catch (Exception e) {
1076 fail ("Failed convert from object to XML: " + e);
1081 // Status with nested child StatusCodes (child status containing child status containing...)
1082 response = new StdMutableResponse();
1083 result = new StdMutableResult();
1084 status = new StdMutableStatus();
1085 StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"));
1086 StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode);
1087 status = new StdMutableStatus(statusCode);
1088 status.setStatusMessage("I'm ok, you're ok");
1089 result.setStatus(status);
1090 result.setDecision(Decision.PERMIT);
1091 response.add(result);
1093 xmlResponse = DOMResponse.toString(response, false);
1094 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"><StatusCode Value=\"child1StatusCode\"/></StatusCode><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse);
1095 } catch (Exception e) {
1096 fail("operation failed, e="+e);
1098 response = new StdMutableResponse();
1099 result = new StdMutableResult();
1100 status = new StdMutableStatus();
1101 StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode"));
1102 StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode);
1103 child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode);
1104 statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode);
1105 status = new StdMutableStatus(statusCode);
1106 status.setStatusMessage("I'm ok, you're ok");
1107 result.setStatus(status);
1108 result.setDecision(Decision.PERMIT);
1109 response.add(result);
1111 xmlResponse = DOMResponse.toString(response, false);
1112 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"><StatusCode Value=\"child1StatusCode\"><StatusCode Value=\"childChildStatusCode\"><StatusCode Value=\"childChildChildStatusCode\"/></StatusCode></StatusCode></StatusCode><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse);
1113 } catch (Exception e) {
1114 fail("operation failed, e="+e);
1122 public void testObligations() {
1124 // create an XPathExpression for use later
1125 StringNamespaceContext snc = new StringNamespaceContext();
1127 snc.add("defaultURI");
1128 snc.add("md", "referenceForMD");
1129 } catch (Exception e) {
1130 fail("unable to create NamespaceContext e="+e);
1132 XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record");
1133 XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital");
1135 StdMutableObligation obligation;
1137 // test Obligation single decision no attributes
1138 response = new StdMutableResponse();
1139 result = new StdMutableResult();
1140 result.setDecision(Decision.PERMIT);
1141 obligation = new StdMutableObligation();
1142 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1143 result.addObligation(obligation);
1144 response.add(result);
1146 xmlResponse = DOMResponse.toString(response, false);
1147 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"></Obligation></Obligations></Result></Response>", xmlResponse);
1148 } catch (Exception e) {
1149 fail("operation failed, e="+e);
1152 // obligation missing Id
1153 response = new StdMutableResponse();
1154 result = new StdMutableResult();
1155 result.setDecision(Decision.PERMIT);
1156 obligation = new StdMutableObligation();
1157 result.addObligation(obligation);
1158 response.add(result);
1160 xmlResponse = DOMResponse.toString(response, false);
1161 fail("Operation should throw exception");
1162 } catch (DOMStructureException e) {
1164 } catch (Exception e) {
1165 fail ("Failed convert from object to XML: " + e);
1170 // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer
1171 response = new StdMutableResponse();
1172 result = new StdMutableResult();
1173 result.setDecision(Decision.PERMIT);
1174 obligation = new StdMutableObligation();
1175 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1176 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1177 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1179 "obligation-issuer1",
1180 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1181 result.addObligation(obligation);
1182 response.add(result);
1184 xmlResponse = DOMResponse.toString(response, false);
1185 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1186 } catch (Exception e) {
1187 fail("operation failed, e="+e);
1191 // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer
1192 response = new StdMutableResponse();
1193 result = new StdMutableResult();
1194 result.setDecision(Decision.PERMIT);
1195 obligation = new StdMutableObligation();
1196 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1197 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1200 "obligation-issuer1",
1201 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1202 result.addObligation(obligation);
1203 response.add(result);
1205 xmlResponse = DOMResponse.toString(response, false);
1206 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1207 } catch (Exception e) {
1208 fail("operation failed, e="+e);
1211 // AttributeAssignment - Missing AttributeId
1212 response = new StdMutableResponse();
1213 result = new StdMutableResult();
1214 result.setDecision(Decision.PERMIT);
1215 obligation = new StdMutableObligation();
1216 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1217 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1218 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1220 "obligation-issuer1",
1221 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1222 result.addObligation(obligation);
1223 response.add(result);
1225 xmlResponse = DOMResponse.toString(response, false);
1226 fail("Operation should throw exception");
1227 } catch (DOMStructureException e) {
1229 } catch (Exception e) {
1230 fail ("Failed convert from object to XML: " + e);
1233 // AttributeAssignment - Missing Value
1234 response = new StdMutableResponse();
1235 result = new StdMutableResult();
1236 result.setDecision(Decision.PERMIT);
1237 obligation = new StdMutableObligation();
1238 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1239 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1240 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1242 "obligation-issuer1",
1244 result.addObligation(obligation);
1245 response.add(result);
1247 xmlResponse = DOMResponse.toString(response, false);
1248 fail("Operation should throw exception");
1249 } catch (DOMStructureException e) {
1251 } catch (Exception e) {
1252 fail ("Failed convert from object to XML: " + e);
1255 // AttributeAssignment - missing required DataType (Different than JSON where DataType is optional with default String)
1256 response = new StdMutableResponse();
1257 result = new StdMutableResult();
1258 result.setDecision(Decision.PERMIT);
1259 obligation = new StdMutableObligation();
1260 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1261 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1262 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1264 "obligation-issuer1",
1265 new StdAttributeValue<String>(null, "Bart")));
1266 result.addObligation(obligation);
1267 response.add(result);
1269 xmlResponse = DOMResponse.toString(response, false);
1270 fail("Operation should throw exception");
1271 } catch (DOMStructureException e) {
1273 } catch (Exception e) {
1274 fail ("Failed convert from object to XML: " + e);
1277 // AttributeAssignment - missing issuer
1278 response = new StdMutableResponse();
1279 result = new StdMutableResult();
1280 result.setDecision(Decision.PERMIT);
1281 obligation = new StdMutableObligation();
1282 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1283 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1284 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1287 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1288 result.addObligation(obligation);
1289 response.add(result);
1291 xmlResponse = DOMResponse.toString(response, false);
1292 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1293 } catch (Exception e) {
1294 fail("operation failed, e="+e);
1297 // AttributeAssignment - Integer type
1298 response = new StdMutableResponse();
1299 result = new StdMutableResult();
1300 result.setDecision(Decision.PERMIT);
1301 obligation = new StdMutableObligation();
1302 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1303 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1304 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1307 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111)));
1308 result.addObligation(obligation);
1309 response.add(result);
1311 xmlResponse = DOMResponse.toString(response, false);
1312 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">1111</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1313 } catch (Exception e) {
1314 fail("operation failed, e="+e);
1318 // AttributeAssignment - XPathExpression type
1319 response = new StdMutableResponse();
1320 result = new StdMutableResult();
1321 result.setDecision(Decision.PERMIT);
1322 obligation = new StdMutableObligation();
1323 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1324 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1325 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1328 new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory"))));
1329 result.addObligation(obligation);
1330 response.add(result);
1332 xmlResponse = DOMResponse.toString(response, false);
1333 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:record</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1334 } catch (Exception e) {
1335 fail("operation failed, e="+e);
1342 // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition:
1343 // <Obligation (attributes of the obligation) >
1344 // <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment>
1345 // <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment>
1348 // which means that there may be multiple AttributeAssignments but each one has only one value.
1349 // This differs from the Attributes section in which each <Attribute> may have multiple <AttributeValue> elements.
1350 // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer.
1354 // AttributeAssignment - Multiple values with same Category and Id (one way of doing array)
1355 response = new StdMutableResponse();
1356 result = new StdMutableResult();
1357 result.setDecision(Decision.PERMIT);
1358 obligation = new StdMutableObligation();
1359 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1360 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1361 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1363 "obligation-issuer1",
1364 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1365 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1366 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1368 "obligation-issuer1",
1369 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Lisa")));
1370 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1371 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1373 "obligation-issuer1",
1374 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Maggie")));
1375 result.addObligation(obligation);
1376 response.add(result);
1378 xmlResponse = DOMResponse.toString(response, false);
1379 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Lisa</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Maggie</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1380 } catch (Exception e) {
1381 fail("operation failed, e="+e);
1385 // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array)
1386 response = new StdMutableResponse();
1387 result = new StdMutableResult();
1388 result.setDecision(Decision.PERMIT);
1389 obligation = new StdMutableObligation();
1390 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1391 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1392 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1394 "obligation-issuer1",
1395 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111)));
1396 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1397 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1399 "obligation-issuer1",
1400 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 2222)));
1401 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1402 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1404 "obligation-issuer1",
1405 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 3333)));
1406 result.addObligation(obligation);
1407 response.add(result);
1409 xmlResponse = DOMResponse.toString(response, false);
1410 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">1111</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">2222</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">3333</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1411 } catch (Exception e) {
1412 fail("operation failed, e="+e);
1416 // Multiple XPathExpression values with same Category and Id (one way of doing array)
1417 response = new StdMutableResponse();
1418 result = new StdMutableResult();
1419 result.setDecision(Decision.PERMIT);
1420 obligation = new StdMutableObligation();
1421 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1422 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1423 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1426 new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory"))));
1427 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1428 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1431 new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory"))));
1432 result.addObligation(obligation);
1433 response.add(result);
1435 xmlResponse = DOMResponse.toString(response, false);
1436 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:record</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:hospital</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1437 } catch (Exception e) {
1438 fail("operation failed, e="+e);
1447 public void testAdvice() {
1449 // create an XPathExpression for use later
1450 StringNamespaceContext snc = new StringNamespaceContext();
1452 snc.add("defaultURI");
1453 snc.add("md", "referenceForMD");
1454 } catch (Exception e) {
1455 fail("unable to create NamespaceContext e="+e);
1457 XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record");
1458 XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital");
1460 StdMutableAdvice Advice;
1462 // test Advice single decision no attributes
1463 response = new StdMutableResponse();
1464 result = new StdMutableResult();
1465 result.setDecision(Decision.PERMIT);
1466 Advice = new StdMutableAdvice();
1467 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1468 result.addAdvice(Advice);
1469 response.add(result);
1471 xmlResponse = DOMResponse.toString(response, false);
1472 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1473 } catch (Exception e) {
1474 fail("operation failed, e="+e);
1477 // Advice missing Id
1478 response = new StdMutableResponse();
1479 result = new StdMutableResult();
1480 result.setDecision(Decision.PERMIT);
1481 Advice = new StdMutableAdvice();
1482 result.addAdvice(Advice);
1483 response.add(result);
1485 xmlResponse = DOMResponse.toString(response, false);
1486 fail("Operation should throw exception");
1487 } catch (DOMStructureException e) {
1489 } catch (Exception e) {
1490 fail ("Failed convert from object to XML: " + e);
1495 // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer
1496 response = new StdMutableResponse();
1497 result = new StdMutableResult();
1498 result.setDecision(Decision.PERMIT);
1499 Advice = new StdMutableAdvice();
1500 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1501 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1502 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1505 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1506 result.addAdvice(Advice);
1507 response.add(result);
1509 xmlResponse = DOMResponse.toString(response, false);
1510 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1511 } catch (Exception e) {
1512 fail("operation failed, e="+e);
1516 // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer
1517 response = new StdMutableResponse();
1518 result = new StdMutableResult();
1519 result.setDecision(Decision.PERMIT);
1520 Advice = new StdMutableAdvice();
1521 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1522 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1526 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1527 result.addAdvice(Advice);
1528 response.add(result);
1530 xmlResponse = DOMResponse.toString(response, false);
1531 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1532 } catch (Exception e) {
1533 fail("operation failed, e="+e);
1536 // AttributeAssignment - Missing AttributeId
1537 response = new StdMutableResponse();
1538 result = new StdMutableResult();
1539 result.setDecision(Decision.PERMIT);
1540 Advice = new StdMutableAdvice();
1541 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1542 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1543 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1546 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1547 result.addAdvice(Advice);
1548 response.add(result);
1550 xmlResponse = DOMResponse.toString(response, false);
1551 fail("Operation should throw exception");
1552 } catch (DOMStructureException e) {
1554 } catch (Exception e) {
1555 fail ("Failed convert from object to XML: " + e);
1558 // AttributeAssignment - Missing Value
1559 response = new StdMutableResponse();
1560 result = new StdMutableResult();
1561 result.setDecision(Decision.PERMIT);
1562 Advice = new StdMutableAdvice();
1563 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1564 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1565 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1569 result.addAdvice(Advice);
1570 response.add(result);
1572 xmlResponse = DOMResponse.toString(response, false);
1573 fail("Operation should throw exception");
1574 } catch (DOMStructureException e) {
1576 } catch (Exception e) {
1577 fail ("Failed convert from object to XML: " + e);
1580 // AttributeAssignment - missing Required DataType (Different than JSON where DataType is optional with default String)
1581 response = new StdMutableResponse();
1582 result = new StdMutableResult();
1583 result.setDecision(Decision.PERMIT);
1584 Advice = new StdMutableAdvice();
1585 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1586 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1587 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1590 new StdAttributeValue<String>(null, "Bart")));
1591 result.addAdvice(Advice);
1592 response.add(result);
1594 xmlResponse = DOMResponse.toString(response, false);
1595 fail("Operation should throw exception");
1596 } catch (DOMStructureException e) {
1598 } catch (Exception e) {
1599 fail ("Failed convert from object to XML: " + e);
1602 // AttributeAssignment - missing issuer
1603 response = new StdMutableResponse();
1604 result = new StdMutableResult();
1605 result.setDecision(Decision.PERMIT);
1606 Advice = new StdMutableAdvice();
1607 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1608 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1609 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1612 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1613 result.addAdvice(Advice);
1614 response.add(result);
1616 xmlResponse = DOMResponse.toString(response, false);
1617 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1618 } catch (Exception e) {
1619 fail("operation failed, e="+e);
1622 // AttributeAssignment - Integer type
1623 response = new StdMutableResponse();
1624 result = new StdMutableResult();
1625 result.setDecision(Decision.PERMIT);
1626 Advice = new StdMutableAdvice();
1627 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1628 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1629 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1632 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111)));
1633 result.addAdvice(Advice);
1634 response.add(result);
1636 xmlResponse = DOMResponse.toString(response, false);
1637 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">1111</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1638 } catch (Exception e) {
1639 fail("operation failed, e="+e);
1643 // AttributeAssignment - XPathExpression type
1644 response = new StdMutableResponse();
1645 result = new StdMutableResult();
1646 result.setDecision(Decision.PERMIT);
1647 Advice = new StdMutableAdvice();
1648 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1649 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1650 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1653 new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory"))));
1654 result.addAdvice(Advice);
1655 response.add(result);
1657 xmlResponse = DOMResponse.toString(response, false);
1658 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:record</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1659 } catch (Exception e) {
1660 fail("operation failed, e="+e);
1667 // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition:
1668 // <Obligation (attributes of the obligation) >
1669 // <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment>
1670 // <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment>
1673 // which means that there may be multiple AttributeAssignments but each one has only one value.
1674 // This differs from the Attributes section in which each <Attribute> may have multiple <AttributeValue> elements.
1675 // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer.
1678 // AttributeAssignment - Multiple values with same Category and Id (one way of doing array)
1679 response = new StdMutableResponse();
1680 result = new StdMutableResult();
1681 result.setDecision(Decision.PERMIT);
1682 Advice = new StdMutableAdvice();
1683 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1684 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1685 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1688 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1689 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1690 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1693 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Lisa")));
1694 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1695 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1698 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Maggie")));
1699 result.addAdvice(Advice);
1700 response.add(result);
1702 xmlResponse = DOMResponse.toString(response, false);
1703 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Lisa</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Maggie</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1704 } catch (Exception e) {
1705 fail("operation failed, e="+e);
1709 // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array)
1710 response = new StdMutableResponse();
1711 result = new StdMutableResult();
1712 result.setDecision(Decision.PERMIT);
1713 Advice = new StdMutableAdvice();
1714 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1715 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1716 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1719 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111)));
1720 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1721 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1724 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 2222)));
1725 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1726 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1729 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 3333)));
1730 result.addAdvice(Advice);
1731 response.add(result);
1733 xmlResponse = DOMResponse.toString(response, false);
1734 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">1111</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">2222</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">3333</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1735 } catch (Exception e) {
1736 fail("operation failed, e="+e);
1740 // Multiple XPathExpression values with same Category and Id (one way of doing array)
1741 response = new StdMutableResponse();
1742 result = new StdMutableResult();
1743 result.setDecision(Decision.PERMIT);
1744 Advice = new StdMutableAdvice();
1745 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1746 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1747 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1750 new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory"))));
1751 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1752 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
1755 new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory"))));
1756 result.addAdvice(Advice);
1757 response.add(result);
1759 xmlResponse = DOMResponse.toString(response, false);
1760 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:record</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:hospital</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1761 } catch (Exception e) {
1762 fail("operation failed, e="+e);
1777 public void testAttributes() {
1779 // create an XPathExpression for use later
1780 StringNamespaceContext snc = new StringNamespaceContext();
1782 snc.add("defaultURI");
1783 snc.add("md", "referenceForMD");
1784 } catch (Exception e) {
1785 fail("unable to create NamespaceContext e="+e);
1787 XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record");
1790 Identifier categoryIdentifier;
1791 List<Attribute> attrList = new ArrayList<Attribute>();
1792 StdMutableAttribute mutableAttribute;
1794 // Attr list with no entries
1795 response = new StdMutableResponse();
1796 result = new StdMutableResult();
1797 result.setDecision(Decision.PERMIT);
1798 categoryIdentifier = new IdentifierImpl("firstCategory");
1800 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1801 response.add(result);
1803 xmlResponse = DOMResponse.toString(response, false);
1804 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"></Attributes></Result></Response>", xmlResponse);
1805 } catch (Exception e) {
1806 fail("operation failed, e="+e);
1811 response = new StdMutableResponse();
1812 result = new StdMutableResult();
1813 result.setDecision(Decision.PERMIT);
1814 categoryIdentifier = new IdentifierImpl("firstCategory");
1816 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1817 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1818 response.add(result);
1820 xmlResponse = DOMResponse.toString(response, false);
1821 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
1822 } catch (Exception e) {
1823 fail("operation failed, e="+e);
1826 // multiple attributes
1827 response = new StdMutableResponse();
1828 result = new StdMutableResult();
1829 result.setDecision(Decision.PERMIT);
1830 categoryIdentifier = new IdentifierImpl("firstCategory");
1832 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1833 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true));
1834 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true));
1835 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true));
1836 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true));
1837 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1838 response.add(result);
1840 xmlResponse = DOMResponse.toString(response, false);
1841 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent2\" Issuer=\"BIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">P10Y4M</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent3\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent4\" Issuer=\"DIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent5\" Issuer=\"EIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
1842 } catch (Exception e) {
1843 fail("operation failed, e="+e);
1846 // IncludeInResult=false/true
1847 response = new StdMutableResponse();
1848 result = new StdMutableResult();
1849 result.setDecision(Decision.PERMIT);
1850 categoryIdentifier = new IdentifierImpl("firstCategory");
1852 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", false));
1853 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1854 response.add(result);
1856 xmlResponse = DOMResponse.toString(response, false);
1857 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"></Attributes></Result></Response>", xmlResponse);
1858 } catch (Exception e) {
1859 fail("operation failed, e="+e);
1862 // Missing AttributeId (mandatory)
1863 response = new StdMutableResponse();
1864 result = new StdMutableResult();
1865 result.setDecision(Decision.PERMIT);
1866 categoryIdentifier = new IdentifierImpl("firstCategory");
1868 attrList.add(new StdAttribute(categoryIdentifier, null, new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1869 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1870 response.add(result);
1872 xmlResponse = DOMResponse.toString(response, false);
1873 fail("Operation should throw exception");
1874 } catch (DOMStructureException e) {
1876 } catch (Exception e) {
1877 fail ("Failed convert from object to XML: " + e);
1880 // Missing mandatory Value
1881 response = new StdMutableResponse();
1882 result = new StdMutableResult();
1883 result.setDecision(Decision.PERMIT);
1884 categoryIdentifier = new IdentifierImpl("firstCategory");
1886 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), null), "AIssue", true));
1887 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1888 response.add(result);
1890 xmlResponse = DOMResponse.toString(response, false);
1891 fail("Operation should throw exception");
1892 } catch (DOMStructureException e) {
1894 } catch (Exception e) {
1895 fail ("Failed convert from object to XML: " + e);
1898 // Missing optional Issuer
1899 response = new StdMutableResponse();
1900 result = new StdMutableResult();
1901 result.setDecision(Decision.PERMIT);
1902 categoryIdentifier = new IdentifierImpl("firstCategory");
1904 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), null, true));
1905 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1906 response.add(result);
1908 xmlResponse = DOMResponse.toString(response, false);
1909 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
1910 } catch (Exception e) {
1911 fail("operation failed, e="+e);
1914 // missing required DataType (different from JSON where DataType is optional and assumed to be String)
1915 response = new StdMutableResponse();
1916 result = new StdMutableResult();
1917 result.setDecision(Decision.PERMIT);
1918 categoryIdentifier = new IdentifierImpl("firstCategory");
1920 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(null, "Apu"), "AIssue", true));
1921 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1922 response.add(result);
1924 xmlResponse = DOMResponse.toString(response, false);
1925 fail("Operation should throw exception");
1926 } catch (DOMStructureException e) {
1928 } catch (Exception e) {
1929 fail ("Failed convert from object to XML: " + e);
1932 // same id, same type different issuer
1933 // (This is not an array of values because Issuer is different)
1934 response = new StdMutableResponse();
1935 result = new StdMutableResult();
1936 result.setDecision(Decision.PERMIT);
1937 categoryIdentifier = new IdentifierImpl("firstCategory");
1939 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1940 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"), "BIssue", true));
1941 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Simpson"), "CIssue", true));
1942 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1943 response.add(result);
1945 xmlResponse = DOMResponse.toString(response, false);
1946 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"BIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Simpson</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
1947 } catch (Exception e) {
1948 fail("operation failed, e="+e);
1951 // same id, same type same issuer
1952 // (This is an array of values)
1953 response = new StdMutableResponse();
1954 result = new StdMutableResult();
1955 result.setDecision(Decision.PERMIT);
1956 categoryIdentifier = new IdentifierImpl("firstCategory");
1958 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1959 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"), "AIssue", true));
1960 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Simpson"), "AIssue", true));
1961 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1962 response.add(result);
1964 xmlResponse = DOMResponse.toString(response, false);
1965 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Simpson</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
1966 } catch (Exception e) {
1967 fail("operation failed, e="+e);
1970 // same Id, different types, same issuer
1971 response = new StdMutableResponse();
1972 result = new StdMutableResult();
1973 result.setDecision(Decision.PERMIT);
1974 categoryIdentifier = new IdentifierImpl("firstCategory");
1976 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1977 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "AIssue", true));
1978 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true));
1979 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true));
1980 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true));
1981 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true));
1982 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1983 response.add(result);
1985 xmlResponse = DOMResponse.toString(response, false);
1986 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">P10Y4M</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
1987 } catch (Exception e) {
1988 fail("operation failed, e="+e);
1991 // same Id, different types, different issuer
1992 response = new StdMutableResponse();
1993 result = new StdMutableResult();
1994 result.setDecision(Decision.PERMIT);
1995 categoryIdentifier = new IdentifierImpl("firstCategory");
1997 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1998 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true));
1999 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true));
2000 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true));
2001 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true));
2002 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), null, true));
2003 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2004 response.add(result);
2006 xmlResponse = DOMResponse.toString(response, false);
2007 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"BIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">P10Y4M</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"DIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"EIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2008 } catch (Exception e) {
2009 fail("operation failed, e="+e);
2012 // different Id, different types, same issuer
2013 response = new StdMutableResponse();
2014 result = new StdMutableResult();
2015 result.setDecision(Decision.PERMIT);
2016 categoryIdentifier = new IdentifierImpl("firstCategory");
2018 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
2019 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "AIssue"), "BIssue", true));
2020 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true));
2021 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true));
2022 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true));
2023 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2024 response.add(result);
2026 xmlResponse = DOMResponse.toString(response, false);
2027 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent2\" Issuer=\"BIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">AIssue</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent3\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent4\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent5\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2028 } catch (Exception e) {
2029 fail("operation failed, e="+e);
2033 // one Attribute of type XPathExpression (the only complex data type)
2034 response = new StdMutableResponse();
2035 result = new StdMutableResult();
2036 result.setDecision(Decision.PERMIT);
2037 categoryIdentifier = new IdentifierImpl("firstCategory");
2039 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategory")), "AIssue", true));
2040 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2041 response.add(result);
2043 xmlResponse = DOMResponse.toString(response, false);
2044 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" XPathCategory=\"xpathCategory\">//md:record</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2045 } catch (Exception e) {
2046 fail("operation failed, e="+e);
2050 // multiple sets of values
2051 response = new StdMutableResponse();
2052 result = new StdMutableResult();
2053 result.setDecision(Decision.PERMIT);
2054 categoryIdentifier = new IdentifierImpl("firstCategory");
2056 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
2057 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false));
2058 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true));
2059 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true));
2060 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true));
2061 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), null, true));
2062 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2063 categoryIdentifier = new IdentifierImpl("secondCategory");
2064 Attribute[] secondAttrList = {
2065 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true),
2066 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false),
2067 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) };
2068 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList)));
2069 response.add(result);
2071 xmlResponse = DOMResponse.toString(response, false);
2072 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent3\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent4\" Issuer=\"DIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent5\" Issuer=\"EIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrNoIssuer\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes><Attributes Category=\"secondCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent12\" Issuer=\"AIssue2\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu2</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent32\" Issuer=\"CIssue2\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Der2</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2073 } catch (Exception e) {
2074 fail("operation failed, e="+e);
2078 // array of values - same type
2079 response = new StdMutableResponse();
2080 result = new StdMutableResult();
2081 result.setDecision(Decision.PERMIT);
2083 categoryIdentifier = new IdentifierImpl("firstCategory");
2084 mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection<AttributeValue<?>>)null, "AIssue", true);
2086 mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"));
2087 mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"));
2088 mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Homer"));
2089 mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Ned"));
2091 attrList.add(mutableAttribute);
2092 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2093 response.add(result);
2095 xmlResponse = DOMResponse.toString(response, false);
2096 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Homer</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Ned</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2097 } catch (Exception e) {
2098 fail("operation failed, e="+e);
2102 // array of values - compatible different types
2103 response = new StdMutableResponse();
2104 result = new StdMutableResult();
2105 result.setDecision(Decision.PERMIT);
2107 categoryIdentifier = new IdentifierImpl("firstCategory");
2108 mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection<AttributeValue<?>>)null, "AIssue", true);
2110 mutableAttribute.addValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567));
2111 mutableAttribute.addValue(new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432));
2112 mutableAttribute.addValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567));
2113 attrList.add(mutableAttribute);
2114 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2115 response.add(result);
2117 xmlResponse = DOMResponse.toString(response, false);
2118 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2119 } catch (Exception e) {
2120 fail("operation failed, e="+e);
2124 // array of values - incompatible different types (Different from JSON because these are not part of an array in XML, just separate values)
2125 response = new StdMutableResponse();
2126 result = new StdMutableResult();
2127 result.setDecision(Decision.PERMIT);
2129 categoryIdentifier = new IdentifierImpl("firstCategory");
2130 mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection<AttributeValue<?>>)null, "AIssue", true);
2132 mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"));
2133 mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"));
2134 mutableAttribute.addValue(new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432));
2135 mutableAttribute.addValue(new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true));
2136 mutableAttribute.addValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567));
2137 mutableAttribute.addValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567));
2138 attrList.add(mutableAttribute);
2139 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2140 response.add(result);
2142 xmlResponse = DOMResponse.toString(response, false);
2143 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">P10Y4M</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2144 } catch (Exception e) {
2145 fail("operation failed, e="+e);
2154 // PolicyIdentifier tests
2156 public void testPolicyIdentifier() {
2158 StdIdReference policyIdentifier1 = null;
2159 StdIdReference policyIdentifier2 = null;
2160 StdIdReference policySetIdentifier1 = null;
2161 StdIdReference policySetIdentifier2 = null;
2163 // multiple PolicyIdentifiers of both types
2164 response = new StdMutableResponse();
2165 result = new StdMutableResult();
2166 result.setDecision(Decision.PERMIT);
2168 policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3"));
2169 policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion"));
2170 policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0"));
2171 policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion"));
2172 } catch (ParseException e1) {
2173 fail("creating policyIds, e="+e1);
2175 result.addPolicyIdentifier(policyIdentifier1);
2176 result.addPolicyIdentifier(policyIdentifier2);
2177 result.addPolicySetIdentifier(policySetIdentifier1);
2178 result.addPolicySetIdentifier(policySetIdentifier2);
2179 response.add(result);
2181 xmlResponse = DOMResponse.toString(response, false);
2182 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><PolicyIdentifierList><PolicyIdReference Version=\"1.2.3\">idRef1</PolicyIdReference><PolicyIdReference>idRef2_NoVersion</PolicyIdReference><PolicySetIdReference Version=\"4.5.6.7.8.9.0\">idSetRef1</PolicySetIdReference><PolicySetIdReference>idSetRef2_NoVersion</PolicySetIdReference></PolicyIdentifierList></Result></Response>", xmlResponse);
2183 } catch (Exception e) {
2184 fail("operation failed, e="+e);
2188 // PolicyIdentifier exists but has no IdReferences
2189 response = new StdMutableResponse();
2190 result = new StdMutableResult();
2191 result.setDecision(Decision.PERMIT);
2192 policyIdentifier1 = null;
2193 result.addPolicyIdentifier(policyIdentifier1);
2194 response.add(result);
2196 xmlResponse = DOMResponse.toString(response, false);
2197 fail("Operation should throw exception");
2198 } catch (DOMStructureException e) {
2200 } catch (Exception e) {
2201 fail ("Failed convert from object to XML: " + e);
2204 // PolicySetIdentifier exists but has not IdReferences
2205 response = new StdMutableResponse();
2206 result = new StdMutableResult();
2207 result.setDecision(Decision.PERMIT);
2208 policySetIdentifier1 = null;
2209 result.addPolicyIdentifier(policySetIdentifier1);
2210 response.add(result);
2212 xmlResponse = DOMResponse.toString(response, false);
2213 fail("Operation should throw exception");
2214 } catch (DOMStructureException e) {
2216 } catch (Exception e) {
2217 fail ("Failed convert from object to XML: " + e);
2220 // PolicyIdentifier with PolicyIdReference and no PolicySetIdReference
2221 response = new StdMutableResponse();
2222 result = new StdMutableResult();
2223 result.setDecision(Decision.PERMIT);
2225 policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3"));
2226 } catch (ParseException e1) {
2227 fail("creating policyIds, e="+e1);
2229 result.addPolicyIdentifier(policyIdentifier1);
2230 response.add(result);
2232 xmlResponse = DOMResponse.toString(response, false);
2233 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><PolicyIdentifierList><PolicyIdReference Version=\"1.2.3\">idRef1</PolicyIdReference></PolicyIdentifierList></Result></Response>", xmlResponse);
2234 } catch (Exception e) {
2235 fail("operation failed, e="+e);
2240 // PolicyIdentifier with no PolicyIdReference and with PolicySetIdReference
2241 response = new StdMutableResponse();
2242 result = new StdMutableResult();
2243 result.setDecision(Decision.PERMIT);
2245 policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0"));
2246 } catch (ParseException e1) {
2247 fail("creating policyIds, e="+e1);
2249 result.addPolicySetIdentifier(policySetIdentifier1);
2250 response.add(result);
2252 xmlResponse = DOMResponse.toString(response, false);
2253 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><PolicyIdentifierList><PolicySetIdReference Version=\"4.5.6.7.8.9.0\">idSetRef1</PolicySetIdReference></PolicyIdentifierList></Result></Response>", xmlResponse);
2254 } catch (Exception e) {
2255 fail("operation failed, e="+e);
2259 // IdReferences without version
2260 response = new StdMutableResponse();
2261 result = new StdMutableResult();
2262 result.setDecision(Decision.PERMIT);
2264 policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), null);
2265 policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion"));
2266 policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"));
2267 policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion"));
2269 result.addPolicyIdentifier(policyIdentifier1);
2270 result.addPolicyIdentifier(policyIdentifier2);
2271 result.addPolicySetIdentifier(policySetIdentifier1);
2272 result.addPolicySetIdentifier(policySetIdentifier2);
2273 response.add(result);
2275 xmlResponse = DOMResponse.toString(response, false);
2276 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><PolicyIdentifierList><PolicyIdReference>idRef1</PolicyIdReference><PolicyIdReference>idRef2_NoVersion</PolicyIdReference><PolicySetIdReference>idSetRef1</PolicySetIdReference><PolicySetIdReference>idSetRef2_NoVersion</PolicySetIdReference></PolicyIdentifierList></Result></Response>", xmlResponse);
2277 } catch (Exception e) {
2278 fail("operation failed, e="+e);
2283 //TODO - the XML spec implies that the Result Attributes may include the Content (It is part of the UML)
2286 // test indentation???
2293 Place to edit long strings ouput from tests
2297 <?xml version="1.0" encoding="UTF-8"?><Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd"><Result><Decision>Permit</Decision></Result></Response>
2298 <?xml version="1.0" encoding="UTF-8"?><Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd"><Result><Decision>Permit</Decision></Result></Response>