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.Iterator; |
22 |
|
import java.util.Map; |
23 |
|
import java.util.List; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.prefs.Preferences; |
26 |
|
|
27 |
|
import javax.security.auth.Subject; |
28 |
|
|
29 |
|
import org.apache.commons.logging.Log; |
30 |
|
import org.apache.commons.logging.LogFactory; |
31 |
|
import org.apache.jetspeed.Jetspeed; |
32 |
|
import org.apache.jetspeed.administration.PortalConfiguration; |
33 |
|
import org.apache.jetspeed.ajax.AJAXException; |
34 |
|
import org.apache.jetspeed.ajax.AjaxAction; |
35 |
|
import org.apache.jetspeed.ajax.AjaxBuilder; |
36 |
|
import org.apache.jetspeed.layout.PortletActionSecurityBehavior; |
37 |
|
import org.apache.jetspeed.request.RequestContext; |
38 |
|
import org.apache.jetspeed.security.RolePrincipal; |
39 |
|
import org.apache.jetspeed.security.User; |
40 |
|
import org.apache.jetspeed.security.UserManager; |
41 |
|
import org.apache.jetspeed.security.impl.RolePrincipalImpl; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
public class GetUserInformationAction |
56 |
|
extends BaseUserAction |
57 |
|
implements AjaxAction, AjaxBuilder, Constants |
58 |
|
{ |
59 |
0 |
protected Log log = LogFactory.getLog(GetUserInformationAction.class); |
60 |
|
|
61 |
|
public GetUserInformationAction(String template, |
62 |
|
String errorTemplate, |
63 |
|
UserManager um, |
64 |
|
RolesSecurityBehavior rolesSecurityBehavior) |
65 |
|
{ |
66 |
0 |
super(template, errorTemplate, um, rolesSecurityBehavior); |
67 |
0 |
} |
68 |
|
|
69 |
|
public boolean run(RequestContext requestContext, Map resultMap) |
70 |
|
throws AJAXException |
71 |
|
{ |
72 |
0 |
boolean success = true; |
73 |
0 |
String status = "success"; |
74 |
|
try |
75 |
|
{ |
76 |
0 |
resultMap.put(ACTION, "userinformation"); |
77 |
|
|
78 |
0 |
if(!requestContext.getUserPrincipal().getName().equals(userManager.getAnonymousUser())) |
79 |
|
{ |
80 |
0 |
Principal principal = requestContext.getUserPrincipal(); |
81 |
0 |
resultMap.put(USERNAME, principal.getName()); |
82 |
0 |
resultMap.put(TYPE, principal.getClass().getName()); |
83 |
|
|
84 |
|
|
85 |
0 |
User user = userManager.getUser(principal.getName()); |
86 |
0 |
if(user != null) |
87 |
|
{ |
88 |
0 |
Preferences prefs = user.getUserAttributes(); |
89 |
0 |
String[] prefKeys = prefs.keys(); |
90 |
0 |
Map prefsSet = new HashMap(); |
91 |
0 |
for(int i = 0; i<prefKeys.length; i++) |
92 |
|
{ |
93 |
0 |
prefsSet.put(prefKeys[i], prefs.get(prefKeys[i], "No value")); |
94 |
|
} |
95 |
0 |
resultMap.put(USERINFO, prefsSet); |
96 |
|
|
97 |
0 |
List roles = new ArrayList(); |
98 |
0 |
Subject userSubject = user.getSubject(); |
99 |
0 |
if ( userSubject != null ) |
100 |
|
{ |
101 |
0 |
Iterator rolesIter = userSubject.getPrincipals( RolePrincipalImpl.class ).iterator(); |
102 |
0 |
while ( rolesIter.hasNext() ) |
103 |
|
{ |
104 |
0 |
RolePrincipal role = (RolePrincipal)rolesIter.next(); |
105 |
0 |
roles.add( role.getName() ); |
106 |
0 |
} |
107 |
|
} |
108 |
0 |
resultMap.put( ROLES, roles); |
109 |
|
} |
110 |
0 |
} |
111 |
|
else |
112 |
|
{ |
113 |
0 |
status = "failure"; |
114 |
0 |
resultMap.put(REASON, "Not logged in"); |
115 |
0 |
return false; |
116 |
|
} |
117 |
0 |
resultMap.put(STATUS, status); |
118 |
|
} |
119 |
0 |
catch (Exception e) |
120 |
|
{ |
121 |
0 |
log.error("exception with user account access", e); |
122 |
0 |
resultMap.put(REASON, e.toString()); |
123 |
0 |
success = false; |
124 |
0 |
} |
125 |
0 |
return success; |
126 |
|
} |
127 |
|
|
128 |
|
} |