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 |
|
package issrg.test; |
56 |
|
|
57 |
|
|
58 |
|
import issrg.pba.PbaException; |
59 |
|
import issrg.pba.Response; |
60 |
|
import issrg.pba.rbac.PermisAction; |
61 |
|
import issrg.pba.rbac.PermisRBAC; |
62 |
|
import issrg.pba.rbac.PermisTarget; |
63 |
|
import issrg.simplePERMIS.SimplePERMISPolicyFinder; |
64 |
|
import issrg.simplePERMIS.SimplePERMISToken; |
65 |
|
import issrg.simplePERMIS.SimplePERMISTokenParser; |
66 |
|
import issrg.utils.repository.Entry; |
67 |
|
import java.util.Vector; |
68 |
|
import issrg.pba.Subject; |
69 |
|
import java.io.FileNotFoundException; |
70 |
|
import java.io.FileOutputStream; |
71 |
|
import java.io.PrintStream; |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
@author |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
|
|
| 86.7% |
Uncovered Elements: 16 (120) |
Complexity: 18 |
Complexity Density: 0.29 |
|
101 |
|
public class SimpleTesting { |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
2
|
public SimpleTesting() {... |
107 |
2
|
System.setProperty("line.separator", "\r\n"); |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
private SimplePERMISTokenParser testParserTok = null; |
129 |
|
|
130 |
|
private PermisRBAC adf = null; |
131 |
|
private SimplePERMISPolicyFinder ssampf=null; |
132 |
|
|
133 |
|
|
134 |
|
private Subject subject=null; |
135 |
|
private PermisAction action=null; |
136 |
|
private PermisTarget target=null; |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
protected String[] m_users; |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
protected String[] m_roles; |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
protected String[] m_issuers; |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
protected String[] m_actions; |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
protected String[] m_targets; |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
@param |
169 |
|
|
170 |
|
|
|
|
| 35.7% |
Uncovered Elements: 9 (14) |
Complexity: 4 |
Complexity Density: 0.33 |
|
171 |
2
|
public boolean loadPolicy(String pathNameofPolicy){... |
172 |
2
|
try{ |
173 |
|
|
174 |
2
|
ssampf = new SimplePERMISPolicyFinder(pathNameofPolicy); |
175 |
|
|
176 |
|
}catch (Exception e){ |
177 |
0
|
System.out.println("Exception was thrown in loading policy!"); |
178 |
0
|
System.out.println(e.getMessage()); |
179 |
0
|
ssampf=null; |
180 |
|
}catch(Throwable th){ |
181 |
0
|
System.out.println("Throwable was thrown in loading policy!"); |
182 |
0
|
System.out.println(th.getMessage()); |
183 |
0
|
ssampf=null; |
184 |
|
} |
185 |
|
|
186 |
2
|
if (ssampf == null){ |
187 |
0
|
System.out.println("Null PolicyFinder was returned!"); |
188 |
0
|
return false; |
189 |
|
} |
190 |
2
|
return true; |
191 |
|
|
192 |
|
|
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
@return |
198 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
199 |
2
|
public boolean constructADF(){... |
200 |
|
|
201 |
2
|
try{ |
202 |
2
|
adf = new PermisRBAC(ssampf); |
203 |
|
} catch(PbaException pe){ |
204 |
0
|
System.out.println(pe.getMessage()); |
205 |
0
|
return false; |
206 |
|
} |
207 |
|
|
208 |
2
|
return true; |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
@param |
215 |
|
@param |
216 |
|
@param |
217 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 2 |
Complexity Density: 0.15 |
|
218 |
594
|
public boolean constructSubject(String userDN,String roleValue, String issuerLDAPDN){... |
219 |
|
|
220 |
|
|
221 |
|
|
222 |
594
|
this.subject=null; |
223 |
|
|
224 |
594
|
SimplePERMISToken subjectToken=null; |
225 |
|
|
226 |
594
|
Entry issuer = null; |
227 |
|
|
228 |
594
|
String roleType = ""; |
229 |
|
|
230 |
594
|
roleType = "permisRole"; |
231 |
|
|
232 |
594
|
subjectToken = new SimplePERMISToken(userDN, issuerLDAPDN, roleType, roleValue); |
233 |
|
|
234 |
594
|
Vector newCreds = new Vector(); |
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
594
|
newCreds.add(subjectToken); |
241 |
594
|
try{ |
242 |
|
|
243 |
594
|
subject = adf.getCreds(subjectToken.getHolderEntry().getEntryName(), newCreds.toArray()); |
244 |
|
}catch(PbaException pbaE){ |
245 |
198
|
subject=null; |
246 |
198
|
return false; |
247 |
|
} |
248 |
|
|
249 |
396
|
return true; |
250 |
|
} |
251 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
252 |
594
|
public boolean constructAction(String actionName){... |
253 |
|
|
254 |
|
|
255 |
594
|
action=null; |
256 |
|
|
257 |
|
|
258 |
|
|
259 |
594
|
action = new PermisAction(actionName); |
260 |
|
|
261 |
594
|
return true; |
262 |
|
} |
263 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
264 |
594
|
public boolean constructTarget(String targetDN){... |
265 |
|
|
266 |
594
|
target = null; |
267 |
|
|
268 |
|
|
269 |
|
|
270 |
594
|
try{ |
271 |
594
|
target = new PermisTarget(targetDN, null); |
272 |
|
}catch(issrg.utils.RFC2253ParsingException rfcExc){ |
273 |
0
|
return false; |
274 |
|
} |
275 |
|
|
276 |
594
|
return true; |
277 |
|
|
278 |
|
} |
279 |
|
|
280 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
281 |
594
|
public Response consult() throws PbaException{... |
282 |
|
|
283 |
594
|
return adf.authzDecision(this.subject,this.action,this.target,null); |
284 |
|
|
285 |
|
} |
286 |
|
|
287 |
|
|
288 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
289 |
2
|
public void prepareTestCases(String[] users,String[] roles, String[] issuers, String[] actions, String[] targets){... |
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
2
|
m_users=users; |
298 |
2
|
m_roles=roles; |
299 |
2
|
m_issuers=issuers; |
300 |
2
|
m_actions=actions; |
301 |
2
|
m_targets=targets; |
302 |
|
|
303 |
|
} |
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
@param |
308 |
|
@param |
309 |
|
|
|
|
| 92.6% |
Uncovered Elements: 4 (54) |
Complexity: 11 |
Complexity Density: 0.29 |
|
310 |
2
|
public void test(String policyfileName,String outputResult) {... |
311 |
|
|
312 |
2
|
String input=null; |
313 |
|
|
314 |
|
|
315 |
2
|
String userDN; |
316 |
2
|
String roleValue; |
317 |
2
|
String actionName; |
318 |
2
|
String targetDN; |
319 |
|
|
320 |
2
|
Response rsp; |
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
2
|
if(this.loadPolicy(policyfileName)==false){ |
331 |
0
|
System.out.println("Failed to load policy!"); |
332 |
|
} |
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
2
|
this.constructADF(); |
339 |
2
|
int iCaseID=0; |
340 |
2
|
try{ |
341 |
2
|
System.setOut(new PrintStream(new FileOutputStream(outputResult))); |
342 |
|
}catch(FileNotFoundException fnf){ |
343 |
0
|
System.out.println(" File Not found : " + fnf.getMessage()); |
344 |
|
} |
345 |
|
|
346 |
2
|
try{ |
347 |
|
|
348 |
2
|
String log; |
349 |
|
|
350 |
8
|
for(int i=0;i < m_users.length;i++) |
351 |
27
|
for(int j=0; j<m_roles.length;j++) |
352 |
|
|
353 |
84
|
for(int l=0;l<m_actions.length;l++) |
354 |
225
|
for(int m=0;m<m_targets.length;m++) |
355 |
756
|
for(int k=0;k<m_issuers.length;k++) |
356 |
|
{ |
357 |
594
|
iCaseID++; |
358 |
594
|
System.out.println(); |
359 |
594
|
System.out.println("CaseID: " + iCaseID ); |
360 |
594
|
System.out.println("User\t: " + m_users[i]); |
361 |
594
|
System.out.println("Role\t: " + m_roles[j]); |
362 |
594
|
System.out.println("Issuer\t: "+ m_issuers[k]); |
363 |
594
|
System.out.println("Action\t: "+ m_actions[l]); |
364 |
594
|
System.out.println( "Target\t: " + m_targets[m]); |
365 |
594
|
rsp=simulate(m_users[i],m_roles[j],m_issuers[k],m_actions[l],m_targets[m]); |
366 |
594
|
if(rsp!=null){ |
367 |
228
|
log="Result\t: "; |
368 |
228
|
if(rsp.isAuthorised()==true) |
369 |
7
|
log+="True"; |
370 |
|
else |
371 |
221
|
log+="false"; |
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
228
|
System.out.println(log); |
381 |
|
|
382 |
|
}else{ |
383 |
366
|
System.out.println("Null Response"); |
384 |
|
} |
385 |
|
} |
386 |
|
|
387 |
|
}catch(Exception e){ |
388 |
0
|
e=null; |
389 |
|
} |
390 |
|
|
391 |
2
|
System.out.close(); |
392 |
|
} |
393 |
|
|
394 |
|
|
395 |
|
|
396 |
|
|
397 |
|
@param |
398 |
|
@param |
399 |
|
@param |
400 |
|
@param |
401 |
|
@param |
402 |
|
@param |
403 |
|
|
404 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
405 |
594
|
private Response simulate(final String userDN, final String roleValue, final String issuer, final String actionName, final String targetDN ) {... |
406 |
|
|
407 |
|
|
408 |
594
|
this.constructSubject(userDN,roleValue, issuer); |
409 |
594
|
constructAction(actionName); |
410 |
594
|
constructTarget(targetDN); |
411 |
|
|
412 |
594
|
Response pdpResponse=null; |
413 |
|
|
414 |
594
|
try{ |
415 |
|
|
416 |
594
|
pdpResponse=consult(); |
417 |
|
|
418 |
228
|
return pdpResponse; |
419 |
|
|
420 |
|
}catch(PbaException e){ |
421 |
366
|
System.out.println("** Exception :"+ e.getMessage()); |
422 |
366
|
return pdpResponse; |
423 |
|
|
424 |
|
} |
425 |
|
} |
426 |
|
|
427 |
|
} |