RetainedADI | Line # 64 | 37 | 13 | 81.7% |
0.81666666
|
No Tests | |||
1 | /* | |
2 | * Copyright (c) 2006, University of Kent | |
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 | * 1. Neither the name of the University of Kent 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 | * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | |
20 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. | |
23 | * | |
24 | * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
31 | * POSSIBILITY OF SUCH DAMAGE. | |
32 | * | |
33 | * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE | |
34 | * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS | |
35 | * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS | |
36 | * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH | |
37 | * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH | |
38 | * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY | |
39 | * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE | |
40 | * SERIOUS FAULTS, IN THIS SOFTWARE. | |
41 | * | |
42 | * 5. This license is governed, except to the extent that local laws | |
43 | * necessarily apply, by the laws of England and Wales. | |
44 | */ | |
45 | ||
46 | ||
47 | package issrg.pba.rbac; | |
48 | ||
49 | import issrg.pba.PbaException; | |
50 | import java.util.Map; | |
51 | import java.util.Hashtable; | |
52 | import java.util.Vector; | |
53 | ||
54 | /** | |
55 | * This is the class for managing retained ADI when history based decision is | |
56 | * needed. | |
57 | * All successfull decisions are kept in this class in a Vector | |
58 | * decisionHistoryVec. | |
59 | * | |
60 | * @author W. Xu | |
61 | * @version 0.1 | |
62 | */ | |
63 | ||
64 | public class RetainedADI { | |
65 | Vector decisionHistoryVec; | |
66 | ||
67 | /** | |
68 | * This constructor generates a new retained ADI object with empty dicisionHistoryVec. | |
69 | */ | |
70 | 4 | public RetainedADI(){ |
71 | 4 | decisionHistoryVec = new Vector(); |
72 | } | |
73 | ||
74 | /** | |
75 | * This constructor generates a new retained ADI object with dicisionVec as | |
76 | * the decisionHisotryVec. | |
77 | * | |
78 | * @params decisionVec is the vector which contains a vector of | |
79 | * DecisionRecord. | |
80 | * | |
81 | */ | |
82 | 0 | public RetainedADI(Vector decisionVec){ |
83 | 0 | this.decisionHistoryVec = decisionVec; |
84 | } | |
85 | ||
86 | /** | |
87 | * This method adds a new DecisionRecord into the decisionHistoryVec. | |
88 | * | |
89 | * @params dr is the new DecisionRecord. | |
90 | * | |
91 | */ | |
92 | 32 | public void add(DecisionRecord dr){ |
93 | 32 | decisionHistoryVec.add(dr); |
94 | } | |
95 | ||
96 | /** | |
97 | * This method adds a new Vector of DecisionRecord into the | |
98 | * decisionHistoryVec. | |
99 | * | |
100 | * @params V is the new Vector of DecisionRecord. | |
101 | * | |
102 | */ | |
103 | 0 | public void addAll(Vector v){ |
104 | 0 | decisionHistoryVec.addAll(v); |
105 | } | |
106 | ||
107 | /** | |
108 | * This method returns the size of the decisionHistoryVec. | |
109 | */ | |
110 | 0 | public int size(){ |
111 | 0 | return decisionHistoryVec.size(); |
112 | } | |
113 | ||
114 | ||
115 | /** | |
116 | * This method retrieves a vector of history decision records according to | |
117 | * the policy contextname, instance contextname, and | |
118 | * userID. | |
119 | * | |
120 | * @params policyDN is the context name in the MSoD policy. | |
121 | * @params instanceDN is the user context instance. | |
122 | * @params userID is the user ID. | |
123 | * | |
124 | */ | |
125 | 32 | public Vector getHistoryRecords(ContextNamePrincipal policyDN, ContextNamePrincipal instanceDN, |
126 | String userID) { | |
127 | 32 | if (policyDN == null || instanceDN == null ) { |
128 | 0 | return null; |
129 | } | |
130 | 32 | ContextNamePrincipal instanceDNInst = policyDN.instantiate(instanceDN); |
131 | 32 | if (instanceDNInst == null) { |
132 | // System.out.println("One record 1: null 2"); | |
133 | 0 | return null; |
134 | } | |
135 | 32 | int size = decisionHistoryVec.size(); |
136 | 32 | DecisionRecord dr = null; |
137 | 32 | Vector result = new Vector(); |
138 | 214 | for (int i = 0; i<size; ++i){ |
139 | 182 | dr = (DecisionRecord) decisionHistoryVec.get(i); |
140 | 182 | ContextNamePrincipal cnp = null; |
141 | 182 | try { |
142 | 182 | cnp = new ContextNamePrincipal(dr.getContextInstance()); |
143 | } catch (Exception e) { | |
144 | } | |
145 | 182 | ContextNamePrincipal cnpInstantiated = policyDN.instantiate(cnp ); |
146 | 182 | if (cnpInstantiated == null) { |
147 | 146 | continue; |
148 | } | |
149 | ||
150 | // System.out.println("One record 1: " + cnpInstantiated.getName() ); | |
151 | // System.out.println("One record 2: " + instanceDNInst.getName() ); | |
152 | ||
153 | 36 | if ( instanceDNInst.equals( cnpInstantiated ) && |
154 | (dr.userID).compareTo(userID) == 0 ){ | |
155 | // System.out.println("One record in the history found: " + dr.toString()); | |
156 | 13 | result.add(dr); |
157 | } | |
158 | ||
159 | } | |
160 | ||
161 | 32 | return result; |
162 | ||
163 | } | |
164 | ||
165 | /** | |
166 | * This method deletes all decision records from the retained ADI which are | |
167 | * related to the instance contextname -- instanceDN according to the | |
168 | * policy context. | |
169 | * | |
170 | * @params policyDN is the context name in the MSoD policy. | |
171 | * @params instanceDN is the user context instance. | |
172 | * | |
173 | */ | |
174 | 3 | public void removeContext(ContextNamePrincipal policyDN, ContextNamePrincipal instanceDN){ |
175 | 3 | int size = decisionHistoryVec.size(); |
176 | 3 | ContextNamePrincipal instanceDNInstantiated = policyDN.instantiate(instanceDN); |
177 | ||
178 | 3 | DecisionRecord dr = null; |
179 | 21 | for (int i = size-1; i >= 0; i--){ |
180 | 18 | dr = (DecisionRecord) decisionHistoryVec.get(i); |
181 | 18 | ContextNamePrincipal cnp = null; |
182 | 18 | try { |
183 | 18 | cnp = new ContextNamePrincipal (dr.getContextInstance()); |
184 | } catch (Exception e) { | |
185 | } | |
186 | 18 | ContextNamePrincipal cnpInstantiated = policyDN.instantiate(cnp ); |
187 | 18 | if (cnpInstantiated == null) { |
188 | 15 | continue; |
189 | } | |
190 | 3 | if ( instanceDNInstantiated.equals( cnpInstantiated ) ){ |
191 | 3 | decisionHistoryVec.remove(i); |
192 | // System.out.println("retainedADI removing " + i); | |
193 | } | |
194 | } | |
195 | ||
196 | } | |
197 | ||
198 | } | |
199 | ||
200 |
|