-
Notifications
You must be signed in to change notification settings - Fork 8
/
RequestGenerator2.java
executable file
·141 lines (112 loc) · 4.66 KB
/
RequestGenerator2.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* SNE-XACML demo project: illustrate how to use SNE-XACML engine.
*
* Copyright (C) 2013 Canh T. 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.evaltest.sunxacml;
import oasis.names.tc.xacml._2_0.context.schema.os.*;
import java.util.*;
/**
* Generate XACML request v2.0
*
* @author CanhNT <canhnt@gmail.com>
*
*/
public class RequestGenerator2 {
protected Map<String, List<String>> subjAttrMapperValues;
protected Map<String, List<String>> resAttrMapperValues;
protected Map<String, List<String>> actAttrMapperValues;
protected Map<String, List<String>> envAttrMapperValues;
protected Map<String, String> attrMapperDataTypes;
protected Map<String, Random> attrRnds;
protected ObjectFactory factory;
public RequestGenerator2() {
subjAttrMapperValues = new HashMap<String, List<String>>();
resAttrMapperValues = new HashMap<String, List<String>>();
actAttrMapperValues = new HashMap<String, List<String>>();
envAttrMapperValues = new HashMap<String, List<String>>();
attrMapperDataTypes = new HashMap<String, String>();
attrRnds = new HashMap<String, Random>();
factory = new ObjectFactory();
}
public void addSubjectAttribute(String attrId, String dataType, List<String> attrValues ) {
List<String> values = new ArrayList<String>(attrValues);
subjAttrMapperValues.put(attrId, values);
attrMapperDataTypes.put(attrId, dataType);
attrRnds.put(attrId, new Random());
}
public void addResourceAttribute(String attrId, String dataType, List<String> attrValues ) {
List<String> values = new ArrayList<String>(attrValues);
resAttrMapperValues.put(attrId, values);
attrMapperDataTypes.put(attrId, dataType);
attrRnds.put(attrId, new Random());
}
public void addActionAttribute(String attrId, String dataType, List<String> attrValues ) {
List<String> values = new ArrayList<String>(attrValues);
actAttrMapperValues.put(attrId, values);
attrMapperDataTypes.put(attrId, dataType);
attrRnds.put(attrId, new Random());
}
public void addEnvAttribute(String attrId, String dataType, List<String> attrValues ) {
List<String> values = new ArrayList<String>(attrValues);
envAttrMapperValues.put(attrId, values);
attrMapperDataTypes.put(attrId, dataType);
attrRnds.put(attrId, new Random());
}
public RequestType generate() {
RequestType request = factory.createRequestType();
SubjectType subj = factory.createSubjectType();
for(String attrId: subjAttrMapperValues.keySet() ) {
AttributeType attr = createAttribute(attrId, subjAttrMapperValues.get(attrId));
subj.getAttribute().add(attr);
}
request.getSubject().add(subj);
ResourceType res = factory.createResourceType();
for(String attrId: resAttrMapperValues.keySet() ) {
AttributeType attr = createAttribute(attrId, resAttrMapperValues.get(attrId));
res.getAttribute().add(attr);
}
request.getResource().add(res);
ActionType act = factory.createActionType();
for(String attrId: actAttrMapperValues.keySet() ) {
AttributeType attr = createAttribute(attrId, actAttrMapperValues.get(attrId));
act.getAttribute().add(attr);
}
request.setAction(act);
EnvironmentType env = factory.createEnvironmentType();
for(String attrId: envAttrMapperValues.keySet() ) {
AttributeType attr = createAttribute(attrId, envAttrMapperValues.get(attrId));
env.getAttribute().add(attr);
}
request.setEnvironment(env);
return request;
}
protected AttributeType createAttribute(String attrId, List<String> lstValues) {
AttributeType attr = factory.createAttributeType();
attr.setAttributeId(attrId);
attr.setDataType(attrMapperDataTypes.get(attrId));
Random rnd = attrRnds.get(attrId);
Object rndValue = lstValues.get(rnd.nextInt(lstValues.size()));
AttributeValueType attrVal = factory.createAttributeValueType();
attrVal.getContent().add(rndValue);
attr.getAttributeValue().add(attrVal);
return attr;
}
}