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 |
|
package issrg.pba.rbac.policies; |
33 |
|
|
34 |
|
import issrg.pba.rbac.LDAPDNPrincipal; |
35 |
|
import issrg.utils.RFC2253ParsingException; |
36 |
|
import issrg.utils.repository.Entry; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
@author |
44 |
|
@version |
45 |
|
|
46 |
|
|
|
|
| 63.2% |
Uncovered Elements: 53 (144) |
Complexity: 30 |
Complexity Density: 0.46 |
|
47 |
|
public class DITSubtree implements Subtree { |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
protected LDAPDNPrincipal subtree; |
52 |
|
|
53 |
|
protected int min; |
54 |
|
protected int max; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
protected String [] objectclasses; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
protected Subtree [] exclusive; |
67 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
68 |
0
|
protected DITSubtree(){}... |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
|
75 |
|
@param |
76 |
|
|
77 |
|
@param |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
@param |
84 |
|
|
85 |
|
|
86 |
|
@param |
87 |
|
|
88 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
89 |
3741
|
public DITSubtree(LDAPDNPrincipal subtree, int min, int max,... |
90 |
|
String [] objectClass, Subtree [] exclude) { |
91 |
|
|
92 |
3741
|
this.subtree = subtree; |
93 |
3741
|
objectclasses = objectClass; |
94 |
3741
|
exclusive = exclude; |
95 |
|
|
96 |
3741
|
this.min=min; |
97 |
3741
|
this.max=max; |
98 |
|
|
99 |
3741
|
if (min<0 || max<-1){ |
100 |
0
|
throw new IllegalArgumentException("Subtree margins exceed the allowed range"); |
101 |
|
} |
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
@param |
112 |
|
|
113 |
|
|
114 |
|
@return |
115 |
|
|
116 |
|
|
117 |
|
|
|
|
| 85.9% |
Uncovered Elements: 9 (64) |
Complexity: 19 |
Complexity Density: 0.56 |
|
118 |
22404
|
public boolean contains(LDAPEntry entry){... |
119 |
22404
|
boolean result=false; |
120 |
|
|
121 |
22404
|
if (subtree!=null){ |
122 |
22404
|
String [][][] alien = entry.getDN().getParsedDN(); |
123 |
22404
|
String [][][] subtree = this.subtree.getParsedDN(); |
124 |
|
|
125 |
22404
|
int o = alien.length-subtree.length; |
126 |
22404
|
if (o>=min && (max==-1 || o<=max)){ |
127 |
|
|
128 |
20802
|
result=true; |
129 |
20802
|
match_DN: |
130 |
71280
|
for (int i=subtree.length; i-->0; ){ |
131 |
63125
|
int i1=o+i; |
132 |
63125
|
if (alien[i1].length!=subtree[i].length){ |
133 |
0
|
result=false; |
134 |
0
|
break; |
135 |
|
} |
136 |
|
|
137 |
113603
|
for (int j=0; j<subtree[i].length; j++){ |
138 |
63125
|
String s = subtree[i][j][0].toUpperCase().intern(); |
139 |
|
|
140 |
63125
|
int k; |
141 |
|
|
142 |
63131
|
for (k=0; k<alien[i1].length; k++){ |
143 |
63125
|
if (s==alien[i1][k][0].toUpperCase().intern()){ |
144 |
63119
|
break; |
145 |
|
} |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
63125
|
if (k>=alien[i1].length){ |
151 |
6
|
result=false; |
152 |
6
|
break match_DN; |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
63119
|
if (subtree[i][j][1].toUpperCase().intern()!=alien[i1][k][1].toUpperCase().intern()){ |
163 |
12641
|
result=false; |
164 |
12641
|
break match_DN; |
165 |
|
} |
166 |
|
} |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
} |
175 |
|
} |
176 |
|
|
177 |
22404
|
if (objectclasses!=null && result){ |
178 |
840
|
result=false; |
179 |
1680
|
for (int i=0; i<objectclasses.length; i++){ |
180 |
0
|
if (!(result=entry.isObjectClass(objectclasses[i]))){ |
181 |
|
|
182 |
0
|
break; |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
} |
188 |
|
} |
189 |
|
|
190 |
22404
|
if (exclusive!=null && result){ |
191 |
|
|
192 |
9175
|
for (int i=0; i<exclusive.length; i++){ |
193 |
0
|
if (!(result=!exclusive[i].contains(entry))){ |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
8
|
break; |
199 |
|
} |
200 |
|
} |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
22404
|
return result; |
205 |
|
} |
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 1 |
|
212 |
22507
|
public boolean contains(Entry e){... |
213 |
22507
|
return (e instanceof LDAPEntry)? contains((LDAPEntry)e): false; |
214 |
|
} |
215 |
|
|
|
|
| 75.9% |
Uncovered Elements: 7 (29) |
Complexity: 5 |
Complexity Density: 0.38 |
|
216 |
3975
|
public String toString(){... |
217 |
3975
|
String exclude=null; |
218 |
3975
|
if (exclusive!=null){ |
219 |
3975
|
exclude=", excluding ["; |
220 |
3975
|
for (int i=0; i<exclusive.length; i++){ |
221 |
0
|
exclude+=(i==0?"":", ")+exclusive[i].toString(); |
222 |
|
} |
223 |
3975
|
exclude+="]"; |
224 |
|
} |
225 |
|
|
226 |
3975
|
String objClasses=null; |
227 |
3975
|
if (objectclasses!=null){ |
228 |
210
|
objClasses=", objectClasses {"; |
229 |
420
|
for (int i=0; i<objectclasses.length; i++){ |
230 |
210
|
objClasses+=(i==0?"":", ")+objectclasses[i]; |
231 |
|
} |
232 |
210
|
objClasses="}"; |
233 |
|
} |
234 |
3975
|
return "DITSubtree with base DN="+subtree.getName()+", min="+min+", max="+max+ |
235 |
3975
|
(exclude==null?"":exclude)+(objClasses==null?"":objClasses); |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
242 |
0
|
public void excludeEntry(Entry e) {... |
243 |
0
|
if (!(e instanceof LDAPEntry)) return; |
244 |
0
|
Subtree[] r; |
245 |
0
|
if (exclusive == null) { |
246 |
0
|
r = new Subtree[1]; |
247 |
0
|
r[0]=new DITSubtree(((LDAPEntry)e).getDN(), 0, -1, null, null); |
248 |
0
|
exclusive = r; |
249 |
|
} else { |
250 |
0
|
r = new Subtree[exclusive.length]; |
251 |
0
|
System.arraycopy(exclusive, 0, r, 0, exclusive.length); |
252 |
0
|
exclusive = new Subtree[r.length + 1]; |
253 |
0
|
System.arraycopy(r, 0, exclusive, 0, r.length); |
254 |
0
|
exclusive[r.length] = new DITSubtree(((LDAPEntry) e).getDN(), 0, -1, null, null); |
255 |
|
} |
256 |
|
} |
257 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
258 |
0
|
public Object clone() {... |
259 |
0
|
String[] a = null; |
260 |
0
|
if (objectclasses != null) { |
261 |
0
|
a = new String[objectclasses.length]; |
262 |
0
|
System.arraycopy(objectclasses, 0, a, 0, a.length); |
263 |
|
} |
264 |
0
|
Subtree[] b = null; |
265 |
0
|
if (exclusive != null) { |
266 |
0
|
b = new Subtree[exclusive.length]; |
267 |
0
|
System.arraycopy(exclusive, 0, b, 0, b.length); |
268 |
|
} |
269 |
|
|
270 |
0
|
try { |
271 |
0
|
return new DITSubtree(new LDAPDNPrincipal(subtree.getName()), min, max, a, b); |
272 |
0
|
} catch (RFC2253ParsingException pe) {pe.printStackTrace(); return null;} |
273 |
|
} |
274 |
|
} |