Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
155   294   23   25.83
18   233   0.18   6
6     4.67  
1    
 
 
  ActionSpaceTest       Line # 24 155 23 78.2% 0.7821229
 
No Tests
 
1    package issrg.test;
2   
3    import java.io.IOException;
4    import java.io.PrintStream;
5    import java.util.ArrayList;
6   
7    import issrg.pba.Action;
8    import issrg.pba.PbaException;
9    import issrg.pba.Subject;
10    import issrg.pba.Target;
11    import issrg.pba.rbac.BadURLException;
12    import issrg.pba.rbac.CustomisePERMIS;
13    import issrg.pba.rbac.PermisAction;
14    import issrg.pba.rbac.PermisRBAC;
15    import issrg.pba.rbac.PermisSubject;
16    import issrg.pba.rbac.PermisTarget;
17    import issrg.pba.rbac.PolicyFinder;
18    import issrg.simplePERMIS.SimplePERMISPolicyFinder;
19    import issrg.simplePERMIS.SimplePERMISPrincipal;
20    import issrg.simplePERMIS.SimplePERMISToken;
21    import issrg.utils.RFC2253ParsingException;
22    import issrg.utils.repository.VirtualRepository;
23   
 
24    public class ActionSpaceTest {
25    static PolicyFinder pfinder = null;
26   
27    static PermisRBAC pbaAPI = null;
28   
 
29  1 toggle public static boolean loadPolicy(String path) {
30   
31  1 try {
32  1 pfinder = new SimplePERMISPolicyFinder(path);
33    } catch (Exception e) {
34  0 out.println(e.getMessage());
35  0 e.printStackTrace();
36  0 pfinder = null;
37    } catch (Throwable th) {
38  0 th.printStackTrace();
39  0 pfinder = null;
40    }
41  1 if (pfinder == null) {
42  0 return false;
43    }
44    // out.println("[" + path + "] has been loaded"); //changed by Gansen on 1 april 2007. it might output relative path or absolute path, which might cause a failure in the regression test
45  1 return true;
46    }
47   
 
48  2 toggle public static SimplePERMISToken createToken(String holder, String issuer,
49    String type, String value) {
50  2 SimplePERMISToken token = null;
51  2 try {
52   
53  2 token = new SimplePERMISToken(holder, issuer, type, value);
54  2 out.println("holder = " + holder + ",Issuer = " + issuer
55    + ", type = " + type + ",value = " + value);
56    } catch (Exception e) {
57  0 System.out
58    .println("createToken() failed - An exception occured when creating the token");
59  0 out.println(e.getMessage());
60  0 e.printStackTrace();
61  0 return null;
62    }
63  2 if (token == null) {
64  0 out.println("createToken() failed - Token is null");
65    }
66  2 return token;
67    }
68   
 
69  9 toggle public static String processDecision(Subject s,Action a,Target t){
70  9 try{
71  9 if (!pbaAPI.decision(s, a, t, null)){
72  4 return "1: the action is not allowed";
73    }
74    }catch (issrg.pba.PbaException pe){
75  0 return "2: invalid input: "+pe.getMessage();
76    }catch (Throwable th){
77  0 return "3: run-time error: "+th.getMessage();
78    }
79   
80  5 return "0: action succeeded";
81    }
82   
 
83  1 toggle public static void main(String[]args){
84  1 System.setProperty("line.separator", "\r\n");
85  1 ActionSpace(args);
86    }
87   
88    static PrintStream out;
89   
 
90  1 toggle static void ActionSpace(String[] args) {
91  1 if (args.length < 3) {
92  0 System.out
93    .println("These tests must be initalised with a configuration file, a list of attributes and an output file");
94  0 System.exit(1);
95    }
96   
97   
98  1 try{
99   
100  1 out=new java.io.PrintStream(new java.io.FileOutputStream(args[2]));
101    }catch(Exception e){
102  0 e.printStackTrace(System.out);
103  0 return;
104    }
105    // load test attributes from attribute list
106  1 out.println("##### Loading text attributes into SimplePERMISTokens #####\r\n");
107  1 String path = args[1];
108  1 ArrayList atts = new ArrayList();
109  1 try {
110   
111  1 java.io.BufferedReader input = null;
112  1 try {
113  1 input = new java.io.BufferedReader(new java.io.FileReader(path));
114    } catch (java.io.FileNotFoundException e) {
115  0 out.println(e.getMessage());
116  0 e.printStackTrace();
117    }
118  1 String holdername = "";
119  1 String issuer = "";
120  1 String type = "";
121  1 String value = "";
122  1 String s = "";
123   
124  0 while ((s = input.readLine()) != null) {
125   
126  2 holdername = s;
127   
128  2 issuer = input.readLine();
129  2 type = input.readLine();
130  2 value = input.readLine();
131   
132  2 atts.add(createToken(holdername, issuer, type, value));
133    }
134    // test attributes now stored as SimplePERMISTokens in the arraylist
135    // atts
136   
137    } catch (Throwable th) {
138   
139  0 out.println("Failed to load text attribute from [" + path
140    + "]");
141    // th.printStackTrace();
142   
143    }
144    // load the policy
145  1 out.println("\r\n##### Loading XML Policy into SimplePERMISPolicyFinder Object #####\r\n");
146   
147  1 String XMLfilename = args[0];
148  1 loadPolicy(XMLfilename);
149  1 if (pfinder == null) {
150  0 out.println("fail");
151    } else {
152  1 out.println("Sucess the policy finder has been created");
153    }
154   
155  1 out.println("\r\n##### Creating PermisRBAC decision engine #####\r\n");
156   
157  1 try {
158  1 pbaAPI = new PermisRBAC(pfinder);
159    } catch (PbaException e) {
160   
161  0 out.println(e.getMessage());
162  0 e.printStackTrace();
163    }
164   
165  1 if (pbaAPI == null) {
166  0 out.println("creation of the decision engine failed");
167    } else {
168  1 out.println("creation of the decision engine Succeeded");
169    }
170   
171  1 out.println("\r\n##### Setting TokenParser for SimplePERMISTokens #####\r\n");
172  1 out.println("setting the attribute certificate attribute");
173  1 CustomisePERMIS.setAttributeCertificateAttribute("simpleSAM-Attribute");
174  1 try {
175  1 out.println("setting the Auth Token Parser");
176  1 CustomisePERMIS.setAuthTokenParser("issrg.simplePERMIS.SimplePERMISTokenParser");
177  1 out.println("Success the SimplePERMISTokenPARSER was set as the tokenPArser");
178    } catch (ClassNotFoundException e) {
179  0 out.println("SimplePERMISTokenPARSER was not found");
180  0 e.printStackTrace();
181    }
182  1 out.println("\r\n##### Creating Valid decision Action with spaces #####\r\n");
183  1 SimplePERMISToken test = (SimplePERMISToken) atts.get(0);
184  1 Object [] tester = new Object[1];
185  1 tester[0] = test;
186  1 createDecision(test,null,"Action0 Action0");
187   
188  1 out.println("\r\n##### Creating Invalid decision Action without spaces #####\r\n");
189  1 test = (SimplePERMISToken) atts.get(0);
190  1 tester = new Object[1];
191  1 tester[0] = test;
192  1 createDecision(test,null,"Action0");
193   
194  1 out.println("\r\n##### Creating Valid decision Action without spaces #####\r\n");
195  1 test = (SimplePERMISToken) atts.get(1);
196  1 tester = new Object[1];
197  1 tester[0] = test;
198  1 createDecision(test,null,"Action0");
199   
200  1 out.println("\r\n##### Creating Invalid decision Action with spaces #####\r\n");
201  1 test = (SimplePERMISToken) atts.get(1);
202  1 tester = new Object[1];
203  1 tester[0] = test;
204  1 createDecision(test,null,"Action0 Action0");
205   
206  1 out.println("\r\n##### Creating valid decision a0 #####\r\n");
207  1 test = (SimplePERMISToken) atts.get(1);
208  1 tester = new Object[1];
209  1 tester[0] = test;
210  1 createDecision(test,null,"a0");
211   
212  1 out.println("\r\n##### Creating valid decision a1,a2, #####\r\n");
213  1 test = (SimplePERMISToken) atts.get(1);
214  1 tester = new Object[1];
215  1 tester[0] = test;
216  1 createDecision(test,null,"a1,a2,");
217   
218  1 out.println("\r\n##### Creating Valid decision a3 #####\r\n");
219  1 test = (SimplePERMISToken) atts.get(1);
220  1 tester = new Object[1];
221  1 tester[0] = test;
222  1 createDecision(test,null,"a3");
223   
224   
225  1 out.println("\r\n##### Creating Invalid decision a0,a1 #####\r\n");
226  1 test = (SimplePERMISToken) atts.get(1);
227  1 tester = new Object[1];
228  1 tester[0] = test;
229  1 createDecision(test,null,"a0,a1");
230   
231  1 out.println("\r\n##### Creating Invalid decision a2,a3 #####\r\n");
232  1 test = (SimplePERMISToken) atts.get(1);
233  1 tester = new Object[1];
234  1 tester[0] = test;
235  1 createDecision(test,null,"a2,a3");
236   
237  1 out.close();
238   
239   
240    }
241   
242   
 
243  9 togglepublic static void createDecision(SimplePERMISToken test, String target, String action){
244   
245  9 Object [] tester = new Object[1];
246  9 SimplePERMISPrincipal principle = null;
247  9 Subject subject = null;
248  9 if (target == null){
249  9 target = "O=PERMIS,C=GB";
250    }
251  9 Action a = null;
252  9 Target t = null;
253   
254  9 tester[0] = test;
255   
256  9 principle = new SimplePERMISPrincipal(test.getHolderEntry().getEntryName().getName());
257  9 out.println("Simple Permis Token Values :");
258  9 out.println("Holder : " + test.getHolderEntry().getEntryName().getName());
259  9 out.println("Issuer : " + test.getIssuerTokenLocator().getLocator().getName());
260  9 out.println("RoleType : " + test.getAttributeType());
261  9 out.println("RoleValue : " + test.getAttributeValue()+ "\r\n");
262  9 out.println("target : " + target );
263  9 out.println("action : " + action + "\r\n");
264  9 try {
265  9 subject = pbaAPI.getCreds(principle, tester);
266  9 out.println(subject.exportCreds().toString());
267    } catch (PbaException e) {
268  0 out.println("Error : " + e.getMessage());
269    }
270   
271  9 out.println("decision returned: ");
272   
273   
274  9 try {
275  9 a= new PermisAction(action);
276  9 if (target.startsWith("http://")){
277   
278  0 try {
279  0 t = new PermisTarget(target);
280    } catch (BadURLException e) {
281   
282    }
283    }else{
284  9 t = new PermisTarget(target,null);
285    }
286   
287   
288    } catch (RFC2253ParsingException e1) {
289  0 out.println("Error : " + e1.getMessage());
290    }
291   
292  9 out.println(processDecision(subject,a,t));
293    }
294    }