1
2
3
4
5 package pt.digitalis.dif.controller.security.objects;
6
7 import pt.digitalis.dif.dem.Entity;
8 import pt.digitalis.dif.utils.ObjectFormatter;
9
10
11
12
13
14
15
16
17 public class ACLEntry {
18
19
20
21
22
23
24
25
26 static public Entity getEntityTypeFromName(String entityName)
27 {
28
29 Entity result = null;
30
31 entityName = entityName.toLowerCase();
32
33 if (entityName.equals(Entity.VALIDATOR.getName().toLowerCase()))
34 result = Entity.VALIDATOR;
35 else if (entityName.equals(Entity.PROVIDER.getName().toLowerCase()))
36 result = Entity.PROVIDER;
37 else if (entityName.equals(Entity.APPLICATION.getName().toLowerCase()))
38 result = Entity.APPLICATION;
39 else if (entityName.equals(Entity.SERVICE.getName().toLowerCase()))
40 result = Entity.SERVICE;
41 else if (entityName.equals(Entity.STAGE.getName().toLowerCase()))
42 result = Entity.STAGE;
43
44 return result;
45 }
46
47
48
49
50
51
52
53
54 static public String getTypeNameFromEntity(Entity entity)
55 {
56 String result = null;
57
58 if (entity.equals(Entity.VALIDATOR))
59 result = Entity.VALIDATOR.getName();
60 else if (entity.equals(Entity.PROVIDER))
61 result = Entity.PROVIDER.getName();
62 else if (entity.equals(Entity.APPLICATION))
63 result = Entity.APPLICATION.getName();
64 else if (entity.equals(Entity.SERVICE))
65 result = Entity.SERVICE.getName();
66 else if (entity.equals(Entity.STAGE))
67 result = Entity.STAGE.getName();
68 else
69 result = "";
70
71 return result.toLowerCase();
72 }
73
74
75 private String entityID;
76
77
78 private Entity entityType;
79
80
81 private String groupID;
82
83
84 private boolean isDefault;
85
86
87 private boolean isEnabled;
88
89
90 private boolean publicAccess;
91
92
93 private String userID;
94
95
96 public ACLEntry()
97 {
98 this.userID = null;
99 this.groupID = null;
100 this.entityType = null;
101 this.entityID = null;
102 this.publicAccess = false;
103 this.isEnabled = true;
104 this.isDefault = false;
105 }
106
107
108
109
110 @Override
111 public boolean equals(Object obj)
112 {
113 ACLEntry entry = (ACLEntry) obj;
114 boolean same = true;
115
116
117 if (isUserACL())
118 same = same && this.getUserID().equals(entry.getUserID());
119 else if (isGroupACL())
120 same = same && this.getGroupID().equals(entry.getGroupID());
121
122
123
124 if (this.entityID != null && entry.entityID != null)
125 same = same && this.getEntityID().equals(entry.getEntityID());
126
127 if (this.entityType != null && entry.entityType != null)
128 same = same && this.getEntityType().equals(entry.getEntityType());
129
130 same = same && this.isDefault() == entry.isDefault();
131 same = same && this.isEnabled() == entry.isEnabled();
132 same = same && this.isPublicAccess() == entry.isPublicAccess();
133
134 return same;
135 }
136
137
138
139
140
141
142 public String getEntityID()
143 {
144 return entityID;
145 }
146
147
148
149
150
151
152 public Entity getEntityType()
153 {
154 return entityType;
155 }
156
157
158
159
160
161
162 public String getGroupID()
163 {
164 return groupID;
165 }
166
167
168
169
170
171
172 public String getUserID()
173 {
174 return userID;
175 }
176
177
178
179
180 @Override
181 public int hashCode()
182 {
183
184 final int ODD_PRIME_FACTOR = 37;
185 final int ODD_PRIME_TRUE = 1231;
186 final int ODD_PRIME_FALSE = 1237;
187
188 int result = 17;
189
190 if (this.isUserACL())
191 result = ODD_PRIME_FACTOR * result + this.userID.hashCode();
192 else if (this.isGroupACL())
193 result = ODD_PRIME_FACTOR * result + this.groupID.hashCode();
194
195 result = ODD_PRIME_FACTOR * result + (publicAccess ? ODD_PRIME_TRUE : ODD_PRIME_FALSE);
196 result = ODD_PRIME_FACTOR * result + (this.entityID == null ? 0 : this.entityID.hashCode());
197 result = ODD_PRIME_FACTOR * result + (this.entityType == null ? 0 : this.entityType.hashCode());
198 result = ODD_PRIME_FACTOR * result + (isDefault ? ODD_PRIME_TRUE : ODD_PRIME_FALSE);
199 result = ODD_PRIME_FACTOR * result + (isEnabled ? ODD_PRIME_TRUE : ODD_PRIME_FALSE);
200
201 return result;
202 }
203
204
205
206
207
208
209 public boolean isDefault()
210 {
211 return this.isDefault;
212 }
213
214
215
216
217
218
219 public boolean isEnabled()
220 {
221 return this.isEnabled;
222 }
223
224
225
226
227
228
229 public boolean isGroupACL()
230 {
231 return (this.groupID != null);
232 }
233
234
235
236
237
238
239 public boolean isPublicAccess()
240 {
241 return publicAccess;
242 }
243
244
245
246
247
248
249 public boolean isUserACL()
250 {
251 return (this.userID != null);
252 }
253
254
255
256
257
258
259
260 public void setDefault(boolean isDefault)
261 {
262 this.isDefault = isDefault;
263 }
264
265
266
267
268
269
270
271 public void setEnabled(boolean isEnabled)
272 {
273 this.isEnabled = isEnabled;
274 }
275
276
277
278
279
280
281
282 public void setEntityID(String entityID)
283 {
284 this.entityID = entityID;
285 }
286
287
288
289
290
291
292
293 public void setEntityType(Entity entityType)
294 {
295 this.entityType = entityType;
296 }
297
298
299
300
301
302
303
304 public void setGroupID(String groupID)
305 {
306 this.groupID = groupID;
307 this.userID = null;
308 this.publicAccess = false;
309 }
310
311
312
313
314 public void setPublicAccess()
315 {
316 this.publicAccess = true;
317 this.userID = null;
318 this.groupID = null;
319 }
320
321
322
323
324
325
326
327 public void setUserID(String userID)
328 {
329 this.userID = userID;
330 this.groupID = null;
331 this.publicAccess = false;
332 }
333
334
335
336
337 @Override
338 public String toString()
339 {
340 ObjectFormatter formatter = new ObjectFormatter();
341 formatter.addItemIfNotNull("User ID", userID);
342 formatter.addItemIfNotNull("Group ID", groupID);
343 formatter.addItemIfNotNull("Public Access", publicAccess);
344 formatter.addItemIfNotNull("Entity Type", entityType);
345 formatter.addItemIfNotNull("Entity ID", entityID);
346 formatter.addItemIfNotNull("Default", isDefault);
347 formatter.addItemIfNotNull("Enabled", isEnabled);
348
349 return formatter.getFormatedObject();
350 }
351
352 }