1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
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; |
|
|
| 88.4% |
Uncovered Elements: 13 (112) |
Complexity: 7 |
Complexity Density: 0.1 |
|
64 |
|
public class ShibbolethAtt { |
65 |
|
|
66 |
|
static java.io.PrintStream out; |
67 |
|
|
68 |
|
|
69 |
|
|
|
|
| 93.8% |
Uncovered Elements: 5 (81) |
Complexity: 3 |
Complexity Density: 0.04 |
|
70 |
1
|
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 |
|
|
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 |
|
} |
|
|
| 80% |
Uncovered Elements: 3 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
192 |
9
|
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 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
|
208 |
2
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
232 |
0
|
public static void main(String[]args){... |
233 |
|
|
234 |
0
|
System.setProperty("line.separator", "\r\n"); |
235 |
0
|
out.close(); |
236 |
|
} |
237 |
|
|
238 |
|
} |