1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.layout.impl;
18
19 import java.security.Principal;
20 import java.util.HashMap;
21 import java.util.Map;
22 import java.util.prefs.Preferences;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.jetspeed.ajax.AJAXException;
27 import org.apache.jetspeed.ajax.AjaxAction;
28 import org.apache.jetspeed.ajax.AjaxBuilder;
29 import org.apache.jetspeed.request.RequestContext;
30 import org.apache.jetspeed.security.User;
31 import org.apache.jetspeed.security.UserManager;
32
33 /***
34 * Retrieve user information of the current user
35 *
36 * AJAX action:
37 * action = getuserinfo
38 *
39 * AJAX Parameters:
40 * none
41 *
42 * @author <a href="mailto:mikko.wuokko@evtek.fi">Mikko Wuokko</a>
43 * @version $Id: $
44 */
45 public class GetUserInformationAction
46 extends BaseUserAction
47 implements AjaxAction, AjaxBuilder, Constants
48 {
49 protected Log log = LogFactory.getLog(GetUserInformationAction.class);
50
51 public GetUserInformationAction(String template,
52 String errorTemplate,
53 UserManager um,
54 RolesSecurityBehavior securityBehavior)
55 {
56 super(template, errorTemplate, um, securityBehavior);
57 }
58
59 public boolean run(RequestContext requestContext, Map resultMap)
60 throws AJAXException
61 {
62 boolean success = true;
63 String status = "success";
64 try
65 {
66 resultMap.put(ACTION, "userinformation");
67
68 if(!requestContext.getUserPrincipal().getName().equals(userManager.getAnonymousUser()))
69 {
70 Principal principal = requestContext.getUserPrincipal();
71 resultMap.put(USERNAME, principal.getName());
72 resultMap.put(TYPE, principal.getClass().getName());
73
74
75 User user = userManager.getUser(principal.getName());
76 if(user != null)
77 {
78 Preferences prefs = user.getUserAttributes();
79 String[] prefKeys = prefs.keys();
80 Map prefsSet = new HashMap();
81 for(int i = 0; i<prefKeys.length; i++)
82 {
83 prefsSet.put(prefKeys[i], prefs.get(prefKeys[i], "No value"));
84 }
85 resultMap.put(USERINFO, prefsSet);
86
87 }
88
89 }
90 else
91 {
92 status = "failure";
93 resultMap.put(REASON, "Not logged in");
94 return false;
95 }
96 resultMap.put(STATUS, status);
97 }
98 catch (Exception e)
99 {
100 log.error("exception with user account access", e);
101 resultMap.put(REASON, e.toString());
102 success = false;
103 }
104 return success;
105 }
106
107 }