Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
100   238   7   25
8   127   0.1   4
4     2.5  
1    
 
 
  ShibbolethAtt       Line # 64 100 7 88.4% 0.8839286
 
No Tests
 
1    /*
2    *ShibbolethAtt.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    package issrg.test;
54   
55   
56   
57    import org.apache.axis.encoding.Base64;
58   
59    import issrg.ac.AttributeCertificate;
60    import issrg.shibboleth.ShibPermisRBAC;
61    import org.apache.log4j.Logger;
62   
63    import com.sun.jndi.ldap.LdapCtx;
 
64    public class ShibbolethAtt {
65   
66    static java.io.PrintStream out;
67   
68   
69   
 
70  1 toggle public ShibbolethAtt(String[] args) {
71   
72  1 if (args.length < 2) {
73  0 out.println("These tests must be initalised with a policy file and an output file");
74  0 System.exit(1);
75    }
76   
77   
78  1 try{
79  1 out=new java.io.PrintStream(new java.io.FileOutputStream(args[1]));
80    }catch(Exception e){
81  0 e.printStackTrace(out);
82  0 return;
83    }
84  1 out.println("--------oooooooo(((((((( SAAM (in push mode) and Shibboleth Attributes Test ))))))))oooooooo--------");
85  1 out.println();
86   
87    // TODO Auto-generated constructor stub
88   
89  1 char myString[]=null;
90   
91   
92   
93  1 String user0 = encodeString("src/issrg/test/shibboleth/user0role0.ace");
94  1 String user1 = encodeString("src/issrg/test/shibboleth/user0role1.ace");
95   
96  1 Logger root = Logger.getRootLogger();
97   
98  1 String [] policy = new String [7];
99   
100  1 policy [0]= "NULL";
101  1 policy [1]= "NULL";
102  1 policy [2]= args[0];
103  1 policy [3]= "attributeCertificateAttribute";
104  1 policy [4]= "";
105  1 policy [5]= "off" ;
106  1 policy [6]= "userCertificateAttribute";
107   
108  1 String [] creds = new String [1];
109   
110  1 creds[0] ="shib:permisRole=Role0@kent.ac.uk";
111   
112   
113  1 String [] creds2 = new String [1];
114  1 creds2[0] ="shib:attributeCertificateAttribute=" + user0 +"@kent.ac.uk";
115   
116  1 String [] creds3 = new String [1];
117  1 creds3[0] = "shib:permisRole=Role0@kent.ac.uk";
118   
119  1 String [] creds4 = new String [2];
120  1 creds4[0] = "shib:permisRole=Role0@kent.ac.uk";
121  1 creds4[1] = "shib:permisRole=Role1@kent.ac.uk";
122   
123  1 String [] creds5 = new String [2];
124  1 creds5[0] = "shib:attributeCertificateAttribute=" + user0 +"@kent.ac.uk";
125  1 creds5[1] = "shib:attributeCertificateAttribute=" + user1 +"@kent.ac.uk";
126   
127   
128  1 String [] creds6 = new String [1];
129  1 creds6[0] = "shib:permisRole=Role1@kent.ac.uk;Role0@kent.ac.uk" ;
130   
131   
132  1 String [] ac = new String [1];
133  1 ac [0] = "";
134   
135  1 String [] loa1 = new String [1];
136  1 loa1[0] = "shib:loa=2@kent.ac.uk";
137   
138   
139  1 ShibPermisRBAC shib = null;
140  1 shib = new ShibPermisRBAC(policy,new String[0]);
141  1 root.removeAllAppenders();
142   
143  1 out.println("Check shib permisRole attribute works :");
144  1 int a =shib.permisAuth( creds,"kent.ac.uk","cn=user0,o=permis,c=gb","GET", "http://www.testsite.com/secure1/", policy,null);
145  1 checkResult(a);
146   
147   
148  1 out.println("Check shib attributeCertificateAttribute attribute works :");
149  1 a =shib.permisAuth( creds2,"kent.ac.uk","cn=user0,o=permis,c=gb","GET", "http://www.testsite.com/secure1/ ", policy,null);
150  1 checkResult(a);
151  1 root.removeAllAppenders();
152   
153  1 out.println("Check that required role is needed (returns deny) :");
154  1 a =shib.permisAuth( creds3,"kent.ac.uk","cn=user0,o=permis,c=gb","GET", "http://www.testsite.com/secure2/ ", policy,null);
155  1 checkResult(a);
156  1 root.removeAllAppenders();
157   
158  1 out.println("Check that multiple permisRoles work :");
159  1 a =shib.permisAuth( creds4,"kent.ac.uk","cn=user0,o=permis,c=gb","GET", "http://www.testsite.com/secure2/ ", policy,null);
160  1 checkResult(a);
161  1 root.removeAllAppenders();
162   
163  1 out.println("Check that multiple attributeCertificateAttributes work :");
164  1 a =shib.permisAuth( creds5,"kent.ac.uk","cn=user0,o=permis,c=gb","GET", "http://www.testsite.com/secure2/ ", policy,null);
165  1 checkResult(a);
166  1 root.removeAllAppenders();
167   
168  1 out.println("Check that multiple permisRoles contained in one shibboleth attribute work :");
169  1 a =shib.permisAuth( creds6,"kent.ac.uk","cn=user0,o=permis,c=gb","GET", "http://www.testsite.com/secure2/ ", policy,null);
170  1 checkResult(a);
171  1 root.removeAllAppenders();
172  1 out.println("Check that a superior role can access a location requiring a subbordinate :");
173   
174  1 a =shib.permisAuth( loa1,"kent.ac.uk","cn=user0,o=permis,c=gb","GET", "http://www.testsite.com/loa1/ ", policy,null);
175  1 checkResult(a);
176  1 root.removeAllAppenders();
177  1 loa1[0] = "shib:loa=2@kent.ac.uk";
178   
179  1 out.println("Check that a role in a role hierachy can access a location requiring its role :");
180   
181  1 a =shib.permisAuth( loa1,"kent.ac.uk","cn=user0,o=permis,c=gb","GET", "http://www.testsite.com/loa2/ ", policy,null);
182  1 checkResult(a);
183  1 root.removeAllAppenders();
184  1 loa1[0] = "shib:loa=2@kent.ac.uk";
185   
186  1 out.println("Check that a subordinate role cannot access a location requiring a superior role (returns deny) :");
187   
188  1 a =shib.permisAuth( loa1,"kent.ac.uk","cn=user0,o=permis,c=gb","GET", "http://www.testsite.com/loa3/ ", policy,null);
189  1 checkResult(a);
190  1 root.removeAllAppenders();
191    }
 
192  9 toggle public void checkResult(int a){
193  9 if (a == 0){
194  7 out.println("Decision returned : OK");
195  7 out.println();
196    }
197  9 if (a == 1){
198  2 out.println("Decision returned : DENY");
199  2 out.println();
200    }
201   
202  9 if (a == 2){
203  0 out.println("Decision returned : DECLINED");
204  0 out.println();
205    }
206    }
207   
 
208  2 toggle public static String encodeString(String filename){
209  2 try {
210  2 java.io.InputStream io = new java.io.FileInputStream(filename);
211   
212  2 byte[] ac = new byte[io.available()];
213  2 io.read(ac);
214  2 issrg.ac.AttributeCertificate acd = issrg.ac.AttributeCertificate
215    .guessEncoding(ac);
216   
217  2 byte[] ap =acd.getEncoded();
218  2 String encoded = Base64.encode(ap);
219   
220  2 return encoded;
221    }
222   
223    catch (Throwable th) {
224   
225  0 out.println(th.getMessage());
226  0 return null;
227    }
228    }
229   
230   
231   
 
232  0 toggle public static void main(String[]args){
233    //ActionSpace(args);
234  0 System.setProperty("line.separator", "\r\n");
235  0 out.close();
236    }
237   
238    }