Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
39   179   12   9.75
8   82   0.38   4
4     3.75  
1    
 
 
  PullFromSimplePERMISWithEmptyDN       Line # 77 39 12 62.7% 0.627451
 
No Tests
 
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    * PullFromSimplePERMISWithEmptyDN.java
47    *
48    * Created on 01 August 2007, 15:58
49    *
50    * To change this template, choose Tools | Template Manager
51    * and open the template in the editor.
52    */
53   
54    package issrg.test.emptyDN;
55   
56    import issrg.pba.PbaException;
57    import issrg.pba.Response;
58    import issrg.pba.rbac.PermisRBAC;
59    import issrg.pba.rbac.LDAPDNPrincipal;
60    import issrg.simplePERMIS.SimplePERMISPolicyFinder;
61    import issrg.simplePERMIS.SimplePERMISToken;
62    import issrg.simplePERMIS.SimplePERMISTokenParser;
63    import issrg.pba.Subject;
64    import issrg.pba.PbaException;
65    import issrg.utils.handler.Config;
66    import issrg.utils.handler.ConfigException;
67    import issrg.utils.RFC2253ParsingException;
68   
69    import java.util.*;
70    import java.io.*;
71   
72    /**
73    *
74    * @author Linying Su
75    */
76   
 
77    public class PullFromSimplePERMISWithEmptyDN {
78   
79    /** Creates a new instance of PullFromSimplePERMISWithEmptyDN */
 
80  0 toggle public PullFromSimplePERMISWithEmptyDN() {
81    }
82   
83    private SimplePERMISTokenParser testParserTok = null;
84   
85    private static PermisRBAC adf = null;
86    private static SimplePERMISPolicyFinder ssampf=null;
87    private static String policy = null;
88    private static Subject subject=null;
89    private static PrintStream out = System.out;
90    private static InputStream in = null;
91    /**
92    * this method is used to test Simple Permis to pull subject attributes with an empty DN
93    * it should return an empty set.
94    */
95   
 
96  1 toggle public static void main(String[] args) {
97   
98  1 System.setProperty("line.separator", "\r\n");
99   
100  1 if (args.length==2){
101  1 Config config = new Config();
102  1 try{
103  1 in = new FileInputStream(config.getURL(args[0]));
104  1 out = new PrintStream(new FileOutputStream(args[1]));
105   
106  1 Properties props = new Properties();
107  1 props.load(in);
108  1 policy = props.getProperty("policy");
109  1 in.close();
110    } catch(IOException ioe){
111  0 out.println("This shouldn't have happened! "+ioe.getMessage());
112    } catch(ConfigException ce){
113  0 out.println("This shouldn't have happened! "+ce.getMessage());
114    }
115    }
116   
117    /*
118    policy="/home/policy/permis/policyForRegressionTest.xml";
119    try {
120    out = new PrintStream(new FileOutputStream("EmptyDNPullSimP.out"));
121    } catch (FileNotFoundException fe) {
122    System.out.println("error: "+fe);
123    }*/
124   
125  1 if (loadPolicy(policy)) out.println("policy is loaded");
126  1 if (constructADF()) out.println("CVS is created");
127  1 try {
128  1 subject = adf.getCreds(new LDAPDNPrincipal(""));
129  1 out.println(subject.exportCreds().toString());
130    } catch (PbaException pe) {
131  0 out.println("error: "+pe);
132    } catch (RFC2253ParsingException re) {
133  0 out.println("error: "+re);
134    }
135  1 out.close();
136    }
137   
138    /**
139    * This function loads the specified policy from an plain xml file.
140    *
141    * @param pathNameofPolicy - The Full file name of the policy file. The file name shall include
142    * the path to allow java vm to locate the file.
143    */
 
144  1 toggle public static boolean loadPolicy(String pathNameofPolicy){
145  1 try{
146  1 ssampf = new SimplePERMISPolicyFinder(pathNameofPolicy);
147    }catch (Exception e){
148  0 out.println("Exception was thrown in loading policy!");
149  0 out.println(e.getMessage());
150  0 ssampf=null;
151    }catch(Throwable th){
152  0 out.println("Throwable was thrown in loading policy!");
153  0 out.println(th.getMessage());
154  0 ssampf=null;
155    }
156   
157  1 if (ssampf == null){
158  0 out.println("Null PolicyFinder was returned!");
159  0 return false;
160    }
161  1 return true;
162    }
163   
164    /**
165    * Contruct the Authorization Decision Function object. This shall be after the policy is loaded.
166    * @return True -- when sucessfully construct the ADF. Otherwise false.
167    */
 
168  1 toggle public static boolean constructADF(){
169    //public static boolean constructADF() throws PbaException {
170  1 try{
171  1 adf = new PermisRBAC(ssampf);
172    } catch(PbaException pe){
173  0 out.println(pe.getMessage());
174  0 return false;
175    }
176   
177  1 return true;
178    }
179    }