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 |
|
package issrg.utils.handler; |
55 |
|
|
56 |
|
import org.w3c.dom.*; |
57 |
|
import java.util.ArrayList; |
58 |
|
import java.util.Iterator; |
59 |
|
|
60 |
|
|
61 |
|
@author |
62 |
|
|
|
|
| 32.2% |
Uncovered Elements: 208 (307) |
Complexity: 64 |
Complexity Density: 0.41 |
|
63 |
|
public class Interpreter { |
64 |
|
|
65 |
|
public static int PUSH = 0; |
66 |
|
public static int PULL = 1; |
67 |
|
public static int INDETERMINATE = 2; |
68 |
|
|
69 |
|
private Node context; |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
2
|
public Interpreter(Node contextIn) {... |
72 |
2
|
this.context = contextIn; |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
|
|
| 72.4% |
Uncovered Elements: 8 (29) |
Complexity: 8 |
Complexity Density: 0.53 |
|
78 |
2
|
public int getModel() {... |
79 |
2
|
if (this.context.getNodeName().equals("wst:RequestSecurityToken")) { |
80 |
2
|
NodeList list = this.context.getChildNodes(); |
81 |
6
|
for (int i=0; i<list.getLength();i++) { |
82 |
6
|
Node node = list.item(i); |
83 |
6
|
if (node.getNodeName().equals("wst:Claims")) { |
84 |
2
|
NamedNodeMap map = node.getAttributes(); |
85 |
2
|
for (int k=0; k<map.getLength(); k++) { |
86 |
2
|
Node statement = map.item(k); |
87 |
2
|
if (statement.getNodeName().equals("Dialect")) { |
88 |
2
|
String value = statement.getNodeValue(); |
89 |
2
|
if (value.equals("urn:oasis:names:tc:SAML:2.0:assertion:AttributeStatementType")) |
90 |
0
|
return this.PUSH; |
91 |
2
|
if (value.equals("urn:oasis:names:tc:SAML:2.0:assertion:AuthnStatementType")) |
92 |
2
|
return this.PULL; |
93 |
|
} |
94 |
|
} |
95 |
|
} |
96 |
|
} |
97 |
|
} |
98 |
0
|
return this.INDETERMINATE; |
99 |
|
} |
100 |
|
|
|
|
| 69.2% |
Uncovered Elements: 8 (26) |
Complexity: 7 |
Complexity Density: 0.5 |
|
101 |
4
|
private Node getSamlAssertion() {... |
102 |
4
|
NodeList nodes=this.context.getChildNodes(); |
103 |
12
|
for (int i=0; i<nodes.getLength();i++) { |
104 |
12
|
Node node = nodes.item(i); |
105 |
0
|
if (Text.class.isAssignableFrom(node.getClass())) continue; |
106 |
12
|
if (node.getNodeName().equals("wst:Claims")) { |
107 |
4
|
NodeList children = node.getChildNodes(); |
108 |
4
|
for (int l=0; l<children.getLength(); l++) { |
109 |
4
|
Node child = children.item(l); |
110 |
0
|
if (Text.class.isAssignableFrom(child.getClass())) continue; |
111 |
4
|
if (child.getNodeName().equals("saml:Assertion")) return child; |
112 |
|
} |
113 |
|
} |
114 |
|
} |
115 |
0
|
return null; |
116 |
|
} |
117 |
|
|
|
|
| 70.7% |
Uncovered Elements: 12 (41) |
Complexity: 10 |
Complexity Density: 0.43 |
|
118 |
2
|
public String getSubjectDN() {... |
119 |
2
|
Node assertion = this.getSamlAssertion(); |
120 |
0
|
if (assertion==null) return null; |
121 |
2
|
NodeList children = assertion.getChildNodes(); |
122 |
4
|
for (int i=0; i<children.getLength(); i++) { |
123 |
4
|
Node node = children.item(i); |
124 |
0
|
if (Text.class.isAssignableFrom(node.getClass())) continue; |
125 |
4
|
if (node.getNodeName().equals("saml:Subject")) { |
126 |
2
|
NodeList j = node.getChildNodes(); |
127 |
2
|
for (int k=0; k<j.getLength(); k++) { |
128 |
2
|
Node gN = j.item(k); |
129 |
0
|
if (Text.class.isAssignableFrom(gN.getClass())) continue; |
130 |
2
|
if (gN.getNodeName().equals("saml:NameID")) { |
131 |
2
|
NodeList fL = gN.getChildNodes(); |
132 |
2
|
if (fL.getLength()==1) { |
133 |
2
|
Node fN = fL.item(0); |
134 |
2
|
if (Text.class.isAssignableFrom(fN.getClass())) { |
135 |
2
|
Text text = (Text)fN; |
136 |
2
|
String str = text.getNodeValue(); |
137 |
2
|
return str.trim(); |
138 |
|
} |
139 |
|
} |
140 |
|
} |
141 |
|
} |
142 |
|
} |
143 |
|
} |
144 |
0
|
return null; |
145 |
|
} |
146 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
147 |
0
|
private String getBinaryCertificate(Node nodeIn) {... |
148 |
0
|
String buf = null; |
149 |
0
|
if (!nodeIn.getNodeName().equals("wsse:BinarySecurityToken")) return null; |
150 |
0
|
NodeList nodes=nodeIn.getChildNodes(); |
151 |
0
|
if (nodes.getLength()==1){ |
152 |
0
|
Node child = nodes.item(0); |
153 |
0
|
if (Text.class.isAssignableFrom(child.getClass())) { |
154 |
0
|
String result = ((Text)child).getNodeValue(); |
155 |
0
|
buf = result.trim(); |
156 |
0
|
return buf; |
157 |
|
} |
158 |
|
} |
159 |
0
|
return buf; |
160 |
|
} |
161 |
|
|
|
|
| 71.4% |
Uncovered Elements: 4 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
162 |
2
|
public String getContextRef() {... |
163 |
2
|
if (this.context.getNodeName().equals("wst:RequestSecurityToken")) { |
164 |
2
|
NamedNodeMap nodeMap = this.context.getAttributes(); |
165 |
4
|
for (int i=0;i<nodeMap.getLength();i++) { |
166 |
2
|
Node node = nodeMap.item(i); |
167 |
2
|
if (node.getNodeName().equals("Context")) { |
168 |
0
|
String val = node.getNodeValue(); |
169 |
0
|
return val.trim(); |
170 |
|
} |
171 |
|
} |
172 |
|
} |
173 |
2
|
return null; |
174 |
|
} |
175 |
|
|
|
|
| 0% |
Uncovered Elements: 92 (92) |
Complexity: 20 |
Complexity Density: 0.37 |
|
176 |
0
|
public AttributeStatement[] getAttributeStatements() {... |
177 |
0
|
ArrayList statements = new ArrayList(); |
178 |
0
|
Node assertion = this.getSamlAssertion(); |
179 |
0
|
NodeList nodes = assertion.getChildNodes(); |
180 |
0
|
for (int i=0; i<nodes.getLength(); i++) { |
181 |
0
|
Node node = nodes.item(i); |
182 |
0
|
if (Text.class.isAssignableFrom(node.getClass())) continue; |
183 |
0
|
if (node.getNodeName().equals("saml:AttributeStatement")) { |
184 |
0
|
AttributeStatement attStatement = new AttributeStatement(); |
185 |
0
|
ArrayList list = new ArrayList(); |
186 |
0
|
NodeList children = node.getChildNodes(); |
187 |
0
|
for (int l=0;l<children.getLength();l++) { |
188 |
0
|
Node ggchild = children.item(l); |
189 |
0
|
if (Text.class.isAssignableFrom(ggchild.getClass())) continue; |
190 |
0
|
if (ggchild.getNodeName().equals("saml:Attribute")) { |
191 |
0
|
NamedNodeMap map = ggchild.getAttributes(); |
192 |
0
|
for (int m=0;m<map.getLength();m++) { |
193 |
0
|
Node att = map.item(m); |
194 |
0
|
if (att.getNodeName().equals("Name")) { |
195 |
0
|
if (att.getNodeValue().equals("Repository")) { |
196 |
0
|
attStatement.setAttributeName("Repository"); |
197 |
0
|
NodeList gggNodes = ggchild.getChildNodes(); |
198 |
0
|
for (int n=0;n<gggNodes.getLength();n++) { |
199 |
0
|
Node gggnode = gggNodes.item(n); |
200 |
0
|
if (Text.class.isAssignableFrom(gggnode.getClass())) continue; |
201 |
0
|
if (gggnode.getNodeName().equals("saml:AttributeValue")) { |
202 |
0
|
NodeList soapNodes = gggnode.getChildNodes(); |
203 |
0
|
if (soapNodes.getLength()==1) { |
204 |
0
|
Node soap = soapNodes.item(0); |
205 |
0
|
if (Text.class.isAssignableFrom(soap.getClass())) { |
206 |
0
|
String result = ((Text)soap).getNodeValue(); |
207 |
0
|
attStatement.setRepository(result.trim()); |
208 |
|
} |
209 |
|
} |
210 |
|
} |
211 |
|
} |
212 |
|
} else { |
213 |
0
|
attStatement.setAttributeName(att.getNodeValue()); |
214 |
0
|
NodeList gggNodes = ggchild.getChildNodes(); |
215 |
0
|
for (int n=0;n<gggNodes.getLength();n++) { |
216 |
0
|
Node gggnode = gggNodes.item(n); |
217 |
0
|
if (Text.class.isAssignableFrom(gggnode.getClass())) continue; |
218 |
0
|
if (gggnode.getNodeName().equals("saml:AttributeValue")) { |
219 |
0
|
NodeList soapNodes = gggnode.getChildNodes(); |
220 |
0
|
for (int j=0; j<soapNodes.getLength(); j++) { |
221 |
0
|
Node value = soapNodes.item(j); |
222 |
0
|
if (Text.class.isAssignableFrom(value.getClass())) continue; |
223 |
0
|
list.add(this.getBinaryCertificate(value)); |
224 |
|
} |
225 |
|
} |
226 |
|
} |
227 |
|
} |
228 |
|
} |
229 |
|
} |
230 |
|
} |
231 |
|
} |
232 |
0
|
String[] binary = new String[list.size()]; |
233 |
0
|
binary = (String[])list.toArray(binary); |
234 |
0
|
attStatement.setBinaryTokens(binary); |
235 |
0
|
statements.add(attStatement); |
236 |
|
} |
237 |
|
} |
238 |
0
|
AttributeStatement [] as = new AttributeStatement[statements.size()]; |
239 |
0
|
as = (AttributeStatement[])statements.toArray(as); |
240 |
0
|
return as; |
241 |
|
} |
242 |
|
|
|
|
| 17.7% |
Uncovered Elements: 65 (79) |
Complexity: 17 |
Complexity Density: 0.36 |
|
243 |
2
|
public SubjectAttributeReference[] getSubAttrRefs() {... |
244 |
2
|
ArrayList references = new ArrayList(); |
245 |
2
|
Node assertion = this.getSamlAssertion(); |
246 |
2
|
NodeList nodes = assertion.getChildNodes(); |
247 |
8
|
for (int i=0; i<nodes.getLength(); i++) { |
248 |
6
|
Node node = nodes.item(i); |
249 |
0
|
if (Text.class.isAssignableFrom(node.getClass())) continue; |
250 |
6
|
if (node.getNodeName().equals("saml:Advice")) { |
251 |
0
|
ArrayList list = new ArrayList(); |
252 |
0
|
NodeList children = node.getChildNodes(); |
253 |
0
|
for (int l=0;l<children.getLength();l++) { |
254 |
0
|
Node ggchild = children.item(l); |
255 |
0
|
if (Text.class.isAssignableFrom(ggchild.getClass())) continue; |
256 |
0
|
if (ggchild.getNodeName().equals("SubjectAttributeReferenceAdvice")) { |
257 |
0
|
NodeList gggNodes = ggchild.getChildNodes(); |
258 |
0
|
for (int m=0;m<gggNodes.getLength();m++) { |
259 |
0
|
Node gggnode = gggNodes.item(m); |
260 |
0
|
if (Text.class.isAssignableFrom(gggnode.getClass())) continue; |
261 |
0
|
if (gggnode.getNodeName().equals("ogsa-saml2:SubjectAttributeReference")) { |
262 |
0
|
NamedNodeMap map = gggnode.getAttributes(); |
263 |
0
|
for (int n=0; n<map.getLength(); n++) { |
264 |
0
|
Node attr = map.item(n); |
265 |
0
|
if (attr.getNodeName().equals("Reference")) { |
266 |
0
|
String uri = attr.getNodeValue(); |
267 |
0
|
NodeList attrChildren = attr.getChildNodes(); |
268 |
0
|
ArrayList atts = new ArrayList(); |
269 |
0
|
for (int j=0; j<attrChildren.getLength(); j++) { |
270 |
0
|
Node g4Node = attrChildren.item(j); |
271 |
0
|
if (Text.class.isAssignableFrom(g4Node.getClass())) continue; |
272 |
0
|
if (g4Node.getNodeName().equals("saml:AttributeDesignator")) { |
273 |
0
|
NamedNodeMap attOfAttrDes = g4Node.getAttributes(); |
274 |
0
|
for (int k=0; k<attOfAttrDes.getLength(); k++) { |
275 |
0
|
Node attType = attOfAttrDes.item(k); |
276 |
0
|
if (attType.getNodeName().equals("AttributeName")) { |
277 |
0
|
String val = attType.getNodeValue(); |
278 |
0
|
val = val.trim(); |
279 |
0
|
atts.add(val); |
280 |
|
} |
281 |
|
} |
282 |
|
} |
283 |
|
} |
284 |
0
|
String[] attNames = new String[atts.size()]; |
285 |
0
|
attNames = (String[])atts.toArray(attNames); |
286 |
0
|
SubjectAttributeReference subAttRef = new SubjectAttributeReference(uri,attNames); |
287 |
0
|
references.add(subAttRef); |
288 |
|
} |
289 |
|
} |
290 |
|
} |
291 |
|
} |
292 |
|
} |
293 |
|
} |
294 |
|
} |
295 |
|
} |
296 |
2
|
SubjectAttributeReference [] sar = new SubjectAttributeReference[references.size()]; |
297 |
2
|
sar = (SubjectAttributeReference[])references.toArray(sar); |
298 |
2
|
return sar; |
299 |
|
} |
300 |
|
} |