Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
176   356   20   35.2
18   200   0.14   5
5     4.8  
1    
 
 
  TestDS       Line # 83 176 20 93.5% 0.93467337
 
  (1)
 
1    /*
2    * Copyright (c) 2006, University of Kent
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * Redistributions of source code must retain the above copyright notice, this
9    * list of conditions and the following disclaimer.
10    *
11    * Redistributions in binary form must reproduce the above copyright notice,
12    * this list of conditions and the following disclaimer in the documentation
13    * and/or other materials provided with the distribution.
14    *
15    * 1. Neither the name of the University of Kent nor the names of its
16    * contributors may be used to endorse or promote products derived from this
17    * software without specific prior written permission.
18    *
19    * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22    * PURPOSE ARE DISCLAIMED.
23    *
24    * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31    * POSSIBILITY OF SUCH DAMAGE.
32    *
33    * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
34    * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
35    * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
36    * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
37    * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
38    * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
39    * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
40    * SERIOUS FAULTS, IN THIS SOFTWARE.
41    *
42    * 5. This license is governed, except to the extent that local laws
43    * necessarily apply, by the laws of England and Wales.
44    */
45   
46    /*
47    * TestDS.java
48    *
49    * Created on December 14, 2005, 10:25 AM
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    //import org.apache.log4j.Logger;
74    //import org.apache.log4j.BasicConfigurator;
75   
76   
77   
78   
79    /**
80    *
81    * @author anhnt
82    */
 
83    public class TestDS extends DISTestNew {
84    // static Logger log = Logger.getLogger(TestDS.class);
85    // static org.apache.log4j.Appender appender;
86    // static org.apache.log4j.Layout layout = new org.apache.log4j.PatternLayout("[%t] %-5p %c %x - %m%n");
87   
88   
89    /** Creates a new instance of TestDS */
 
90  1 toggle public TestDS(String path) throws Exception {
91  1 super(path);
92    // log.setLevel(org.apache.log4j.Level.OFF);
93    // appender = new org.apache.log4j.WriterAppender(layout, System.out);
94    // BasicConfigurator.configure(appender);
95    }
 
96  1 toggle public void initialize(issrg.utils.repository.AttributeRepository r, String path) {
97  1 try {
98    // log.setLevel(org.apache.log4j.Level.ERROR);
99  1 issrg.test.ds.VirtualLDAP repository = (issrg.test.ds.VirtualLDAP) r;
100  1 String separator = System.getProperties().getProperty("file.separator");
101    // log.info("Geting the policy");
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    // log.fatal("policy file is not found");
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    // log.info(soaCerPath);
118  1 try {
119  1 reader = new FileInputStream(soaCerPath);
120    } catch(FileNotFoundException fnfe) {
121    // log.fatal("soa certificate is not found");
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    // log.info(disCerPath);
131  1 try {
132  1 reader = new FileInputStream(disCerPath);//reader = this.getClass().getResourceAsStream(disCerPath);
133    } catch(FileNotFoundException fnfe) {
134    // log.fatal("dis certificate is not found");
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    // log.info("disACPath");
144  1 try {
145  1 reader = new FileInputStream(disACPath);//reader = this.getClass().getResourceAsStream(disACPath);
146    } catch(FileNotFoundException fnfe) {
147    // log.fatal("dis AC is not found");
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   
 
158  30 toggle 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   
 
166  1 toggle public void testIssuing() {
167    // log.debug("Starting the issuing process");
168   
169    //NOTE: I HOPE THE TESTS HERE ARE ENOUGH FOR THE TESTING THE PDP. COMPARE TO OSCAR'S TESTS, THIS TEST SUITE HAS MUCH MORE ACs
170  1 int count = 1;
171   
172    //ISSSUED BY SOA
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    //issue to outside world
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    //issue to aa1
194   
195    //this is testing for both summer time and GMT time
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    //issue to student1
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    //ISSUED BY DIS
216   
217    //issue to admin1
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    //issue to DIS
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    //issue to aa2
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    //ISSUED BY AA1
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    //ISSUED BY AA2
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    //ISSUED BY AA3
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    //ISSUED BY STUDENT1
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    // log.debug("Issuing process is done");
291    }
292   
 
293  1 toggle 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    // log.fatal(args[0] + " is not found");
302  0 return;
303    }
304   
305  1 try {
306  1 PermisRBAC pba = null;
307    // log.debug("Setting the clock");
308  1 CustomisePERMIS.setSystemClock("issrg.test.ds.PermisRBACDISTest");
309  1 PermisRBACDISTest theClock = (PermisRBACDISTest)CustomisePERMIS.getSystemClock();
310    // log.debug("Initializing the PermisRBAC");
311  1 pba = new PermisRBAC(new RepositoryACPolicyFinder(r, OID, new LDAPDNPrincipal(SOA), sv), r, tokenParser);
312    // log.debug("PermisRBAC is initialized");
313    //Vector arguments = new Vector();
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){ /* ignore it */ }
336  124 if (proto!=null && URLHandler.getURLHandler(proto)!=null){ // it is a URL then
337  0 target = new PermisTarget(rhs);
338    }else{ // well, it must be a LDAP DN then
339  124 target = new PermisTarget(rhs, null); // this time it is treated as a DN + a null array of object classes
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    }