1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.openpermis.policy.bean.basic; |
11 | |
|
12 | |
import java.net.URI; |
13 | |
import java.util.Collection; |
14 | |
|
15 | |
import org.joda.time.DateTimeZone; |
16 | |
|
17 | |
import org.openpermis.basic.TimePeriodConstraint; |
18 | |
import org.openpermis.policy.Action; |
19 | |
import org.openpermis.policy.ActionCollection; |
20 | |
import org.openpermis.policy.Authority; |
21 | |
import org.openpermis.policy.Domain; |
22 | |
import org.openpermis.policy.Obligation; |
23 | |
import org.openpermis.policy.ObligationCollection; |
24 | |
import org.openpermis.policy.ParameterList; |
25 | |
import org.openpermis.policy.Predicate; |
26 | |
import org.openpermis.policy.Role; |
27 | |
import org.openpermis.policy.RoleAssignmentRule; |
28 | |
import org.openpermis.policy.RoleAssignmentRuleCollection; |
29 | |
import org.openpermis.policy.RoleHierarchy; |
30 | |
import org.openpermis.policy.RoleHierarchyCollection; |
31 | |
import org.openpermis.policy.Target; |
32 | |
import org.openpermis.policy.TargetAccessRule; |
33 | |
import org.openpermis.policy.TargetAccessRuleCollection; |
34 | |
import org.openpermis.policy.TargetCollection; |
35 | |
import org.openpermis.policy.bean.ActionBean; |
36 | |
import org.openpermis.policy.bean.ActionBeanCollection; |
37 | |
import org.openpermis.policy.bean.AuthorityBean; |
38 | |
import org.openpermis.policy.bean.DomainBean; |
39 | |
import org.openpermis.policy.bean.ObligationBean; |
40 | |
import org.openpermis.policy.bean.ObligationBeanCollection; |
41 | |
import org.openpermis.policy.bean.PartBeanFactory; |
42 | |
import org.openpermis.policy.bean.PolicyBean; |
43 | |
import org.openpermis.policy.bean.RoleAssignmentRuleBean; |
44 | |
import org.openpermis.policy.bean.RoleAssignmentRuleBeanCollection; |
45 | |
import org.openpermis.policy.bean.RoleHierarchyBean; |
46 | |
import org.openpermis.policy.bean.RoleHierarchyBeanCollection; |
47 | |
import org.openpermis.policy.bean.SerialNumber; |
48 | |
import org.openpermis.policy.bean.TargetAccessRuleBean; |
49 | |
import org.openpermis.policy.bean.TargetAccessRuleBeanCollection; |
50 | |
import org.openpermis.policy.bean.TargetBean; |
51 | |
import org.openpermis.policy.bean.TargetBeanCollection; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | 3 | public class BasicPartBeanFactory |
58 | |
implements PartBeanFactory |
59 | |
{ |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
private final SerialNumber serialNumber; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | 414 | public BasicPartBeanFactory () { |
74 | 414 | this.serialNumber = SerialNumber.create(); |
75 | 414 | } |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
protected final SerialNumber nextSerial () { |
84 | 5467 | return getSerialNumber().next(); |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
public SerialNumber getSerialNumber () { |
93 | 5499 | return this.serialNumber; |
94 | |
} |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public ActionBean createAction (String name, ParameterList parameterList) { |
100 | 458 | return new BasicAction(nextSerial(), name, parameterList); |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
@SuppressWarnings("unchecked") |
107 | |
public ActionBeanCollection createActionCollection (Collection<? extends Action> collection) { |
108 | 603 | return new BasicActionCollection(nextSerial(), (Collection) collection); |
109 | |
} |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public AuthorityBean createAuthority (URI identity) { |
115 | 180 | return new BasicAuthority(nextSerial(), identity); |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public DomainBean createDomain (URI uri) { |
122 | 391 | return new BasicDomain(nextSerial(), uri); |
123 | |
} |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
public ObligationBean createObligation (String text) { |
129 | 130 | return new BasicObligation(nextSerial(), text); |
130 | |
} |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
@SuppressWarnings("unchecked") |
136 | |
public ObligationBeanCollection createObligationCollection ( |
137 | |
Collection<? extends Obligation> collection |
138 | |
) { |
139 | 582 | return new BasicObligationCollection(nextSerial(), (Collection) collection); |
140 | |
} |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
public PolicyBean createPolicy () { |
146 | 239 | return new BasicPolicy(nextSerial()); |
147 | |
} |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
public PolicyBean createPolicy ( |
159 | |
DateTimeZone zone, |
160 | |
RoleHierarchyCollection hierarchies, |
161 | |
TargetAccessRuleCollection targetAccessRules, |
162 | |
RoleAssignmentRuleCollection roleAssignmentRules |
163 | |
) { |
164 | 235 | final PolicyBean policy = createPolicy(); |
165 | 235 | policy.setDateTimeZone(zone); |
166 | 235 | policy.setRoleHierarchies((RoleHierarchyBeanCollection) hierarchies); |
167 | 235 | policy.setTargetAccessRules((TargetAccessRuleBeanCollection) targetAccessRules); |
168 | 235 | policy.setRoleAssignmentRules((RoleAssignmentRuleBeanCollection) roleAssignmentRules); |
169 | 235 | return policy; |
170 | |
} |
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
public RoleHierarchyBean createRoleHierarchy (URI uri) { |
176 | 329 | return new BasicRoleHierarchy(nextSerial(), uri); |
177 | |
} |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
@SuppressWarnings("unchecked") |
183 | |
public RoleHierarchyBeanCollection createRoleHierarchyCollection ( |
184 | |
Collection<? extends RoleHierarchy> collection) |
185 | |
{ |
186 | 247 | return new BasicRoleHierarchyCollection(nextSerial(), (Collection) collection); |
187 | |
} |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
public RoleAssignmentRuleBean createRoleAssignmentRule ( |
193 | |
Authority authority, |
194 | |
DomainBean subjectDomain, |
195 | |
Collection<Role> roles, |
196 | |
TimePeriodConstraint constraint, |
197 | |
int delegationDepth |
198 | |
) { |
199 | 226 | return new BasicRoleAssignmentRule( |
200 | |
nextSerial(), |
201 | |
(AuthorityBean) authority, |
202 | |
subjectDomain, |
203 | |
roles, |
204 | |
constraint, |
205 | |
delegationDepth |
206 | |
); |
207 | |
} |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
@SuppressWarnings("unchecked") |
213 | |
public RoleAssignmentRuleBeanCollection createRoleAssignmentRuleCollection ( |
214 | |
Collection<? extends RoleAssignmentRule> collection |
215 | |
) { |
216 | 249 | return new BasicRoleAssignmentRuleCollection(nextSerial(), (Collection) collection); |
217 | |
} |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
public TargetBean createTarget (Domain domain, ActionCollection actions) { |
223 | 550 | return new BasicTarget( |
224 | |
nextSerial(), |
225 | |
(DomainBean) domain, |
226 | |
(ActionBeanCollection) actions |
227 | |
); |
228 | |
} |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
@SuppressWarnings("unchecked") |
234 | |
public TargetBeanCollection createTargetCollection (Collection<? extends Target> collection) { |
235 | 551 | return new BasicTargetCollection(nextSerial(), (Collection) collection); |
236 | |
} |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
public TargetAccessRuleBean createTargetAccessRule ( |
242 | |
TargetCollection targets, |
243 | |
Collection<Role> roles, |
244 | |
Predicate condition, |
245 | |
ObligationCollection obligations |
246 | |
) { |
247 | 483 | return new BasicTargetAccessRule( |
248 | |
nextSerial(), |
249 | |
(TargetBeanCollection) targets, |
250 | |
roles, |
251 | |
condition, |
252 | |
(ObligationBeanCollection) obligations |
253 | |
); |
254 | |
} |
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
@SuppressWarnings("unchecked") |
260 | |
public TargetAccessRuleBeanCollection createTargetAccessRuleCollection ( |
261 | |
Collection<? extends TargetAccessRule> collection |
262 | |
) { |
263 | 249 | return new BasicTargetAccessRuleCollection(nextSerial(), (Collection) collection); |
264 | |
} |
265 | |
|
266 | |
|
267 | |
} |