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