ComplexSubtree | Line # 44 | 41 | 16 | 46.8% |
0.46753246
|
(1) | |||
Result | |||
0.14285715
|
issrg.test.ds.TestDS.testIssuing issrg.test.ds.TestDS.testIssuing | 1 PASS | |
1 | /* | |
2 | * Copyright (c) 2000-2005, University of Salford | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions are met: | |
7 | * | |
8 | * Redistributions of source code must retain the above copyright notice, this | |
9 | * list of conditions and the following disclaimer. | |
10 | * | |
11 | * Redistributions in binary form must reproduce the above copyright notice, | |
12 | * this list of conditions and the following disclaimer in the documentation | |
13 | * and/or other materials provided with the distribution. | |
14 | * | |
15 | * Neither the name of the University of Salford nor the names of its | |
16 | * contributors may be used to endorse or promote products derived from this | |
17 | * software without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | |
31 | ||
32 | package issrg.pba.rbac.policies; | |
33 | ||
34 | import issrg.utils.repository.Entry; | |
35 | ||
36 | /** | |
37 | * This class stands for a subtree that has several roots: a union of | |
38 | * several simple subtrees. | |
39 | * | |
40 | * @author A Otenko | |
41 | * @version 1.0 | |
42 | */ | |
43 | ||
44 | public class ComplexSubtree implements Subtree { | |
45 | /** | |
46 | * This is an array of all roots of this union of subtrees. | |
47 | */ | |
48 | protected Subtree [] dits; | |
49 | ||
50 | /** | |
51 | * This is an array of additional Object Classes restrictions (in addition to | |
52 | * those specified within the dits). | |
53 | */ | |
54 | protected String [] objectClasses; | |
55 | ||
56 | /** | |
57 | * @return the array of Subtrees that this Complex Subtree is a union of | |
58 | */ | |
59 | 0 | public Subtree[] getSubtrees() { |
60 | 0 | return dits; |
61 | } | |
62 | ||
63 | /** | |
64 | * This constructor builds a ComplexSubtree with no components. | |
65 | */ | |
66 | 0 | public ComplexSubtree(){} |
67 | ||
68 | /** | |
69 | * This constructor builds the union of the array of DIT subtrees, with | |
70 | * additional object classes restriction, so even if the object class will | |
71 | * be allowed by a certain subtree, it still can be sieved away by this object | |
72 | * class specification. | |
73 | * | |
74 | * @param dits is the array of subtrees to join together; if null, or an empty | |
75 | * array, then no entries belong to it; pass it an array of one | |
76 | * Subtree based on null DN for this subtree to contain the whole world | |
77 | * @param objectClasses is the array of objectClasses that the entries must be | |
78 | * of (must match all of the objectClasses); if it is null, entries with | |
79 | * any object Classes are accepted, if they match the subtree specification | |
80 | */ | |
81 | 0 | public ComplexSubtree(Subtree [] dits, String [] objectClasses) { |
82 | 0 | _create_(dits, objectClasses); |
83 | } | |
84 | ||
85 | /** | |
86 | * Does the same as the ComplexSubtree(Subtree [], String[]) constructor, but | |
87 | * gets the | |
88 | * arrays of subtrees and objectClasses as vectors. Note that each of the | |
89 | * elements should be of type Subtree and String respectively. | |
90 | * | |
91 | * @param dits is a Vector of Subtree objects, a union of which will be | |
92 | * represented by this object; this array can be null | |
93 | * @param objectClasses is a vector of Strings, each representing the object | |
94 | * class of acceptable entries; this array can be null | |
95 | */ | |
96 | 166 | public ComplexSubtree(java.util.Vector dits, java.util.Vector objectClasses){ |
97 | 166 | Subtree [] s = null; |
98 | 166 | String [] c = null; |
99 | ||
100 | 166 | if (dits!=null){ |
101 | 166 | s = (Subtree[]) dits.toArray(new Subtree[0]); |
102 | } | |
103 | ||
104 | 166 | if (objectClasses!=null){ |
105 | 0 | c = (String[])objectClasses.toArray(new String[0]); |
106 | } | |
107 | ||
108 | 166 | _create_(s, c); |
109 | } | |
110 | ||
111 | ||
112 | /** | |
113 | * This is the method that does the actual construction of the object and is | |
114 | * called by both constructors. | |
115 | */ | |
116 | 166 | private void _create_(Subtree [] dits, String [] objClass){ |
117 | 166 | if (dits==null){ |
118 | 0 | dits=new Subtree[0]; |
119 | } | |
120 | ||
121 | 166 | this.dits = dits; |
122 | 166 | this.objectClasses = objClass; |
123 | } | |
124 | ||
125 | /** | |
126 | * This method tells whether or not the given entry belongs to this subtree. | |
127 | * It is redefined to go through the whole array of Subtree objects that | |
128 | * has been passed to the constructor, and if the given Entry is contained in | |
129 | * either of them, and it satisfies the additional object class constraints, | |
130 | * it returns true. Otherwise, it returns false. | |
131 | * | |
132 | * @param what is the Entry that is tested; if ComplexSubtree is built with | |
133 | * ObjectClasses, | |
134 | * it will expect only LDAPEntry on input here (returns false otherwise) | |
135 | * | |
136 | * @return true, if the given Entry is included in the subtree; false | |
137 | * otherwise | |
138 | */ | |
139 | 20010 | public boolean contains(Entry what){ |
140 | 20010 | if (objectClasses!=null){ |
141 | 0 | if (!(what instanceof LDAPEntry)) return false; // object class cannot match: what is not an LDAPEntry |
142 | ||
143 | 0 | boolean falseClass=true; |
144 | 0 | for (int i=0; i<objectClasses.length; i++){ |
145 | 0 | if (falseClass=!((LDAPEntry)what).isObjectClass(objectClasses[i])){ |
146 | 0 | break; |
147 | } | |
148 | } | |
149 | ||
150 | 0 | if (falseClass){ |
151 | 0 | return false; |
152 | } | |
153 | } | |
154 | ||
155 | 36362 | for (int i=0; i<dits.length; i++){ |
156 | 26181 | if (dits[i]!=null && dits[i].contains(what)){ |
157 | 9829 | return true; |
158 | } | |
159 | } | |
160 | ||
161 | 10181 | return false; |
162 | } | |
163 | ||
164 | 3490 | public String toString(){ |
165 | 3490 | StringBuffer sb = new StringBuffer("Complex Subtree: {"); |
166 | 7874 | for (int i=0; i<dits.length; i++){ |
167 | 4384 | if (i!=0){ |
168 | 894 | sb.append(", "); |
169 | } | |
170 | 4384 | sb.append(dits[i].toString()); |
171 | } | |
172 | ||
173 | 3490 | return sb.toString()+"}"; |
174 | } | |
175 | ||
176 | ||
177 | 0 | public Object clone() { |
178 | 0 | Subtree[] a = null; |
179 | 0 | if (dits != null) { |
180 | 0 | a = new Subtree[dits.length]; |
181 | 0 | System.arraycopy(dits, 0, a, 0, a.length); |
182 | } | |
183 | 0 | String[] b = null; |
184 | 0 | if (objectClasses != null) { |
185 | 0 | b = new String[objectClasses.length]; |
186 | 0 | System.arraycopy(objectClasses, 0, b, 0, b.length); |
187 | } | |
188 | 0 | return new ComplexSubtree(a, b); |
189 | } | |
190 | ||
191 | } | |
192 |
|