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 |
|
package issrg.test.ds; |
53 |
|
|
54 |
|
import issrg.pba.Action; |
55 |
|
import issrg.pba.Subject; |
56 |
|
import issrg.pba.rbac.BadURLException; |
57 |
|
import issrg.pba.rbac.CustomisePERMIS; |
58 |
|
import issrg.pba.rbac.LDAPDNPrincipal; |
59 |
|
import issrg.pba.rbac.PermisAction; |
60 |
|
import issrg.pba.rbac.PermisRBAC; |
61 |
|
import issrg.pba.rbac.PermisTarget; |
62 |
|
import issrg.pba.rbac.URLHandler; |
63 |
|
import issrg.pba.rbac.x509.RepositoryACPolicyFinder; |
64 |
|
import java.io.BufferedReader; |
65 |
|
import java.io.File; |
66 |
|
import java.io.FileInputStream; |
67 |
|
import java.io.FileNotFoundException; |
68 |
|
import java.io.IOException; |
69 |
|
import java.io.InputStream; |
70 |
|
import java.io.InputStreamReader; |
71 |
|
import java.util.Hashtable; |
72 |
|
import java.util.Map; |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@author |
82 |
|
|
|
|
| 93.5% |
Uncovered Elements: 13 (199) |
Complexity: 20 |
Complexity Density: 0.14 |
|
83 |
|
public class TestDS extends DISTestNew { |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
1
|
public TestDS(String path) throws Exception { ... |
91 |
1
|
super(path); |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
} |
|
|
| 86.5% |
Uncovered Elements: 5 (37) |
Complexity: 6 |
Complexity Density: 0.16 |
|
96 |
1
|
public void initialize(issrg.utils.repository.AttributeRepository r, String path) { ... |
97 |
1
|
try { |
98 |
|
|
99 |
1
|
issrg.test.ds.VirtualLDAP repository = (issrg.test.ds.VirtualLDAP) r; |
100 |
1
|
String separator = System.getProperties().getProperty("file.separator"); |
101 |
|
|
102 |
1
|
String policyPath = path.concat(separator); |
103 |
1
|
policyPath = policyPath.concat("policy.ace"); |
104 |
1
|
java.io.InputStream reader = null; |
105 |
1
|
try { |
106 |
1
|
reader = new FileInputStream(policyPath); |
107 |
|
} catch(FileNotFoundException fnfe) { |
108 |
|
|
109 |
0
|
throw fnfe; |
110 |
|
} |
111 |
1
|
byte[] policy = new byte[reader.available()]; |
112 |
1
|
reader.read(policy); |
113 |
1
|
repository.populate(SOA.toUpperCase(), AC_attribute, policy); |
114 |
|
|
115 |
1
|
String soaCerPath = path.concat(separator); |
116 |
1
|
soaCerPath = soaCerPath.concat("soacert.cer"); |
117 |
|
|
118 |
1
|
try { |
119 |
1
|
reader = new FileInputStream(soaCerPath); |
120 |
|
} catch(FileNotFoundException fnfe) { |
121 |
|
|
122 |
0
|
throw fnfe; |
123 |
|
} |
124 |
1
|
byte[] soacert = new byte[reader.available()]; |
125 |
1
|
reader.read(soacert); |
126 |
1
|
repository.populate(SOA.toUpperCase(), User_certificate, soacert); |
127 |
|
|
128 |
1
|
String disCerPath = path.concat(separator); |
129 |
1
|
disCerPath = disCerPath.concat("discert.cer"); |
130 |
|
|
131 |
1
|
try { |
132 |
1
|
reader = new FileInputStream(disCerPath); |
133 |
|
} catch(FileNotFoundException fnfe) { |
134 |
|
|
135 |
0
|
throw fnfe; |
136 |
|
} |
137 |
1
|
byte[] discert = new byte[reader.available()]; |
138 |
1
|
reader.read(discert); |
139 |
1
|
repository.populate(DIS.toUpperCase(), User_certificate, discert); |
140 |
|
|
141 |
1
|
String disACPath = path.concat(separator); |
142 |
1
|
disACPath = disACPath.concat("dis.ace"); |
143 |
|
|
144 |
1
|
try { |
145 |
1
|
reader = new FileInputStream(disACPath); |
146 |
|
} catch(FileNotFoundException fnfe) { |
147 |
|
|
148 |
0
|
throw fnfe; |
149 |
|
} |
150 |
1
|
byte[] disAC = new byte[reader.available()]; |
151 |
1
|
reader.read(disAC); |
152 |
1
|
repository.populate(DIS.toUpperCase(), AC_attribute, disAC); |
153 |
|
} catch (Exception e) { |
154 |
0
|
e.printStackTrace(); |
155 |
|
} |
156 |
|
} |
157 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
158 |
30
|
public void doIssuing(int count, String issuer, String holder, String[] roleValues, String roleType, String from, String to, String _assert, String depth) {... |
159 |
30
|
try { |
160 |
30
|
String ret = signForMe(issuer, holder, roleValues, roleType, from, to, _assert, depth); |
161 |
|
} catch (Exception e) { |
162 |
0
|
e.printStackTrace(); |
163 |
|
} |
164 |
|
} |
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (91) |
Complexity: 1 |
Complexity Density: 0.01 |
1
PASS
|
|
166 |
1
|
public void testIssuing() {... |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
1
|
int count = 1; |
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
1
|
String[] roles = new String[] {"Admin"}; |
176 |
1
|
doIssuing(count, "cn=soa,ou=admin,o=permis,c=gb", "cn=dis,ou=admin,o=permis,c=gb", roles, "permisRole", "2004.01.01 00:00:00", "2010.01.01 00:00:00", "cannot", "0"); count++; |
177 |
|
|
178 |
|
|
179 |
1
|
roles = new String[] {"Admin", "Professor"}; |
180 |
1
|
doIssuing(count, "cn=soa,ou=admin,o=permis,c=gb", "cn=admin1,ou=admin,o=permis,c=gb", roles, "permisRole", "2003.01.01 00:00:00", "2011.01.01 00:00:00", "cannot", "0"); count++; |
181 |
|
|
182 |
1
|
roles = new String[] {"Student", "Researcher"}; |
183 |
1
|
doIssuing(count, "cn=soa,ou=admin,o=permis,c=gb", "cn=admin1,ou=admin,o=permis,c=gb", roles, "permisRole", "2001.01.01 00:00:00", "2006.01.01 00:00:00", "can", "2"); count++; |
184 |
|
|
185 |
|
|
186 |
1
|
roles = new String[] {"Staff"}; |
187 |
1
|
doIssuing(count, "cn=soa,ou=admin,o=permis,c=gb", "cn=admin1,ou=admin,o=permis,c=gb", roles, "perRole", "2005.01.01 00:00:00", "2007.01.01 00:00:00", "can", "2"); count++; |
188 |
|
|
189 |
|
|
190 |
1
|
roles = new String[] {"Staff"}; |
191 |
1
|
doIssuing(count, "cn=soa,ou=admin,o=permis,c=gb", "cn=soa1, o=permis,c=gb", roles, "permisRole", "2005.01.01 00:00:00", "2006.01.01 00:00:00", "can", "2"); count++; |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
1
|
roles = new String[] {"Professor", "Researcher"}; |
197 |
1
|
doIssuing(count, "cn=soa,ou=admin,o=permis,c=gb", "cn=aa1,ou=staff,o=permis,c=gb", roles, "permisRole", "2004.06.01 12:00:00", "2007.01.1 12:00:00", "can", "-1"); count++; |
198 |
|
|
199 |
1
|
roles = new String[] {"Professor", "Researcher"}; |
200 |
1
|
doIssuing(count, "cn=soa,ou=admin,o=permis,c=gb", "cn=aa1,ou=staff,o=permis,c=gb", roles, "permisRole", "2004.06.01 12:00:00", "2007.08.27 12:00:00", "can", "-1"); count++; |
201 |
|
|
202 |
1
|
roles = new String[] {"Professor", "Staff"}; |
203 |
1
|
doIssuing(count, "cn=soa,ou=admin,o=permis,c=gb", "cn=aa1,ou=staff,o=permis,c=gb", roles, "permisRole", "2004.06.01 12:00:00", "2007.08.27 12:00:00", "can", "0"); count++; |
204 |
|
|
205 |
1
|
roles = new String[] {"Student", "Researcher"}; |
206 |
1
|
doIssuing(count, "cn=soa,ou=admin,o=permis,c=gb", "cn=aa1,ou=staff,o=permis,c=gb", roles, "permisRole", "2004.06.01 12:00:00", "2007.08.27 12:00:00", "can", "2"); count++; |
207 |
|
|
208 |
|
|
209 |
1
|
roles = new String[] {"Student"}; |
210 |
1
|
doIssuing(count, "cn=soa,ou=admin,o=permis,c=gb", "cn=student1,ou=student,o=permis,c=gb", roles, "permisRole", "2004.06.10 12:00:00", "2007.08.27 12:00:00", "can", "2"); count++; |
211 |
|
|
212 |
1
|
roles = new String[] {"Professor", "Student"}; |
213 |
1
|
doIssuing(count, "cn=soa,ou=admin,o=permis,c=gb", "cn=student1,ou=student,o=permis,c=gb", roles, "permisRole", "2003.06.01 12:00:00", "2008.08.27 12:00:00", "can", "-1"); count++; |
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
1
|
roles = new String[] {"Admin"}; |
219 |
1
|
doIssuing(count, "cn=dis,ou=admin,o=permis,c=gb", "cn=admin1,ou=admin,o=permis,c=gb", roles, "permisRole", "2004.01.01 12:00:00", "2010.01.01 12:00:00", "cannot", "0"); count++; |
220 |
|
|
221 |
|
|
222 |
1
|
roles = new String[] {"Admin"}; |
223 |
1
|
doIssuing(count, "cn=dis,ou=admin,o=permis,c=gb", "cn=admin1,ou=admin,o=permis,c=gb", roles, "permisRole", "2004.01.01 12:00:00", "2009.05.01 12:00:00", "can", "1"); count++; |
224 |
|
|
225 |
1
|
roles = new String[] {"Admin", "Professor"}; |
226 |
1
|
doIssuing(count, "cn=dis,ou=admin,o=permis,c=gb", "cn=admin1,ou=admin,o=permis,c=gb", roles, "permisRole", "2003.01.01 00:00:00", "2011.01.01 00:00:00", "cannot", "0"); count++; |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
1
|
roles = new String[] {"Admin", "Professor"}; |
231 |
1
|
doIssuing(count, "cn=dis,ou=admin,o=permis,c=gb", "cn=dis,ou=admin,o=permis,c=gb", roles, "permisRole", "2006.01.01 00:00:00", "2009.01.01 00:00:00", "cannot", "0"); count++; |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
1
|
roles = new String[] {"Professor", "Researcher"}; |
236 |
1
|
doIssuing(count, "cn=dis,ou=admin,o=permis,c=gb", "cn=aa2,ou=staff,o=permis,c=gb", roles, "permisRole", "2004.06.01 12:00:00", "2007.08.27 12:00:00", "cannot", "0"); count++; |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
1
|
roles = new String[] {"Student", "Researcher"}; |
241 |
1
|
doIssuing(count, "cn=aa1,ou=staff,o=permis,c=gb", "cn=aa1,ou=staff,o=permis,c=gb", roles, "permisRole", "2004.06.01 12:00:00", "2007.08.27 12:00:00", "can", "2"); count++; |
242 |
|
|
243 |
1
|
roles = new String[] {"Student"}; |
244 |
1
|
doIssuing(count, "cn=aa1,ou=staff,o=permis,c=gb", "cn=student1,ou=student,o=permis,c=gb", roles, "permisRole", "2004.06.01 12:00:00", "2007.08.27 12:00:00", "can", "2"); count++; |
245 |
|
|
246 |
1
|
roles = new String[] {"Researcher"}; |
247 |
1
|
doIssuing(count, "cn=aa1,ou=staff,o=permis,c=gb", "cn=aa2,ou=staff,o=permis,c=gb", roles, "permisRole", "2004.03.01 00:00:00", "2007.08.27 12:00:00", "can", "2"); count++; |
248 |
|
|
249 |
1
|
roles = new String[] {"Professor"}; |
250 |
1
|
doIssuing(count, "cn=aa1,ou=staff,o=permis,c=gb", "cn=aa3,ou=staff,o=permis,c=gb", roles, "permisRole", "2005.01.01 00:00:00", "2007.08.27 00:00:00", "can", "1"); count++; |
251 |
|
|
252 |
1
|
roles = new String[] {"Professor", "Researcher"}; |
253 |
1
|
doIssuing(count, "cn=aa1,ou=staff,o=permis,c=gb", "cn=aa4,ou=staff,o=permis,c=gb", roles, "permisRole", "2005.01.01 00:00:00", "2007.08.27 00:00:00", "can", "0"); count++; |
254 |
|
|
255 |
|
|
256 |
|
|
257 |
1
|
roles = new String[] {"Student"}; |
258 |
1
|
doIssuing(count, "cn=aa2,ou=staff,o=permis,c=gb", "cn=student1,ou=student,o=permis,c=gb", roles, "permisRole", "2004.06.01 12:00:00", "2007.08.27 12:00:00", "can", "2"); count++; |
259 |
|
|
260 |
1
|
roles = new String[] {"Professor", "Researcher"}; |
261 |
1
|
doIssuing(count, "cn=aa2,ou=staff,o=permis,c=gb", "cn=aa5,ou=staff,o=permis,c=gb", roles, "permisRole", "2005.01.01 00:00:00", "2010.01.01 00:00:00", "can", "0"); count++; |
262 |
|
|
263 |
1
|
roles = new String[] {"Researcher"}; |
264 |
1
|
doIssuing(count, "cn=aa2,ou=staff,o=permis,c=gb", "cn=aa5,ou=staff,o=permis,c=gb", roles, "permisRole", "2005.01.01 00:00:00", "2006.05.01 00:00:00", "can", "0"); count++; |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
1
|
roles = new String[] {"Researcher"}; |
270 |
1
|
doIssuing(count, "cn=aa3,ou=staff,o=permis,c=gb", "cn=aa5,ou=staff,o=permis,c=gb", roles, "permisRole", "2005.01.01 00:00:00", "2006.05.01 00:00:00", "can", "0"); count++; |
271 |
|
|
272 |
|
|
273 |
1
|
roles = new String[] {"Professor"}; |
274 |
1
|
doIssuing(count, "cn=aa3,ou=staff,o=permis,c=gb", "cn=aa5,ou=staff,o=permis,c=gb", roles, "permisRole", "2005.01.01 00:00:00", "2006.05.01 00:00:00", "can", "0"); count++; |
275 |
|
|
276 |
1
|
roles = new String[] {"Professor"}; |
277 |
1
|
doIssuing(count, "cn=aa3,ou=staff,o=permis,c=gb", "cn=admin1,ou=admin,o=permis,c=gb", roles, "permisRole", "2005.01.01 00:00:00", "2006.05.01 00:00:00", "can", "0"); count++; |
278 |
|
|
279 |
|
|
280 |
|
|
281 |
1
|
roles = new String[] {"Student"}; |
282 |
1
|
doIssuing(count, "cn=student1,ou=student,o=permis,c=gb", "cn=student2,ou=student,o=permis,c=gb", roles, "permisRole", "2005.01.01 00:00:00", "2006.05.01 00:00:00", "can", "0"); count++; |
283 |
|
|
284 |
1
|
roles = new String[] {"Professor"}; |
285 |
1
|
doIssuing(count, "cn=student1,ou=student,o=permis,c=gb", "cn=student2,ou=student,o=permis,c=gb", roles, "permisRole", "2000.01.01 00:00:00", "2007.08.27 02:00:00", "can", "0"); count++; |
286 |
|
|
287 |
1
|
roles = new String[] {"Student"}; |
288 |
1
|
doIssuing(count, "cn=student1,ou=student,o=permis,c=gb", "cn=student5,ou=student,o=permis,c=gb", roles, "permisRole", "2005.01.01 00:00:00", "2006.05.01 00:00:00", "can", "0"); count++; |
289 |
|
|
290 |
|
|
291 |
|
} |
292 |
|
|
|
|
| 88.7% |
Uncovered Elements: 7 (62) |
Complexity: 14 |
Complexity Density: 0.32 |
|
293 |
1
|
public void testPDP(String[] args) { ... |
294 |
1
|
InputStream in = System.in; |
295 |
1
|
File parentDir = null; |
296 |
1
|
try{ |
297 |
1
|
File inFile = new File(args[0]); |
298 |
1
|
in = new FileInputStream(inFile); |
299 |
1
|
parentDir=inFile.getParentFile(); |
300 |
|
}catch(IOException ioe){ |
301 |
|
|
302 |
0
|
return; |
303 |
|
} |
304 |
|
|
305 |
1
|
try { |
306 |
1
|
PermisRBAC pba = null; |
307 |
|
|
308 |
1
|
CustomisePERMIS.setSystemClock("issrg.test.ds.PermisRBACDISTest"); |
309 |
1
|
PermisRBACDISTest theClock = (PermisRBACDISTest)CustomisePERMIS.getSystemClock(); |
310 |
|
|
311 |
1
|
pba = new PermisRBAC(new RepositoryACPolicyFinder(r, OID, new LDAPDNPrincipal(SOA), sv), r, tokenParser); |
312 |
|
|
313 |
|
|
314 |
1
|
LDAPDNPrincipal user=null; |
315 |
1
|
Subject subject=null; |
316 |
1
|
PermisTarget target=null; |
317 |
1
|
Action act = null; |
318 |
1
|
Map env = new Hashtable(); |
319 |
1
|
int count = 0; |
320 |
1
|
BufferedReader br=new BufferedReader(new InputStreamReader(in)); |
321 |
1
|
String s=null; |
322 |
0
|
while((s=br.readLine())!=null){ |
323 |
757
|
if (!s.trim().equals("") && !s.trim().startsWith("#")){ |
324 |
498
|
String instruction = s.substring(0,4).trim(); |
325 |
498
|
String rhs = s.substring(4).trim(); |
326 |
498
|
System.out.println(rhs); |
327 |
498
|
if (instruction.equals("usr")) { |
328 |
124
|
user=new LDAPDNPrincipal(rhs); |
329 |
374
|
} else if (instruction.equals("act")) { |
330 |
124
|
act = new PermisAction(rhs); |
331 |
250
|
} else if (instruction.equals("tgt")) { |
332 |
124
|
String proto = null; |
333 |
124
|
try{ |
334 |
124
|
proto=URLHandler.getProtocolName(rhs); |
335 |
|
}catch(BadURLException bue){ } |
336 |
124
|
if (proto!=null && URLHandler.getURLHandler(proto)!=null){ |
337 |
0
|
target = new PermisTarget(rhs); |
338 |
|
}else{ |
339 |
124
|
target = new PermisTarget(rhs, null); |
340 |
|
} |
341 |
126
|
} else if (instruction.equals("env")) { |
342 |
124
|
theClock.setTime(theClock.toTime(rhs)); |
343 |
124
|
subject=pba.getCreds(user); |
344 |
124
|
System.out.println(++count + ". Decision: "+(pba.decision(subject, act, target, env)?"grant":"deny")); |
345 |
124
|
System.out.println(); |
346 |
2
|
} else if (instruction.equals("prtl")) { |
347 |
2
|
System.out.println("--------------Change user-----------------"); |
348 |
|
} |
349 |
|
} |
350 |
|
} |
351 |
|
|
352 |
|
} catch (Exception e) { |
353 |
0
|
e.printStackTrace(System.out); |
354 |
|
} |
355 |
|
} |
356 |
|
} |