-
Notifications
You must be signed in to change notification settings - Fork 8
/
AnyOfExpressionTest.java
executable file
·116 lines (97 loc) · 4.22 KB
/
AnyOfExpressionTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* SNE-XACML: A high performance XACML evaluation engine.
*
* Copyright (C) 2013-2014 Canh Ngo <canhnt@gmail.com>
* System and Network Engineering Group, University of Amsterdam.
* All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package nl.uva.sne.xacml.parsers;
import nl.uva.sne.midd.MIDDException;
import nl.uva.sne.midd.nodes.AbstractNode;
import nl.uva.sne.xacml.AttributeMapper;
import nl.uva.sne.xacml.policy.parsers.*;
import nl.uva.sne.xacml.util.XACMLUtil;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.*;
import org.junit.Test;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class AnyOfExpressionTest {
private static final String SAMPLE_POLICY_FILE = "src/test/resources/xacml3-AnyOf.xml";
//@Test
public void testListIntervals() throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
TargetType target = readTarget();
assertNotNull(target);
List<AnyOfType> lstAnyOf = target.getAnyOf();
assertTrue(lstAnyOf != null && lstAnyOf.size() > 0);
for (AnyOfType anyOf : lstAnyOf) {
List<AllOfType> lstAllOf = anyOf.getAllOf();
assertTrue(lstAllOf != null && lstAllOf.size() > 0);
for (AllOfType allOf : lstAllOf) {
AllOfExpression allOfExp = new AllOfExpression();
try {
allOfExp.parse(allOf);
Map<String, AttributeInfo> mapIntervals = allOfExp.getAttributeInfos();
Iterator<String> it = mapIntervals.keySet().iterator();
while (it.hasNext()) {
String varId = it.next();
System.out.println("Variable '" + varId + "' has interval: " + mapIntervals.get(varId));
}
} catch (XACMLParsingException | MIDDException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println();
}
System.out.println();
}
}
@Test
public void testAnyOf() throws ParserConfigurationException, SAXException, IOException, MIDDException {
TargetType target = readTarget();
assertNotNull(target);
List<AnyOfType> lstAnyOf = target.getAnyOf();
assertTrue(lstAnyOf != null && lstAnyOf.size() > 0);
AttributeMapper attrMapper = new AttributeMapper();
AnyOfExpression ae = new AnyOfExpression(lstAnyOf.get(0), attrMapper);
try {
AbstractNode root = ae.parse();
root.print(System.out);
} catch (XACMLParsingException | MIDDParsingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private TargetType readTarget() throws ParserConfigurationException,
SAXException, IOException, FileNotFoundException {
PolicyType p1 = XACMLUtil.unmarshalPolicyType(new FileInputStream(SAMPLE_POLICY_FILE));
List<Object> objs = p1.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
assertNotNull(objs);
assertTrue(objs.size() == 1);
assertTrue(objs.get(0) instanceof RuleType);
TargetType target = p1.getTarget();
return target;
}
}