1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
package issrg.test.emptyDN; |
11 |
|
|
12 |
|
import issrg.pba.PbaException; |
13 |
|
import issrg.pba.Response; |
14 |
|
import issrg.pba.rbac.PermisAction; |
15 |
|
import issrg.pba.rbac.PermisRBAC; |
16 |
|
import issrg.pba.rbac.PermisTarget; |
17 |
|
import issrg.simplePERMIS.SimplePERMISPolicyFinder; |
18 |
|
import issrg.simplePERMIS.SimplePERMISToken; |
19 |
|
import issrg.simplePERMIS.SimplePERMISTokenParser; |
20 |
|
import issrg.utils.repository.Entry; |
21 |
|
import issrg.pba.Subject; |
22 |
|
import issrg.utils.handler.Config; |
23 |
|
import issrg.utils.handler.ConfigException; |
24 |
|
|
25 |
|
import java.util.*; |
26 |
|
import java.io.*; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
@author |
31 |
|
|
|
|
| 73.5% |
Uncovered Elements: 26 (98) |
Complexity: 17 |
Complexity Density: 0.32 |
|
32 |
|
public class PushSimplePERMISTokenWithEmptyDN { |
33 |
|
|
34 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
35 |
0
|
public PushSimplePERMISTokenWithEmptyDN() {... |
36 |
|
} |
37 |
|
private SimplePERMISTokenParser testParserTok = null; |
38 |
|
|
39 |
|
private static PermisRBAC adf = null; |
40 |
|
private static SimplePERMISPolicyFinder ssampf=null; |
41 |
|
|
42 |
|
private static Subject subject=null; |
43 |
|
private static PermisAction action=null; |
44 |
|
private static PermisTarget target=null; |
45 |
|
private static PrintStream out = System.out; |
46 |
|
private static InputStream in = null; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
|
|
| 78% |
Uncovered Elements: 11 (50) |
Complexity: 11 |
Complexity Density: 0.31 |
|
52 |
1
|
public static void main(String[] args) {... |
53 |
|
|
54 |
1
|
System.setProperty("line.separator", "\r\n"); |
55 |
|
|
56 |
1
|
String policy = null; |
57 |
1
|
String role = null; |
58 |
1
|
String action = null; |
59 |
1
|
String target = null; |
60 |
|
|
61 |
1
|
if (args.length==2){ |
62 |
1
|
Config config = new Config(); |
63 |
1
|
try{ |
64 |
1
|
in = new FileInputStream(config.getURL(args[0])); |
65 |
1
|
out = new PrintStream(new FileOutputStream(args[1])); |
66 |
|
|
67 |
1
|
Properties props = new Properties(); |
68 |
1
|
props.load(in); |
69 |
1
|
policy = props.getProperty("policy"); |
70 |
1
|
role = props.getProperty("role"); |
71 |
1
|
action = props.getProperty("action"); |
72 |
1
|
target = props.getProperty("target"); |
73 |
|
|
74 |
1
|
in.close(); |
75 |
|
|
76 |
|
} catch(IOException ioe){ |
77 |
0
|
out.println("This shouldn't have happened! "+ioe.getMessage()); |
78 |
|
} catch(ConfigException ce){ |
79 |
0
|
out.println("This shouldn't have happened! "+ce.getMessage()); |
80 |
|
} |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
1
|
if (loadPolicy(policy)) out.println("policy is loaded"); |
97 |
1
|
if (constructADF()) out.println("PDP is created"); |
98 |
1
|
if (constructSubject(role)) out.println("Subject (role = "+role+") is created"); |
99 |
1
|
if (constructAction(action)) out.println("Action (name = "+action+") is created"); |
100 |
1
|
if (constructTarget(target)) out.println("Target (DN = "+target+") is created"); |
101 |
1
|
try { |
102 |
1
|
Response res = consult(); |
103 |
1
|
if (res.isAuthorised()) out.println("Permit"); |
104 |
0
|
else out.println("Deny"); |
105 |
|
} catch (PbaException pe) { |
106 |
0
|
out.println("error: "+pe); |
107 |
|
} |
108 |
1
|
out.close(); |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
@param |
115 |
|
|
116 |
|
|
|
|
| 35.7% |
Uncovered Elements: 9 (14) |
Complexity: 4 |
Complexity Density: 0.33 |
|
117 |
1
|
public static boolean loadPolicy(String pathNameofPolicy){... |
118 |
1
|
try{ |
119 |
1
|
ssampf = new SimplePERMISPolicyFinder(pathNameofPolicy); |
120 |
|
}catch (Exception e){ |
121 |
0
|
out.println("Exception was thrown in loading policy!"); |
122 |
0
|
out.println(e.getMessage()); |
123 |
0
|
ssampf=null; |
124 |
|
}catch(Throwable th){ |
125 |
0
|
out.println("Throwable was thrown in loading policy!"); |
126 |
0
|
out.println(th.getMessage()); |
127 |
0
|
ssampf=null; |
128 |
|
} |
129 |
|
|
130 |
1
|
if (ssampf == null){ |
131 |
0
|
out.println("Null PolicyFinder was returned!"); |
132 |
0
|
return false; |
133 |
|
} |
134 |
1
|
return true; |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
@return |
140 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
141 |
1
|
public static boolean constructADF(){... |
142 |
|
|
143 |
1
|
try{ |
144 |
1
|
adf = new PermisRBAC(ssampf); |
145 |
|
} catch(PbaException pe){ |
146 |
0
|
out.println(pe.getMessage()); |
147 |
0
|
return false; |
148 |
|
} |
149 |
|
|
150 |
1
|
return true; |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
@param |
157 |
|
@param |
158 |
|
@param |
159 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 2 |
Complexity Density: 0.17 |
|
160 |
1
|
public static boolean constructSubject(String roleValue){... |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
1
|
subject=null; |
165 |
|
|
166 |
1
|
SimplePERMISToken subjectToken=null; |
167 |
|
|
168 |
|
|
169 |
1
|
String roleType = ""; |
170 |
|
|
171 |
1
|
roleType = "permisRole"; |
172 |
|
|
173 |
1
|
subjectToken = new SimplePERMISToken("", "", roleType, roleValue); |
174 |
|
|
175 |
1
|
Vector newCreds = new Vector(); |
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
1
|
newCreds.add(subjectToken); |
182 |
1
|
try{ |
183 |
|
|
184 |
1
|
subject = adf.getCreds(subjectToken.getHolderEntry().getEntryName(), newCreds.toArray()); |
185 |
|
}catch(PbaException pbaE){ |
186 |
0
|
subject=null; |
187 |
0
|
return false; |
188 |
|
} |
189 |
|
|
190 |
1
|
return true; |
191 |
|
} |
192 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
193 |
1
|
public static boolean constructAction(String actionName){... |
194 |
|
|
195 |
|
|
196 |
1
|
action=null; |
197 |
|
|
198 |
|
|
199 |
|
|
200 |
1
|
action = new PermisAction(actionName); |
201 |
|
|
202 |
1
|
return true; |
203 |
|
} |
204 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
205 |
1
|
public static boolean constructTarget(String targetDN){... |
206 |
|
|
207 |
1
|
target = null; |
208 |
|
|
209 |
|
|
210 |
|
|
211 |
1
|
try{ |
212 |
1
|
target = new PermisTarget(targetDN, null); |
213 |
|
}catch(issrg.utils.RFC2253ParsingException rfcExc){ |
214 |
0
|
return false; |
215 |
|
} |
216 |
|
|
217 |
1
|
return true; |
218 |
|
|
219 |
|
} |
220 |
|
|
221 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
222 |
1
|
public static Response consult() throws PbaException{... |
223 |
|
|
224 |
1
|
return adf.authzDecision(subject,action,target,null); |
225 |
|
|
226 |
|
} |
227 |
|
} |