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 |
|
package issrg.pba.rbac.xmlpolicy; |
53 |
|
|
54 |
|
import issrg.pba.Credentials; |
55 |
|
import issrg.pba.DelegatableToken; |
56 |
|
import issrg.pba.ParsedToken; |
57 |
|
import issrg.pba.rbac.ExpirableCredentials; |
58 |
|
import issrg.pba.rbac.SetOfSubsetsCredentials; |
59 |
|
import issrg.pba.rbac.policies.AssignmentRule; |
60 |
|
import java.util.Arrays; |
61 |
|
import java.util.Date; |
62 |
|
import java.util.Iterator; |
63 |
|
import java.util.Vector; |
64 |
|
|
65 |
|
import org.apache.log4j.*; |
66 |
|
|
|
|
| 79.7% |
Uncovered Elements: 38 (187) |
Complexity: 54 |
Complexity Density: 0.53 |
|
67 |
|
public class DefaultRuleComparator implements issrg.pba.rbac.RuleComparator, java.util.Comparator { |
68 |
|
|
69 |
|
private Logger logger = Logger.getLogger(DefaultRuleComparator.class); |
70 |
|
Object assertion; |
71 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
72 |
26
|
public DefaultRuleComparator() {... |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
@param |
85 |
|
@param |
86 |
|
@return |
87 |
|
|
|
|
| 68.8% |
Uncovered Elements: 24 (77) |
Complexity: 28 |
Complexity Density: 0.57 |
|
88 |
9
|
public int compare(Object o1, Object o2) {... |
89 |
0
|
if (!(o1 instanceof ParsedToken && o2 instanceof ParsedToken && o1!=null && o2!=null)) throw new ClassCastException("Two parameters should not be null and must be the instance of ParsedToken class"); |
90 |
9
|
DelegatableToken obj1 = (DelegatableToken) o1; |
91 |
9
|
DelegatableToken obj2 = (DelegatableToken) o2; |
92 |
|
|
93 |
9
|
Credentials credsTok1 = obj1.getDelegateableCredentials(); |
94 |
9
|
Credentials credsTok2 = obj2.getDelegateableCredentials(); |
95 |
9
|
Credentials assertCred; |
96 |
9
|
if (assertion instanceof AssignmentRule) assertCred = ((AssignmentRule) assertion).getCredentials(); else assertCred = (Credentials) assertion; |
97 |
|
|
98 |
9
|
Credentials con1, con2; |
99 |
9
|
con1 = credsTok1.intersection(assertCred); |
100 |
9
|
con2 = credsTok2.intersection(assertCred); |
101 |
9
|
int states = morePriority(con1, con2); |
102 |
9
|
if (states == -1) return -1; |
103 |
0
|
if (states == 1) return 1; |
104 |
|
|
105 |
6
|
if (con1 instanceof SetOfSubsetsCredentials && con2 instanceof SetOfSubsetsCredentials) { |
106 |
6
|
Credentials f1, f2; |
107 |
6
|
f1 = (Credentials) ((SetOfSubsetsCredentials)con1).getValue().get(0); |
108 |
6
|
f2 = (Credentials) ((SetOfSubsetsCredentials)con2).getValue().get(0); |
109 |
6
|
if (f1 instanceof ExpirableCredentials && f2 instanceof ExpirableCredentials) { |
110 |
6
|
issrg.pba.rbac.ValidityPeriod vp1 = ((ExpirableCredentials) f1).getValidityPeriod(); |
111 |
6
|
issrg.pba.rbac.ValidityPeriod vp2 = ((ExpirableCredentials) f2).getValidityPeriod(); |
112 |
6
|
Date na1 = vp1.getNotAfter(); |
113 |
6
|
Date nb1 = vp1.getNotBefore(); |
114 |
6
|
Date na2 = vp2.getNotAfter(); |
115 |
6
|
Date nb2 = vp2.getNotBefore(); |
116 |
0
|
if ((nb1.compareTo(nb2) < 0) && (na1.compareTo(na2) >= 0)) return -1; |
117 |
0
|
if ((nb1.compareTo(nb2) == 0) && (na1.compareTo(na2) > 0)) return -1; |
118 |
0
|
if ((nb2.compareTo(nb1) < 0) && (na2.compareTo(na1) >= 0)) return 1; |
119 |
0
|
if ((nb2.compareTo(nb1) == 0) && (na2.compareTo(na1) > 0)) return 1; |
120 |
|
} |
121 |
|
} |
122 |
|
|
123 |
6
|
if (assertion instanceof Credentials) return 1; |
124 |
4
|
int tok1Depth = obj1.getDepth(); |
125 |
4
|
int tok2Depth = obj2.getDepth(); |
126 |
4
|
int requestedDepth = ((AssignmentRule) assertion).getDelegationDepth(); |
127 |
4
|
if ((tok1Depth == -1) || ((tok1Depth > requestedDepth) && (requestedDepth > -1))) return -1; |
128 |
0
|
if ((tok2Depth == -1) || ((tok2Depth > requestedDepth) && (requestedDepth > -1))) return 1; |
129 |
0
|
if (tok1Depth >= tok2Depth) return -1; else return 1; |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
@param |
136 |
|
@param |
137 |
|
@param |
138 |
|
@return |
139 |
|
|
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 6 |
Complexity Density: 0.32 |
|
141 |
560
|
public synchronized ParsedToken[] predict(Object assertion, Vector tokens, issrg.utils.repository.Entry holder){... |
142 |
560
|
this.assertion = assertion; |
143 |
560
|
Credentials assertCred; |
144 |
560
|
if (assertion instanceof AssignmentRule) assertCred = ((AssignmentRule) assertion).getCredentials(); else assertCred = (Credentials) assertion; |
145 |
560
|
Vector tokensClone = (Vector) tokens.clone(); |
146 |
560
|
SetOfSubsetsCredentials empty = new SetOfSubsetsCredentials(); |
147 |
1151
|
for (Iterator i = tokensClone.iterator(); i.hasNext();) { |
148 |
591
|
ParsedToken t = (ParsedToken) i.next(); |
149 |
591
|
if (!(t instanceof DelegatableToken)) { |
150 |
18
|
i.remove(); |
151 |
18
|
continue; |
152 |
|
} |
153 |
573
|
DelegatableToken dt = (DelegatableToken)t; |
154 |
573
|
if (dt.getDelegateableCredentials().intersection(assertCred).equals(empty) |
155 |
|
|| !dt.getSubjectDomain().contains(holder)) |
156 |
132
|
i.remove(); |
157 |
|
} |
158 |
560
|
ParsedToken[] ret; |
159 |
560
|
ret = (ParsedToken[]) tokensClone.toArray(new ParsedToken[0]); |
160 |
560
|
Arrays.sort(ret, this); |
161 |
560
|
return ret; |
162 |
|
|
163 |
|
} |
164 |
|
|
165 |
|
private boolean flag = false; |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
167 |
1177
|
public void setFlag (boolean manySOAs) {... |
168 |
1177
|
flag = manySOAs; |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
@param |
173 |
|
@param |
174 |
|
|
175 |
|
@param |
176 |
|
@param |
177 |
|
@return |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
|
|
| 85.4% |
Uncovered Elements: 6 (41) |
Complexity: 12 |
Complexity Density: 0.57 |
|
182 |
2360
|
public boolean isSufficient(AssignmentRule asRAR, AssignmentRule vaRAR, Object assertion, Object validated) {... |
183 |
2360
|
if (asRAR==null && vaRAR==null) |
184 |
|
{ |
185 |
1576
|
if (!flag) return true; |
186 |
|
else { |
187 |
1133
|
if (validated instanceof Credentials) { |
188 |
1126
|
if (((Credentials) validated).equals(new SetOfSubsetsCredentials())) return false; else return true; |
189 |
|
} else { |
190 |
7
|
if (validated instanceof Vector) { |
191 |
0
|
if (!((Vector)validated).isEmpty()) return true; else return false; |
192 |
0
|
} else return false; |
193 |
|
} |
194 |
|
} |
195 |
|
} |
196 |
|
|
197 |
784
|
if (validated instanceof Credentials) { |
198 |
687
|
if (((Credentials) validated).equals(new SetOfSubsetsCredentials())) return false; else return true; |
199 |
|
} else { |
200 |
97
|
if (validated instanceof Vector) { |
201 |
97
|
if (!((Vector)validated).isEmpty()) return true; else return false; |
202 |
0
|
} else return false; |
203 |
|
} |
204 |
|
|
205 |
|
} |
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
@param |
212 |
|
@param |
213 |
|
|
214 |
|
@return |
215 |
|
|
216 |
|
|
|
|
| 77.1% |
Uncovered Elements: 8 (35) |
Complexity: 11 |
Complexity Density: 0.52 |
|
217 |
9
|
private int morePriority(Credentials current, Credentials cred) {... |
218 |
9
|
if (current instanceof SetOfSubsetsCredentials && cred instanceof SetOfSubsetsCredentials) { |
219 |
9
|
Vector t = ((SetOfSubsetsCredentials)current).getValue(); |
220 |
9
|
Vector fromCurrent = new Vector(); |
221 |
20
|
for (int i = 0; i < t.size(); i++) { |
222 |
0
|
if (!(t.get(i) instanceof ExpirableCredentials)) return 0; |
223 |
11
|
fromCurrent.add(((ExpirableCredentials) t.get(i)).getExpirable()); |
224 |
|
} |
225 |
9
|
t = ((SetOfSubsetsCredentials) cred).getValue(); |
226 |
9
|
Vector fromCred = new Vector(); |
227 |
19
|
for (int i = 0; i < t.size(); i++) { |
228 |
0
|
if (!(t.get(i) instanceof ExpirableCredentials)) return 0; |
229 |
10
|
fromCred.add(((ExpirableCredentials) t.get(i)).getExpirable()); |
230 |
|
} |
231 |
9
|
SetOfSubsetsCredentials currentSet = new SetOfSubsetsCredentials(fromCurrent); |
232 |
9
|
SetOfSubsetsCredentials credSet = new SetOfSubsetsCredentials(fromCred); |
233 |
9
|
if (currentSet.contains(credSet) && !currentSet.equals(credSet)) return -1; |
234 |
0
|
if (credSet.contains(currentSet) && !currentSet.equals(credSet)) return 1; |
235 |
6
|
return 0; |
236 |
|
} |
237 |
0
|
return 0; |
238 |
|
} |
239 |
|
} |
240 |
|
|