Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
286   534   27   40.86
20   385   0.12   7
7     4.71  
1    
 
 
  CaseSense       Line # 84 286 27 84.3% 0.8434505
 
No Tests
 
1    /*
2    * CaseSense.java
3    *
4    * Created on 10 May 2007, 14:49
5    *
6    * Copyright (c) 2006, University of Kent
7    * All rights reserved.
8    *
9    * Redistribution and use in source and binary forms, with or without
10    * modification, are permitted provided that the following conditions are met:
11    *
12    * Redistributions of source code must retain the above copyright notice, this
13    * list of conditions and the following disclaimer.
14    *
15    * Redistributions in binary form must reproduce the above copyright notice,
16    * this list of conditions and the following disclaimer in the documentation
17    * and/or other materials provided with the distribution.
18    *
19    * 1. Neither the name of the University of Kent nor the names of its
20    * contributors may be used to endorse or promote products derived from this
21    * software without specific prior written permission.
22    *
23    * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26    * PURPOSE ARE DISCLAIMED.
27    *
28    * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35    * POSSIBILITY OF SUCH DAMAGE.
36    *
37    * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
38    * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
39    * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
40    * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
41    * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
42    * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
43    * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
44    * SERIOUS FAULTS, IN THIS SOFTWARE.
45    *
46    * 5. This license is governed, except to the extent that local laws
47    * necessarily apply, by the laws of England and Wales.
48    *
49    * Author : George Inman
50    * Email: g.inman@kent.ac.uk
51    *
52    */
53   
54    package issrg.test;
55   
56    import java.io.IOException;
57    import java.util.ArrayList;
58    import java.util.Map;
59   
60    import issrg.aef.SamplePKI;
61    import issrg.pba.Action;
62    import issrg.pba.ParsedToken;
63    import issrg.pba.PbaException;
64    import issrg.pba.PolicyParser;
65    import issrg.pba.Subject;
66    import issrg.pba.Target;
67    import issrg.pba.rbac.BadURLException;
68    import issrg.pba.rbac.CustomisePERMIS;
69    import issrg.pba.rbac.LDAPDNPrincipal;
70    import issrg.pba.rbac.PermisAction;
71    import issrg.pba.rbac.PermisRBAC;
72    import issrg.pba.rbac.PermisSubject;
73    import issrg.pba.rbac.PermisTarget;
74    import issrg.pba.rbac.PolicyFinder;
75    import issrg.pba.rbac.x509.RepositoryACPolicyFinder;
76    import issrg.simplePERMIS.SimplePERMISPolicyFinder;
77    import issrg.simplePERMIS.SimplePERMISPrincipal;
78    import issrg.simplePERMIS.SimplePERMISSignatureVerifier;
79    import issrg.simplePERMIS.SimplePERMISToken;
80    import issrg.utils.RFC2253ParsingException;
81    import issrg.utils.repository.AttributeRepository;
82    import issrg.utils.repository.VirtualRepository;
83   
 
