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 |
|
package issrg.test.ptb; |
46 |
|
|
47 |
|
import issrg.pba.*; |
48 |
|
import issrg.pba.rbac.*; |
49 |
|
import issrg.pba.rbac.x509.RepositoryACPolicyFinder; |
50 |
|
|
51 |
|
import java.util.ArrayList; |
52 |
|
import java.util.Hashtable; |
53 |
|
import java.io.BufferedReader; |
54 |
|
import java.io.FileInputStream; |
55 |
|
import java.security.MessageDigest; |
56 |
|
import java.math.BigInteger; |
57 |
|
import java.net.URL; |
58 |
|
import java.io.File; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
@author |
75 |
|
@author |
76 |
|
@version |
77 |
|
|
78 |
|
|
|
|
| 70.2% |
Uncovered Elements: 169 (568) |
Complexity: 104 |
Complexity Density: 0.3 |
|
79 |
|
public class PermisTestBench { |
80 |
|
protected static java.io.PrintStream out = System.out; |
81 |
|
protected static java.io.PrintStream err = System.err; |
82 |
|
|
83 |
|
protected String SOA = ""; |
84 |
|
protected String oID = ""; |
85 |
|
protected PBAAPI pbaApi = null; |
86 |
|
protected PTBClock clock; |
87 |
|
protected PermisAction permisAction; |
88 |
|
protected PermisTarget permisTarget; |
89 |
|
protected String userDN; |
90 |
|
protected String rqNumber; |
91 |
|
protected issrg.pba.rbac.SignatureVerifier sv; |
92 |
|
protected issrg.utils.repository.VirtualRepository vr; |
93 |
|
protected PolicyFinder pfinder; |
94 |
|
protected boolean isXML = false; |
95 |
|
|
|
|
| 71.4% |
Uncovered Elements: 12 (42) |
Complexity: 10 |
Complexity Density: 0.36 |
|
96 |
4
|
public static void main(String [] args){... |
97 |
4
|
System.setProperty("line.separator", "\r\n"); |
98 |
4
|
try{ |
99 |
|
|
100 |
4
|
PermisTestBench bench = new PermisTestBench(); |
101 |
|
|
102 |
4
|
try{ |
103 |
4
|
if (args.length >= 5) { |
104 |
4
|
java.io.PrintStream ps = new java.io.PrintStream(new java.io.FileOutputStream(args[args.length-1])); |
105 |
4
|
System.setOut(ps); |
106 |
4
|
System.setErr(ps); |
107 |
|
} |
108 |
|
|
109 |
4
|
if (args.length < 5) { |
110 |
0
|
System.out.println(args.length); |
111 |
0
|
printUsage(); |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
4
|
else if (args[0].intern() == "-generate") { |
116 |
2
|
boolean check; |
117 |
|
|
118 |
|
|
119 |
2
|
if ((args.length == 6) && (args[4]).intern() == "-ignore-signatures") |
120 |
0
|
check = false; |
121 |
2
|
else check = true; |
122 |
|
|
123 |
|
|
124 |
2
|
if (!bench.loadRepositoryFile(args[1],check)) |
125 |
1
|
return; |
126 |
|
|
127 |
|
|
128 |
1
|
if (!bench.initialisePBAAPI()) |
129 |
0
|
return; |
130 |
|
|
131 |
|
|
132 |
1
|
bench.loadRequestsAndGenerateDecisions(args[2],args[3]); |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
2
|
else if (args[0].intern() == "-check") { |
138 |
2
|
bench.checkDecisionFiles(args[1],args[2],args[3]); |
139 |
|
} |
140 |
|
else { |
141 |
|
|
142 |
0
|
printUsage(); |
143 |
|
} |
144 |
|
|
145 |
|
}catch (Throwable th){ |
146 |
0
|
System.out.println("Failed to initialise: "+th.getMessage()); |
147 |
0
|
th.printStackTrace(); |
148 |
|
} |
149 |
|
}finally{ |
150 |
4
|
System.setOut(out); |
151 |
4
|
System.setErr(err); |
152 |
|
} |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
159 |
0
|
public static void printUsage()... |
160 |
|
{ |
161 |
0
|
System.out.println("Usage:"); |
162 |
0
|
System.out.println(" 1. To generate an output file containing decisions"); |
163 |
0
|
System.out.println(" PermisTestBench -generate <repository_spec_file> <rq_spec_file> <decision_file> [-ignore-signatures] <stdio and stderr redirect_file>"); |
164 |
0
|
System.out.println(" 2. To compare two decision files containing decisions"); |
165 |
0
|
System.out.println(" PermisTestBench -check <decision_file1> <decision_file2> <output_diff_file> <stdio and stderr redirect_file>"); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
173 |
4
|
public PermisTestBench(){... |
174 |
4
|
vr = new issrg.utils.repository.VirtualRepository(); |
175 |
4
|
try{ |
176 |
4
|
CustomisePERMIS.setSystemClock("issrg.test.ptb.PTBClock"); |
177 |
4
|
clock = (PTBClock)CustomisePERMIS.getSystemClock(); |
178 |
|
}catch(Exception e){ |
179 |
|
|
180 |
0
|
e.printStackTrace(); |
181 |
|
} |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
@param |
189 |
|
@param |
190 |
|
@return |
191 |
|
|
|
|
| 70% |
Uncovered Elements: 3 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
|
192 |
7
|
protected boolean loadAC(issrg.utils.repository.VirtualRepository vr, String filename){... |
193 |
7
|
try{ |
194 |
7
|
java.io.InputStream io = new java.io.FileInputStream(filename); |
195 |
7
|
byte [] ac = new byte [io.available()]; |
196 |
|
|
197 |
7
|
io.read(ac); |
198 |
|
|
199 |
7
|
issrg.ac.AttributeCertificate acd = issrg.ac.AttributeCertificate.guessEncoding(ac); |
200 |
|
|
201 |
7
|
vr.populate(issrg.ac.Util.generalNamesToString(acd.getACInfo().getHolder().getEntityName()).toUpperCase(), |
202 |
|
CustomisePERMIS.getAttributeCertificateAttribute(), |
203 |
|
ac); |
204 |
7
|
return true; |
205 |
|
} catch (Throwable th){ |
206 |
0
|
System.out.println("Failed to load AC from ["+filename+"]"); |
207 |
0
|
th.printStackTrace(); |
208 |
0
|
return false; |
209 |
|
} |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
@param |
233 |
|
@param |
234 |
|
@return |
235 |
|
|
|
|
| 78.5% |
Uncovered Elements: 14 (65) |
Complexity: 16 |
Complexity Density: 0.43 |
|
236 |
2
|
public boolean loadRepositoryFile(String filename, boolean check) {... |
237 |
2
|
try { |
238 |
2
|
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.FileReader(filename)); |
239 |
2
|
String s; |
240 |
2
|
String varName = null; |
241 |
2
|
String[] varValue = null; |
242 |
2
|
PTBSignatureVerifier ptbSV = null; |
243 |
|
|
244 |
|
|
245 |
0
|
if (!check) sv = new SamplePKI(); |
246 |
|
else { |
247 |
|
|
248 |
2
|
sv = new PTBSignatureVerifier(); |
249 |
2
|
ptbSV = (PTBSignatureVerifier) sv; |
250 |
|
} |
251 |
|
|
252 |
0
|
while ((varValue = loadVarValue(in))!=null){ |
253 |
18
|
s = varValue[1]; |
254 |
18
|
varName = varValue[0]; |
255 |
|
|
256 |
18
|
if (varName == "SOA_DN"){ |
257 |
2
|
SOA = s; |
258 |
|
}else |
259 |
16
|
if (varName == "POLICY_OID"){ |
260 |
2
|
oID = s; |
261 |
|
}else |
262 |
14
|
if (varName == "CA") { |
263 |
2
|
if (check) |
264 |
2
|
if (!ptbSV.setCACertificate(s)) return false; |
265 |
|
} else |
266 |
12
|
if (varName == "SOA_CERT"){ |
267 |
3
|
if (check) |
268 |
0
|
if (!ptbSV.addSOACertificate(s)) return false; |
269 |
|
}else |
270 |
9
|
if (varName == "POLICY_AC"){ |
271 |
0
|
loadAC(vr, s); |
272 |
|
}else |
273 |
9
|
if (varName == "CURRENT_TIME"){ |
274 |
1
|
clock.setTime(s); |
275 |
|
}else |
276 |
8
|
if (varName == "AC"){ |
277 |
7
|
loadAC(vr, s); |
278 |
|
}else |
279 |
1
|
if (varName == "POLICY_XML"){ |
280 |
1
|
loadXML(s); |
281 |
|
}else |
282 |
0
|
System.out.println("Unrecognised line; ignored: "+varName+"="+s); |
283 |
|
} |
284 |
1
|
return true; |
285 |
|
} |
286 |
|
catch (Exception e) |
287 |
|
{ |
288 |
0
|
e.printStackTrace(); |
289 |
0
|
return false; |
290 |
|
} |
291 |
|
} |
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
@param |
301 |
|
@return |
302 |
|
|
303 |
|
|
304 |
|
|
|
|
| 88% |
Uncovered Elements: 3 (25) |
Complexity: 6 |
Complexity Density: 0.32 |
|
305 |
11116
|
protected String[] loadVarValue(BufferedReader in) {... |
306 |
11116
|
String s = ""; |
307 |
11116
|
try { |
308 |
11116
|
while (true) { |
309 |
11122
|
s= in.readLine(); |
310 |
11122
|
if (s == null) return null; |
311 |
11117
|
if (s.startsWith("#")) continue; |
312 |
11111
|
int i = s.indexOf('='); |
313 |
11111
|
String varName = null; |
314 |
11111
|
if (i>=0){ |
315 |
11111
|
varName = s.substring(0, i).intern(); |
316 |
11111
|
s = s.substring(i+1); |
317 |
11111
|
String[] result = new String[2]; |
318 |
11111
|
result[0] = varName; |
319 |
11111
|
result[1] = s; |
320 |
11111
|
return result; |
321 |
|
} |
322 |
0
|
else continue; |
323 |
|
} |
324 |
|
} |
325 |
|
catch (Exception e) { |
326 |
0
|
return null; |
327 |
|
} |
328 |
|
} |
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
@return |
337 |
|
|
|
|
| 63.6% |
Uncovered Elements: 4 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
338 |
1
|
public boolean initialisePBAAPI() {... |
339 |
|
|
340 |
1
|
issrg.utils.repository.AttributeRepository r=vr; |
341 |
1
|
try { |
342 |
1
|
CustomisePERMIS.configureX509Flavour(); |
343 |
1
|
if (!isXML){ |
344 |
0
|
pbaApi = new PermisRBAC(new RepositoryACPolicyFinder(r, oID, new LDAPDNPrincipal(SOA), sv), r, null); |
345 |
|
}else{ |
346 |
1
|
pbaApi = new PermisRBAC(pfinder, r, null); |
347 |
|
} |
348 |
1
|
return true; |
349 |
|
} |
350 |
|
catch (Exception e) { |
351 |
0
|
e.printStackTrace(); |
352 |
0
|
return false; |
353 |
|
} |
354 |
|
} |
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
@param |
377 |
|
@return |
378 |
|
|
|
|
| 74.3% |
Uncovered Elements: 26 (101) |
Complexity: 23 |
Complexity Density: 0.32 |
|
379 |
721
|
protected boolean loadRequest(BufferedReader in) {... |
380 |
721
|
String[] varValue; |
381 |
721
|
String targetDN = ""; |
382 |
721
|
String action = ""; |
383 |
721
|
String value = ""; |
384 |
721
|
String type = ""; |
385 |
721
|
int argN; |
386 |
721
|
ArrayList arguments = new ArrayList(); |
387 |
|
|
388 |
721
|
varValue = loadVarValue(in); |
389 |
721
|
if (varValue == null) return false; |
390 |
|
|
391 |
720
|
if (varValue[0].intern() == "RQ_NUMBER") { |
392 |
720
|
rqNumber = varValue[1]; |
393 |
0
|
} else return false; |
394 |
|
|
395 |
720
|
varValue = loadVarValue(in); |
396 |
0
|
if (varValue == null) return false; |
397 |
|
|
398 |
720
|
if ((varValue[0].intern() == "USER_DN") || (varValue[0].intern() == "USER")) { |
399 |
720
|
userDN = varValue[1]; |
400 |
0
|
} else return false; |
401 |
|
|
402 |
720
|
varValue = loadVarValue(in); |
403 |
0
|
if (varValue == null) return false; |
404 |
|
|
405 |
720
|
if ((varValue[0].intern() == "TARGET_DN") || (varValue[0].intern() == "TARGET")) { |
406 |
720
|
targetDN = varValue[1]; |
407 |
0
|
} else return false; |
408 |
|
|
409 |
720
|
varValue = loadVarValue(in); |
410 |
0
|
if (varValue == null) return false; |
411 |
|
|
412 |
720
|
if (varValue[0].intern() == "ACTION") { |
413 |
720
|
action = varValue[1]; |
414 |
0
|
} else return false; |
415 |
|
|
416 |
|
|
417 |
720
|
argN = -1; |
418 |
720
|
do { |
419 |
1584
|
argN++; |
420 |
1584
|
try { |
421 |
|
|
422 |
1584
|
in.mark(1024); |
423 |
|
} |
424 |
|
catch (Exception e) |
425 |
|
{ |
426 |
0
|
return false; |
427 |
|
} |
428 |
1584
|
varValue = loadVarValue(in); |
429 |
1584
|
if (varValue == null) break; |
430 |
|
|
431 |
1583
|
if (varValue[0].intern() == "RQ_NUMBER") { |
432 |
719
|
try { |
433 |
|
|
434 |
719
|
in.reset(); |
435 |
719
|
break; |
436 |
|
} |
437 |
|
catch (Exception e) { |
438 |
0
|
return false; |
439 |
|
} |
440 |
|
} |
441 |
|
|
442 |
864
|
if (varValue[0].intern() == "ARG_TYPE") { |
443 |
|
|
444 |
864
|
type = varValue[1]; |
445 |
864
|
varValue = loadVarValue(in); |
446 |
0
|
if (varValue == null) return false; |
447 |
864
|
if (varValue[0].intern() == "ARG_VALUE") { |
448 |
864
|
value = varValue[1]; |
449 |
0
|
} else return false; |
450 |
|
} |
451 |
|
|
452 |
864
|
arguments.add(argN, new PermisArgument(type, value)); |
453 |
|
} while (true); |
454 |
|
|
455 |
|
|
456 |
720
|
if (argN > 0) { |
457 |
|
|
458 |
576
|
PermisArgument[] permisArguments = new PermisArgument[arguments.size()]; |
459 |
576
|
permisArguments = (PermisArgument[]) arguments.toArray(permisArguments); |
460 |
576
|
permisAction = new PermisAction(action, permisArguments); |
461 |
|
} else |
462 |
|
|
463 |
144
|
permisAction = new PermisAction(action); |
464 |
|
|
465 |
|
|
466 |
720
|
try { |
467 |
720
|
boolean isAURL; |
468 |
|
|
469 |
720
|
try { |
470 |
720
|
new URL(targetDN); |
471 |
0
|
isAURL = true; |
472 |
|
} |
473 |
|
catch (Exception e) { |
474 |
|
|
475 |
|
|
476 |
720
|
isAURL = false; |
477 |
|
} |
478 |
|
|
479 |
720
|
if (!isAURL) |
480 |
720
|
permisTarget = new PermisTarget(targetDN, null); |
481 |
0
|
else permisTarget = new PermisTarget(targetDN); |
482 |
720
|
return true; |
483 |
|
} |
484 |
|
catch (Exception e) { |
485 |
0
|
e.printStackTrace(); |
486 |
0
|
return false; |
487 |
|
} |
488 |
|
} |
489 |
|
|
490 |
|
|
491 |
|
|
492 |
|
|
493 |
|
|
494 |
|
|
495 |
|
|
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
@param |
501 |
|
@param |
502 |
|
@return |
503 |
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 2 |
Complexity Density: 0.14 |
|
504 |
1
|
protected boolean writeDecisionHeader(java.io.BufferedWriter out, String rqFile) {... |
505 |
1
|
try { |
506 |
|
|
507 |
1
|
out.write("REQUEST_FILE="); |
508 |
|
|
509 |
1
|
out.newLine(); |
510 |
1
|
out.write("REQUEST_FILE_HASH="); |
511 |
1
|
byte[] hash = getRequestHash(rqFile); |
512 |
1
|
BigInteger bi = new BigInteger(hash); |
513 |
1
|
bi = bi.abs(); |
514 |
1
|
String s = bi.toString(16); |
515 |
1
|
out.write(s); |
516 |
1
|
out.newLine(); |
517 |
1
|
out.write("EVALUATION_DATE="); |
518 |
|
|
519 |
|
|
520 |
1
|
out.newLine(); |
521 |
1
|
return true; |
522 |
|
} |
523 |
|
catch (Exception e) { |
524 |
0
|
return false; |
525 |
|
} |
526 |
|
} |
527 |
|
|
528 |
|
|
529 |
|
|
530 |
|
|
531 |
|
|
532 |
|
|
533 |
|
|
534 |
|
|
535 |
|
|
536 |
|
|
537 |
|
|
538 |
|
|
539 |
|
@param |
540 |
|
@param |
541 |
|
@param |
542 |
|
@param |
543 |
|
@param |
544 |
|
@return |
545 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 2 |
Complexity Density: 0.12 |
|
546 |
720
|
protected boolean writeDecisionData(java.io.BufferedWriter out, String rqNumber,... |
547 |
|
String code, String info, String additionalInfo) { |
548 |
720
|
try { |
549 |
720
|
out.write("RQ_NUMBER="); |
550 |
720
|
out.write(rqNumber); out.newLine(); |
551 |
720
|
out.write("RESULT_CODE="); |
552 |
720
|
out.write(code); out.newLine(); |
553 |
720
|
out.write("RESULT_INFO="); |
554 |
720
|
out.write(info); out.newLine(); |
555 |
720
|
out.write("ADDITIONAL_INFO="); |
556 |
720
|
out.write(additionalInfo); out.newLine(); |
557 |
720
|
out.flush(); |
558 |
720
|
return true; |
559 |
|
} |
560 |
|
catch (Exception e) { |
561 |
0
|
return false; |
562 |
|
} |
563 |
|
} |
564 |
|
|
565 |
|
|
566 |
|
|
567 |
|
|
568 |
|
|
569 |
|
|
570 |
|
@param |
571 |
|
@param |
572 |
|
|
|
|
| 73.2% |
Uncovered Elements: 11 (41) |
Complexity: 8 |
Complexity Density: 0.24 |
|
573 |
1
|
public void loadRequestsAndGenerateDecisions(String rqFile, String decisionFile) {... |
574 |
|
|
575 |
1
|
try { |
576 |
1
|
java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter(decisionFile)); |
577 |
|
|
578 |
1
|
int code; |
579 |
1
|
String resultInfo; |
580 |
1
|
String additionalInfo; |
581 |
|
|
582 |
|
|
583 |
0
|
if (!writeDecisionHeader(out,rqFile)) return; |
584 |
1
|
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.FileReader(rqFile)); |
585 |
|
|
586 |
|
|
587 |
721
|
while (loadRequest(in)) { |
588 |
720
|
resultInfo = ""; |
589 |
720
|
additionalInfo = ""; |
590 |
720
|
try{ |
591 |
|
|
592 |
720
|
java.security.Principal user = new LDAPDNPrincipal(userDN); |
593 |
720
|
authenticate(user); |
594 |
|
|
595 |
|
|
596 |
720
|
Subject s = pbaApi.getCreds(user, null); |
597 |
|
|
598 |
720
|
Hashtable env = new Hashtable(); |
599 |
720
|
env.put(((PermisRBAC)pbaApi).TIME_VARIABLE,clock); |
600 |
|
|
601 |
588
|
if (!pbaApi.decision(s, permisAction, permisTarget, env)) { |
602 |
588
|
code = 1; |
603 |
588
|
resultInfo = "The action is not allowed"; |
604 |
|
} |
605 |
|
else { |
606 |
0
|
code = 0; |
607 |
0
|
resultInfo = "Action succeeded"; |
608 |
|
} |
609 |
|
} catch (PbaException pe) { |
610 |
132
|
code = 2; |
611 |
132
|
resultInfo = "Invalid input"; |
612 |
132
|
additionalInfo = pe.getMessage(); |
613 |
|
} catch (Throwable th){ |
614 |
0
|
code = 3; |
615 |
0
|
resultInfo = "Run-time error"; |
616 |
0
|
additionalInfo = th.getMessage(); |
617 |
|
} |
618 |
|
|
619 |
720
|
if (!writeDecisionData(out,rqNumber,new Integer(code).toString(),resultInfo,additionalInfo)) |
620 |
0
|
break; |
621 |
|
} |
622 |
1
|
out.flush(); out.close(); |
623 |
|
} |
624 |
|
catch (Exception e) |
625 |
|
{ |
626 |
0
|
e.printStackTrace(); |
627 |
|
} |
628 |
|
} |
629 |
|
|
630 |
|
|
631 |
|
|
632 |
|
|
633 |
|
|
634 |
|
|
635 |
|
|
636 |
|
|
637 |
|
|
638 |
|
|
639 |
|
|
640 |
|
@param |
641 |
|
@return |
642 |
|
|
|
|
| 75% |
Uncovered Elements: 9 (36) |
Complexity: 7 |
Complexity Density: 0.29 |
|
643 |
2
|
protected String[] loadDecisionHeader(java.io.BufferedReader in) {... |
644 |
2
|
String[] varValue; |
645 |
2
|
String requestFile = ""; |
646 |
2
|
String requestHash = ""; |
647 |
2
|
String evaluationDate = ""; |
648 |
|
|
649 |
2
|
varValue = loadVarValue(in); |
650 |
0
|
if (varValue == null) return null; |
651 |
|
|
652 |
2
|
if (varValue[0].intern() == "REQUEST_FILE") { |
653 |
2
|
requestFile = varValue[1]; |
654 |
|
} |
655 |
|
|
656 |
2
|
varValue = loadVarValue(in); |
657 |
0
|
if (varValue == null) return null; |
658 |
|
|
659 |
2
|
if (varValue[0].intern() == "REQUEST_FILE_HASH") { |
660 |
2
|
requestHash = varValue[1]; |
661 |
|
} |
662 |
|
|
663 |
2
|
varValue = loadVarValue(in); |
664 |
0
|
if (varValue == null) return null; |
665 |
|
|
666 |
2
|
if (varValue[0].intern() == "EVALUATION_DATE") { |
667 |
2
|
evaluationDate = varValue[1]; |
668 |
|
} |
669 |
2
|
String[] result = new String[3]; |
670 |
2
|
result[0] = requestFile; |
671 |
2
|
result[1] = requestHash; |
672 |
2
|
result[2] = evaluationDate; |
673 |
2
|
return result; |
674 |
|
} |
675 |
|
|
676 |
|
|
677 |
|
|
678 |
|
|
679 |
|
|
680 |
|
|
681 |
|
|
682 |
|
|
683 |
|
|
684 |
|
|
685 |
|
|
686 |
|
|
687 |
|
@param |
688 |
|
@return |
689 |
|
|
|
|
| 74% |
Uncovered Elements: 13 (50) |
Complexity: 9 |
Complexity Density: 0.26 |
|
690 |
1442
|
protected String[] loadDecision(BufferedReader in) {... |
691 |
1442
|
String[] varValue; |
692 |
1442
|
String rqNumber = ""; |
693 |
1442
|
String resultCode = ""; |
694 |
1442
|
String resultInfo = ""; |
695 |
1442
|
String additionalInfo = ""; |
696 |
|
|
697 |
1442
|
varValue = loadVarValue(in); |
698 |
1442
|
if (varValue == null) return null; |
699 |
|
|
700 |
1440
|
if (varValue[0].intern() == "RQ_NUMBER") { |
701 |
1440
|
rqNumber = varValue[1]; |
702 |
0
|
} else return null; |
703 |
|
|
704 |
1440
|
varValue = loadVarValue(in); |
705 |
0
|
if (varValue == null) return null; |
706 |
|
|
707 |
1440
|
if (varValue[0].intern() == "RESULT_CODE") { |
708 |
1440
|
resultCode = varValue[1]; |
709 |
0
|
} else return null; |
710 |
|
|
711 |
1440
|
varValue = loadVarValue(in); |
712 |
0
|
if (varValue == null) return null; |
713 |
|
|
714 |
1440
|
if (varValue[0].intern() == "RESULT_INFO") { |
715 |
1440
|
resultInfo = varValue[1]; |
716 |
0
|
} else return null; |
717 |
|
|
718 |
1440
|
varValue = loadVarValue(in); |
719 |
0
|
if (varValue == null) return null; |
720 |
|
|
721 |
1440
|
if (varValue[0].intern() == "ADDITIONAL_INFO") { |
722 |
1440
|
additionalInfo = varValue[1]; |
723 |
|
} |
724 |
1440
|
String[] result = new String[4]; |
725 |
1440
|
result[0] = rqNumber; |
726 |
1440
|
result[1] = resultCode; |
727 |
1440
|
result[2] = resultInfo; |
728 |
1440
|
result[3] = additionalInfo; |
729 |
1440
|
return result; |
730 |
|
} |
731 |
|
|
732 |
|
|
733 |
|
|
734 |
|
|
735 |
|
|
736 |
|
|
737 |
|
|
738 |
|
|
739 |
|
|
740 |
|
|
741 |
|
|
742 |
|
|
743 |
|
|
744 |
|
|
745 |
|
|
746 |
|
|
747 |
|
@param |
748 |
|
@param |
749 |
|
@param |
750 |
|
|
|
|
| 59.5% |
Uncovered Elements: 32 (79) |
Complexity: 17 |
Complexity Density: 0.29 |
|
751 |
2
|
public void checkDecisionFiles(String f1,String f2, String diff) {... |
752 |
2
|
try { |
753 |
2
|
java.io.BufferedReader in1 = new java.io.BufferedReader(new java.io.FileReader(f1)); |
754 |
2
|
java.io.BufferedReader in2 = new java.io.BufferedReader(new java.io.FileReader(f2)); |
755 |
1
|
java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter(diff)); |
756 |
|
|
757 |
|
|
758 |
1
|
String[] header1 = loadDecisionHeader(in1); |
759 |
1
|
String[] header2 = loadDecisionHeader(in2); |
760 |
|
|
761 |
0
|
if (header1 == null || header2 == null) return; |
762 |
|
|
763 |
|
|
764 |
|
|
765 |
1
|
String[] decision1 = null; |
766 |
1
|
String[] decision2 = null; |
767 |
|
|
768 |
|
|
769 |
1
|
decision1 = loadDecision(in1); |
770 |
1
|
decision2 = loadDecision(in2); |
771 |
721
|
while ((decision1 != null) && (decision2 != null)) { |
772 |
|
|
773 |
720
|
if (decision1[0].intern() == decision2[0].intern()) { |
774 |
720
|
out.write("[Checking request " + decision1[0]+"]"); out.newLine(); |
775 |
|
|
776 |
720
|
if (decision1[1].intern() == decision2[1].intern()) { |
777 |
720
|
out.write(" (OK) Decision codes are equal."); out.newLine(); |
778 |
|
} |
779 |
|
else { |
780 |
0
|
out.write(" (WN) Decision codes differ (" + decision1[1] + " VS " + decision2[1] + ")"); |
781 |
0
|
out.newLine(); |
782 |
|
} |
783 |
|
|
784 |
720
|
if (decision1[2].intern() == decision2[2].intern()) { |
785 |
720
|
out.write(" (OK) Messages are the same."); out.newLine(); |
786 |
|
} |
787 |
|
else { |
788 |
0
|
out.write(" (WN) Messages differ:"); out.newLine(); |
789 |
0
|
out.write(" 1. " + decision1[2]); out.newLine(); |
790 |
0
|
out.write(" 2. " + decision2[2]); out.newLine(); |
791 |
|
} |
792 |
720
|
if ((decision1[3].intern() == "") && (decision2[3].intern() == "")) { |
793 |
588
|
out.write(" (OK) No additional information provided."); out.newLine(); |
794 |
|
} |
795 |
|
else |
796 |
132
|
if (decision1[3].intern() == decision2[3].intern()) { |
797 |
132
|
out.write(" (OK) Additional notes are the same."); |
798 |
132
|
out.newLine(); |
799 |
|
} else { |
800 |
0
|
out.write(" (WN) Additional notes differ:"); |
801 |
0
|
out.newLine(); |
802 |
0
|
out.write(" 1. " + decision1[3]); |
803 |
0
|
out.newLine(); |
804 |
0
|
out.write(" 2. " + decision2[3]); |
805 |
0
|
out.newLine(); |
806 |
|
} |
807 |
|
} |
808 |
0
|
else break; |
809 |
720
|
decision1 = loadDecision(in1); |
810 |
720
|
decision2 = loadDecision(in2); |
811 |
|
} |
812 |
1
|
if ((decision1 != null) && (decision2 != null)) { |
813 |
0
|
out.write("**ERROR**: Check the sequences of request numbers in both files, they differ."); |
814 |
0
|
out.newLine(); |
815 |
|
} |
816 |
1
|
else if ((decision1 != null) || (decision2 != null)) { |
817 |
0
|
if (decision1 == null) { |
818 |
0
|
out.write("**WARNING**: The first file is shorter than the second one"); |
819 |
0
|
out.newLine(); |
820 |
|
} |
821 |
|
else { |
822 |
0
|
out.write("**WARNING**: The second file is shorter than the first one"); |
823 |
0
|
out.newLine(); |
824 |
|
} |
825 |
|
} |
826 |
1
|
in1.close();in2.close(); |
827 |
1
|
out.flush(); out.close(); |
828 |
|
} |
829 |
|
catch (Exception e) |
830 |
|
{ |
831 |
1
|
e.printStackTrace(); |
832 |
|
} |
833 |
|
} |
834 |
|
|
835 |
|
|
836 |
|
|
837 |
|
|
838 |
|
@param |
839 |
|
@return |
840 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
841 |
1
|
protected byte[] getRequestHash(String rqFile) {... |
842 |
|
|
843 |
1
|
try { |
844 |
1
|
MessageDigest md = MessageDigest.getInstance("SHA"); |
845 |
1
|
FileInputStream fis = new FileInputStream(rqFile); |
846 |
1
|
byte[] content = new byte[fis.available()]; |
847 |
1
|
int nb = fis.read(content); |
848 |
2
|
while (nb != -1) { |
849 |
1
|
md.update(content,0,nb); |
850 |
1
|
nb = fis.read(content); |
851 |
|
} |
852 |
1
|
byte[] result = md.digest(); |
853 |
1
|
return result; |
854 |
|
} catch (Exception e) { |
855 |
0
|
e.printStackTrace(); |
856 |
0
|
return null; |
857 |
|
} |
858 |
|
|
859 |
|
} |
860 |
|
|
861 |
|
|
862 |
|
|
863 |
|
|
864 |
|
|
865 |
|
|
866 |
|
|
867 |
|
|
868 |
|
|
869 |
|
|
870 |
|
|
871 |
|
@param |
872 |
|
@param |
873 |
|
@param |
874 |
|
@param |
875 |
|
@param |
876 |
|
@return |
877 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 4 |
Complexity Density: 0.19 |
|
878 |
0
|
protected boolean writeDiffHeader(java.io.BufferedWriter out, String[] h1, String[] h2, String f1, String f2) {... |
879 |
0
|
try { |
880 |
0
|
out.write("CHECKING " + f1 + " against " + f2); out.newLine(); |
881 |
0
|
if (h1[1].intern() == h2[1].intern()) { |
882 |
0
|
out.write("Both files are related to the same requests, i.e. same hash: <"+h1[1]+">"); |
883 |
0
|
out.newLine(); |
884 |
|
} |
885 |
|
else { |
886 |
0
|
out.write("WARNING: Decisions correspond to different request files"); |
887 |
0
|
out.newLine(); |
888 |
0
|
out.write(" Hash of File 1 <"+h1[1]+">"); out.newLine(); |
889 |
0
|
out.write(" Hash of File 2 <"+h2[1]+">"); out.newLine(); |
890 |
|
} |
891 |
|
|
892 |
0
|
java.util.Date date1 = new java.text.SimpleDateFormat().parse(h1[2]); |
893 |
0
|
java.util.Date date2 = new java.text.SimpleDateFormat().parse(h2[2]); |
894 |
|
|
895 |
0
|
if (date1.before(date2)) { |
896 |
0
|
out.write("File "+ f2 + " is newer than file " + f1); out.newLine(); |
897 |
|
} |
898 |
|
else { |
899 |
0
|
out.write("File "+ f1 + " is newer than file " + f2); out.newLine(); |
900 |
|
} |
901 |
0
|
return true; |
902 |
|
} |
903 |
|
catch (Exception e) { |
904 |
0
|
return false; |
905 |
|
} |
906 |
|
} |
907 |
|
|
|
|
| 54.5% |
Uncovered Elements: 5 (11) |
Complexity: 5 |
Complexity Density: 0.56 |
|
908 |
1
|
public void loadXML(... |
909 |
|
String filename) { |
910 |
1
|
try { |
911 |
1
|
try{ |
912 |
1
|
if (filename.endsWith(".xml") || filename.endsWith(".XML")) { |
913 |
1
|
isXML = true; |
914 |
1
|
pfinder = new issrg.simplePERMIS.SimplePERMISPolicyFinder(filename); |
915 |
|
} else { |
916 |
0
|
throw new Exception("Failed to load XML Policy from [" + filename + "]"); |
917 |
|
} }catch(java.io.FileNotFoundException e){ |
918 |
0
|
System.err.println(e.getMessage()); |
919 |
|
} |
920 |
|
} catch (Throwable th) { |
921 |
0
|
System.err.println("Failed to load XML from [" + filename + "]"); |
922 |
0
|
th.printStackTrace(); |
923 |
|
|
924 |
|
} |
925 |
|
} |
926 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
927 |
720
|
protected void authenticate(java.security.Principal user){... |
928 |
|
} |
929 |
|
} |