1
2
3
4
5 package pt.digitalis.dif.controller.objects;
6
7 import java.util.ArrayList;
8 import java.util.List;
9 import java.util.Map;
10 import java.util.Set;
11
12 import pt.digitalis.dif.controller.security.managers.IIdentityManager;
13 import pt.digitalis.dif.controller.security.objects.IDIFGroup;
14 import pt.digitalis.dif.controller.security.objects.IDIFInternalUser;
15 import pt.digitalis.dif.controller.security.objects.IDIFUser;
16 import pt.digitalis.dif.dem.Entity;
17 import pt.digitalis.dif.dem.interfaces.IStage;
18 import pt.digitalis.dif.exception.InternalFrameworkException;
19 import pt.digitalis.dif.exception.security.IdentityManagerException;
20 import pt.digitalis.dif.utils.ObjectFormatter;
21 import pt.digitalis.utils.common.collections.CaseInsensitiveHashMap;
22
23
24
25
26
27
28
29
30
31 public class DIFUserInSession implements IDIFInternalUser {
32
33
34 private List<String> attributesToRemove = new ArrayList<String>();
35
36
37 private boolean isDefault;
38
39
40 private String password;
41
42
43 private IDIFUser user;
44
45
46
47
48
49
50
51 public DIFUserInSession(IDIFUser user, String password)
52 {
53 this.user = user;
54 this.password = password;
55 }
56
57
58
59
60 public void addTempGroup(String groupId)
61 {
62 user.addTempGroup(groupId);
63 }
64
65
66
67
68
69 public boolean canAccess(Entity resourceType, String resourceId)
70 {
71 return user.canAccess(resourceType, resourceId);
72 }
73
74
75
76
77 public boolean canAccess(IStage stage)
78 {
79 return user.canAccess(stage);
80 }
81
82
83
84
85 public void cleanCache()
86 {
87 user.cleanCache();
88 }
89
90
91
92
93 public boolean containsAttribute(String id)
94 {
95 return user.containsAttribute(id);
96 }
97
98
99
100
101 public boolean containsParameter(String id)
102 {
103 return user.containsParameter(id);
104 }
105
106
107
108
109 public Object getAttribute(String id)
110 {
111 return user.getAttribute(id);
112 }
113
114
115
116
117 public CaseInsensitiveHashMap<Object> getAttributes()
118 {
119 return user.getAttributes();
120 }
121
122
123
124
125 public List<String> getAttributesToRemove()
126 {
127 return attributesToRemove;
128 }
129
130
131
132
133 public String getEmail()
134 {
135 return user.getEmail();
136 }
137
138
139
140
141 public Set<String> getGroupIDs() throws IdentityManagerException
142 {
143 return user.getGroupIDs();
144 }
145
146
147
148
149 public Map<String, IDIFGroup> getGroups() throws IdentityManagerException
150 {
151 return user.getGroups();
152 }
153
154
155
156
157 public String getID()
158 {
159 return user.getID();
160 }
161
162
163
164
165 public String getName()
166 {
167 return user.getName();
168 }
169
170
171
172
173 public String getNick()
174 {
175 return user.getNick();
176 }
177
178
179
180
181 public Object getParameter(String id)
182 {
183 return user.getParameter(id);
184 }
185
186
187
188
189 public Map<String, Object> getParameters()
190 {
191 return user.getParameters();
192 }
193
194
195
196
197 public String getPassword()
198 {
199 return this.password;
200 }
201
202
203
204
205 public IDIFGroup getProfile() throws IdentityManagerException
206 {
207 return user.getProfile();
208 }
209
210
211
212
213 public String getProfileID() throws IdentityManagerException
214 {
215 return user.getProfileID();
216 }
217
218
219
220
221 public void initializeAttributes(Map<String, Object> attrs)
222 {
223 user.initializeAttributes(attrs);
224 }
225
226
227
228
229 public boolean isDefault()
230 {
231 return this.isDefault;
232 }
233
234
235
236
237 public boolean isEnabled()
238 {
239 return user.isEnabled();
240 }
241
242
243
244
245 public void refresh()
246 {
247 user.refresh();
248 }
249
250
251
252
253 public void removeAttribute(String id)
254 {
255 user.removeAttribute(id);
256 attributesToRemove.add(id);
257 }
258
259
260
261
262 public void removeParameter(String id)
263 {
264 user.removeParameter(id);
265 }
266
267
268
269
270 public void removeTempGroup(String groupId)
271 {
272 user.removeTempGroup(groupId);
273 }
274
275
276
277
278 public void setAttribute(String id, Object attribute) throws InternalFrameworkException
279 {
280 user.setAttribute(id, attribute);
281 }
282
283
284
285
286 public void setAttributes(Map<String, Object> attributes) throws InternalFrameworkException
287 {
288 this.user.setAttributes(attributes);
289 }
290
291
292
293
294 public void setDefault(boolean isDefault)
295 {
296 this.isDefault = isDefault;
297 }
298
299
300
301
302 public void setEmail(String email)
303 {
304 user.setEmail(email);
305 }
306
307
308
309
310 public void setEnabled(boolean enabled)
311 {
312 user.setEnabled(enabled);
313 }
314
315
316
317
318 public void setID(String id)
319 {
320 user.setID(id);
321 }
322
323
324
325
326 public void setName(String name)
327 {
328 user.setName(name);
329 }
330
331
332
333
334 public void setNick(String nick)
335 {
336 user.setNick(nick);
337 }
338
339
340
341
342 public void setParameter(String id, Object parameter)
343 {
344 user.setParameter(id, parameter);
345 }
346
347
348
349
350 public void setParameters(Map<String, Object> parameters)
351 {
352 this.user.setParameters(parameters);
353 }
354
355
356
357
358 public void setPassword(String password)
359 {
360 user.setPassword(password);
361 this.password = password;
362 }
363
364
365
366
367 public void setProfileID(String profileGroupID)
368 {
369 user.setProfileID(profileGroupID);
370 }
371
372
373
374
375 @Override
376 public String toString()
377 {
378 ObjectFormatter formatter = new ObjectFormatter();
379
380 formatter.addItem("ID", getID());
381 formatter.addItemIfNotNull("Name", getName());
382 formatter.addItemIfNotNull("Password", "*****");
383 formatter.addItemIfNotNull("Nick", getNick());
384 formatter.addItemIfNotNull("Email", getEmail());
385 formatter.addItem("Enabled", isEnabled());
386 formatter.addItemIfNotNull("Attributes", this.getAttributes());
387 formatter.addItemIfNotNull("Parameters", this.getParameters());
388
389 try
390 {
391 IDIFGroup profile = getProfile();
392 formatter.addItem("Profile", profile);
393 }
394 catch (IdentityManagerException identityManagerException)
395 {
396 throw new RuntimeException("Could not access the user's profile on the identity manager!",
397 identityManagerException);
398 }
399
400 try
401 {
402 Map<String, IDIFGroup> groups = getGroups();
403 formatter.addItemIfNotNull("Groups", groups);
404 }
405 catch (IdentityManagerException identityManagerException)
406 {
407 throw new RuntimeException("Could not access the user's groups on the identity manager!",
408 identityManagerException);
409 }
410
411 return formatter.getFormatedObject();
412 }
413 }