84    public class CaseSense {
85    static PolicyFinder pfinder = null;
86   
87    static PermisRBAC pbaAPI = null;
88    static PermisRBAC pbaApi2 =null;
89   
 
90  1 toggle public static boolean loadPolicy(String path) {
91   
92  1 try {
93  1 pfinder = new SimplePERMISPolicyFinder(path);
94   
95    } catch (Exception e) {
96  0 out.println(e.getMessage());
97  0 e.printStackTrace();
98  0 pfinder = null;
99    } catch (Throwable th) {
100  0 th.printStackTrace();
101  0 pfinder = null;
102    }
103  1 if (pfinder == null) {
104  0 return false;
105    }
106  1 out.println("The Policy has been loaded");
107  1 return true;
108    }
109   
 
110  18 toggle public static SimplePERMISToken createToken(String holder, String issuer,
111    String type, String value) {
112  18 SimplePERMISToken token = null;
113  18 try {
114   
115  18 token = new SimplePERMISToken(holder, issuer, type, value);
116  18 out.println("holder = " + holder + ",Issuer = " + issuer
117    + ", type = " + type + ",value = " + value);
118    } catch (Exception e) {
119  0 out.println("createToken() failed - An exception occured when creating the token");
120  0 out.println(e.getMessage());
121  0 e.printStackTrace();
122  0 return null;
123    }
124  18 if (token == null) {
125  0 out.println("createToken() failed - Token is null");
126    }
127  18 return token;
128    }
129   
 
130  21 toggle public static String processDecision(Subject s,Action a,Target t){
131  21 try{
132  21 if (!pbaAPI.decision(s, a, t, null)){
133  8 return "1: the action is not allowed";
134    }
135    }catch (issrg.pba.PbaException pe){
136  0 return "2: invalid input: "+pe.getMessage();
137    }catch (Throwable th){
138  0 return "3: run-time error: "+th.getMessage();
139    }
140   
141  13 return "0: action succeeded";
142    }
143   
 
144  1 toggle public static void main(String[]args){
145  1 System.setProperty("line.separator", "\r\n");
146  1 ActionSpace(args);
147  1 out.close();
148    }
149   
150    static java.io.PrintStream out;
151   
 
152  1 toggle static void ActionSpace(String[] args) {
153  1 if (args.length < 3) {
154  0 out.println("These tests must be initalised with a configuration file, a list of attributes and an output file");
155  0 System.exit(1);
156    }
157   
158   
159  1 try{
160  1 out=new java.io.PrintStream(new java.io.FileOutputStream(args[2]));
161    }catch(Exception e){
162  0 e.printStackTrace(out);
163  0 return;
164    }
165    // load test attributes from attribute list
166  1 out.println("##### Loading text attributes into SimplePERMISTokens #####");
167  1 out.println();
168  1 String path = args[0];
169  1 ArrayList atts = new ArrayList();
170  1 try {
171   
172  1 java.io.BufferedReader input = null;
173  1 try {
174  1 input = new java.io.BufferedReader(new java.io.FileReader(path));
175    } catch (java.io.FileNotFoundException e) {
176  0 out.println(e.getMessage());
177  0 e.printStackTrace();
178    }
179  1 String holdername = "";
180  1 String issuer = "";
181  1 String type = "";
182  1 String value = "";
183  1 String s = "";
184   
185  0 while ((s = input.readLine()) != null) {
186   
187  18 holdername = s;
188   
189  18 issuer = input.readLine();
190  18 type = input.readLine();
191  18 value = input.readLine();
192   
193  18 atts.add(createToken(holdername, issuer, type, value));
194    }
195    // test attributes now stored as SimplePERMISTokens in the arraylist
196    // atts
197   
198    } catch (Throwable th) {
199   
200  0 out.println("Failed to load text attribute from [" + path
201    + "]");
202    // th.printStackTrace();
203   
204    }
205    // load the policy
206  1 out.println();
207  1 out.println("##### Loading XML Policy into SimplePERMISPolicyFinder Object #####");
208  1 out.println();
209   
210  1 String XMLfilename = args[1];
211  1 loadPolicy(XMLfilename);
212  1 if (pfinder == null) {
213  0 out.println("fail");
214    } else {
215  1 out.println("Sucess the policy finder has been created");
216    }
217   
218   
219  1 out.println();
220  1 out.println("##### Setting TokenParser for SimplePERMISTokens #####");
221  1 out.println();
222  1 out.println("setting the attribute certificate attribute");
223  1 CustomisePERMIS.setAttributeCertificateAttribute("simpleSAM-Attribute");
224  1 try {
225  1 out.println("setting the Auth Token Parser");
226  1 CustomisePERMIS.setAuthTokenParser("issrg.simplePERMIS.SimplePERMISTokenParser");
227  1 out.println("Success the SimplePERMISTokenPARSER was set as the tokenPArser");
228    } catch (ClassNotFoundException e) {
229  0 out.println("SimplePERMISTokenPARSER was not found");
230  0 e.printStackTrace();
231    }
232  1 loadAC("./src/issrg/test/caseSense/certs/role1-1.ace");
233  1 out.println();
234  1 out.println("##### Creating PermisRBAC decision engine #####");
235  1 out.println();
236   
237  1 try {
238  1 pbaAPI = new PermisRBAC(pfinder);
239   
240  1 try {
241  1 out.println("setting the Auth Token Parser");
242  1 CustomisePERMIS.setAuthTokenParser("issrg.pba.rbac.x509.RoleBasedACParser");
243  1 out.println("Success the RoleBasedACParser was set as the tokenPArser");
244    } catch (ClassNotFoundException e) {
245  0 out.println("RoleBasedACParser was not found");
246  0 e.printStackTrace();
247    }
248   
249  1 issrg.utils.repository.AttributeRepository r = vr;
250  1 issrg.pba.rbac.SignatureVerifier sv = new issrg.aef.SamplePKI();
251  1 pbaApi2 = new PermisRBAC(pfinder,r, null);
252   
253    } catch (PbaException e) {
254   
255  0 out.println(e.getMessage());
256  0 e.printStackTrace();
257    }
258   
259  1 if (pbaAPI == null) {
260  0 out.println("creation of the decision engine failed");
261    } else {
262  1 out.println("creation of the decision engine Succeeded");
263    }
264  1 out.println();
265  1 out.println("##### Creating Valid decision - permisRole (Role0) #####");
266  1 out.println();
267  1 SimplePERMISToken test = (SimplePERMISToken) atts.get(0);
268  1 Object [] tester = new Object[1];
269  1 tester[0] = test;
270  1 createDecision(test,"o=permis,c=gb","Action0");
271   
272  1 out.println();
273  1 out.println("##### Creating invalid decision - permisRole (role0) #####");
274  1 out.println();
275  1 test = (SimplePERMISToken) atts.get(1);
276  1 tester = new Object[1];
277  1 tester[0] = test;
278  1 createDecision(test,"o=permis,c=gb","Action0");
279   
280  1 out.println();
281  1 out.println("##### Creating invalid decision - permisRole (ROLE0) #####");
282  1 out.println();
283  1 test = (SimplePERMISToken) atts.get(2);
284  1 tester = new Object[1];
285  1 tester[0] = test;
286  1 createDecision(test,"o=permis,c=gb","Action0");
287   
288  1 out.println();
289  1 out.println("##### Creating Invalid decision - PERMISROLE (Role0) #####");
290  1 out.println();
291  1 test = (SimplePERMISToken) atts.get(3);
292  1 tester = new Object[1];
293  1 tester[0] = test;
294  1 createDecision(test,"o=permis,c=gb","Action0");
295   
296   
297  1 out.println();
298  1 out.println("##### Creating invalid decision - PERMISROLE (role0) #####");
299  1 out.println();
300  1 test = (SimplePERMISToken) atts.get(4);
301  1 tester = new Object[1];
302  1 tester[0] = test;
303  1 createDecision(test,"o=permis,c=gb","Action0");
304   
305   
306  1 out.println();
307  1 out.println("##### Creating invalid decision - PERMISROLE (ROLE0) #####");
308  1 out.println();
309  1 test = (SimplePERMISToken) atts.get(5);
310  1 tester = new Object[1];
311  1 tester[0] = test;
312  1 createDecision(test,"o=permis,c=gb","Action0");
313   
314   
315  1 out.println();
316  1 out.println("##### Creating Invalid decision - permisrole (Role0) #####");
317  1 out.println();
318  1 test = (SimplePERMISToken) atts.get(6);
319  1 tester = new Object[1];
320  1 tester[0] = test;
321  1 createDecision(test,"o=permis,c=gb","Action0");
322   
323   
324  1 out.println();
325  1 out.println("##### Creating Invalid decision - permisrole (role0) #####");
326  1 out.println();
327  1 test = (SimplePERMISToken) atts.get(7);
328  1 tester = new Object[1];
329  1 tester[0] = test;
330  1 createDecision(test,"o=permis,c=gb","Action0");
331   
332   
333  1 out.println();
334  1 out.println("##### Creating Invalid decision - permisrole (ROLE0) #####");
335  1 out.println();
336  1 test = (SimplePERMISToken) atts.get(8);
337  1 tester = new Object[1];
338  1 tester[0] = test;
339  1 createDecision(test,"o=permis,c=gb","Action0");
340   
341  1 out.println();
342  1 out.println();
343  1 out.println("##### DN TESTS #####");
344   
345  1 out.println();
346  1 out.println("##### Creating Valid decision -Upper Case type -mixed value #####");
347  1 out.println();
348  1 test = (SimplePERMISToken) atts.get(9);
349  1 tester = new Object[1];
350  1 tester[0] = test;
351  1 createDecision(test,"o=permis,c=gb","Action0");
352   
353  1 out.println();
354  1 out.println("##### Creating Valid decision -Upper Case type -Upper value #####");
355  1 out.println();
356  1 test = (SimplePERMISToken) atts.get(10);
357  1 tester = new Object[1];
358  1 tester[0] = test;
359  1 createDecision(test,"o=permis,c=gb","Action0");
360   
361  1 out.println();
362  1 out.println("##### Creating Valid decision -Upper Case type -lower value #####");
363  1 out.println();
364  1 test = (SimplePERMISToken) atts.get(11);
365  1 tester = new Object[1];
366  1 tester[0] = test;
367  1 createDecision(test,"o=permis,c=gb","Action0");
368   
369  1 out.println();
370  1 out.println("##### Creating Valid decision -lower Case type -mixed value #####");
371  1 out.println();
372  1 test = (SimplePERMISToken) atts.get(11);
373  1 tester = new Object[1];
374  1 tester[0] = test;
375  1 createDecision(test,"o=permis,c=gb","Action0");
376   
377  1 out.println();
378  1 out.println("##### Creating Valid decision -lower Case type -Upper value #####");
379  1 out.println();
380  1 test = (SimplePERMISToken) atts.get(10);
381  1 tester = new Object[1];
382  1 tester[0] = test;
383  1 createDecision(test,"o=permis,c=gb","Action0");
384   
385  1 out.println();
386  1 out.println("##### Creating Valid decision -lower Case type -lower value #####");
387  1 out.println();
388  1 test = (SimplePERMISToken) atts.get(11);
389  1 tester = new Object[1];
390  1 tester[0] = test;
391  1 createDecision(test,"o=permis,c=gb","Action0");
392   
393  1 out.println();
394  1 out.println("##### Creating Valid decision -Mixed Case type -mixed value #####");
395  1 out.println();
396  1 test = (SimplePERMISToken) atts.get(11);
397  1 tester = new Object[1];
398  1 tester[0] = test;
399  1 createDecision(test,"o=permis,c=gb","Action0");
400   
401  1 out.println();
402  1 out.println("##### Creating Valid decision -Mixed Case type -Upper value #####");
403  1 out.println();
404  1 test = (SimplePERMISToken) atts.get(10);
405  1 tester = new Object[1];
406  1 tester[0] = test;
407  1 createDecision(test,"o=permis,c=gb","Action0");
408   
409  1 out.println();
410  1 out.println("##### Creating Valid decision -Mixed Case type -lower value #####");
411  1 out.println();
412  1 test = (SimplePERMISToken) atts.get(11);
413  1 tester = new Object[1];
414  1 tester[0] = test;
415  1 createDecision(test,"o=permis,c=gb","Action0");
416   
417  1 out.println();
418  1 out.println("##### Target tests #####");
419  1 out.println();
420  1 out.println("##### Creating Valid decision -lower case target DN #####");
421  1 out.println();
422  1 test = (SimplePERMISToken) atts.get(11);
423  1 tester = new Object[1];
424  1 tester[0] = test;
425  1 createDecision(test,"o=permis,c=gb","Action0");
426   
427  1 out.println();
428  1 out.println("##### Creating Valid decision -upper case target DN #####");
429  1 out.println();
430  1 test = (SimplePERMISToken) atts.get(11);
431  1 tester = new Object[1];
432  1 tester[0] = test;
433  1 createDecision(test,"O=PERMIS,C=GB","Action0");
434   
435  1 out.println();
436  1 out.println("##### Creating Valid decision -mixed case target DN #####");
437  1 out.println();
438  1 test = (SimplePERMISToken) atts.get(11);
439  1 tester = new Object[1];
440  1 tester[0] = test;
441  1 createDecision(test,"o=PermiS,C=gB","Action0");
442    }
443   
444   
445   
446    static VirtualRepository vr = new VirtualRepository();
 
447  1 toggle public static void loadAC(
448    String filename) {
449  1 try {
450   
451  1 java.io.InputStream io = new java.io.FileInputStream(filename);
452  1 byte[] ac = new byte[io.available()];
453   
454  1 io.read(ac);
455   
456  1 issrg.ac.AttributeCertificate acd = issrg.ac.AttributeCertificate
457    .guessEncoding(ac);
458   
459   
460  1 vr.populate(new LDAPDNPrincipal(issrg.ac.Util.generalNamesToString(
461    acd.getACInfo().getHolder().getEntityName()))
462    .getName(), CustomisePERMIS
463    .getAttributeCertificateAttribute(), ac);
464   
465   
466    } catch (Throwable th) {
467  0 out.println("Failed to load AC from [" + filename + "]");
468  0 th.printStackTrace();
469    }}
470   
471   
472   
 
473  21 togglepublic static void createDecision(SimplePERMISToken test, String target, String action){
474   
475  21 Object [] tester = new Object[1];
476  21 SimplePERMISPrincipal principle = null;
477  21 Subject subject = null;
478  21 if (target == null){
479  0 target = "o=PERMIS,c=gb";
480    }
481  21 Action a = null;
482  21 Target t = null;
483  21 if (test != null){
484  21 tester[0] = test;
485   
486  21 principle = new SimplePERMISPrincipal(test.getHolderEntry().getEntryName().getName());
487    //out.println("Simple Permis Token Values :");
488    //out.println("Holder : " + test.getHolderEntry().getEntryName().getName());
489    //out.println("Issuer : " + test.getIssuerTokenLocator().getLocator().getName());
490    //out.println("RoleType : " + test.getAttributeType());
491    //out.println("RoleValue : " + test.getAttributeValue()+ "\n");
492    //out.println("target : " + target );
493    //out.println("action : " + action + "\n");
494   
495  21 try {
496  21 subject = pbaAPI.getCreds(principle, tester);
497  21 out.println(subject.exportCreds().toString());
498    } catch (PbaException e) {
499  0 out.println("Error : " + e.getMessage());
500    }
501   
502  21 out.println("decision returned: ");
503    }else{
504  0 principle = new SimplePERMISPrincipal("cn=User0,o=permis,c=gb");
505  0 try {
506  0 Subject s = pbaApi2.getCreds(principle);
507    } catch (PbaException e) {
508    // TODO Auto-generated catch block
509  0 e.printStackTrace();
510    }
511    }
512   
513   
514  21 try {
515  21 a= new PermisAction(action);
516  21 if (target.startsWith("http://")){
517   
518  0 try {
519  0 t = new PermisTarget(target);
520    } catch (BadURLException e) {
521   
522    }
523    }else{
524  21 t = new PermisTarget(target,null);
525    }
526   
527   
528    } catch (RFC2253ParsingException e1) {
529  0 out.println("Error : " + e1.getMessage());
530    }
531   
532  21 out.println(processDecision(subject,a,t));
533    }
534    }