%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.layout.impl.GetUserInformationAction |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
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 | 0 | protected Log log = LogFactory.getLog(GetUserInformationAction.class); |
50 | ||
51 | public GetUserInformationAction(String template, |
|
52 | String errorTemplate, |
|
53 | UserManager um, |
|
54 | RolesSecurityBehavior securityBehavior) |
|
55 | { |
|
56 | 0 | super(template, errorTemplate, um, securityBehavior); |
57 | 0 | } |
58 | ||
59 | public boolean run(RequestContext requestContext, Map resultMap) |
|
60 | throws AJAXException |
|
61 | { |
|
62 | 0 | boolean success = true; |
63 | 0 | String status = "success"; |
64 | try |
|
65 | { |
|
66 | 0 | resultMap.put(ACTION, "userinformation"); |
67 | // Get the necessary parameters off of the request |
|
68 | 0 | if(!requestContext.getUserPrincipal().getName().equals(userManager.getAnonymousUser())) |
69 | { |
|
70 | 0 | Principal principal = requestContext.getUserPrincipal(); |
71 | 0 | resultMap.put(USERNAME, principal.getName()); |
72 | 0 | resultMap.put(TYPE, principal.getClass().getName()); |
73 | ||
74 | // Loading the userinfo |
|
75 | 0 | User user = userManager.getUser(principal.getName()); |
76 | 0 | if(user != null) |
77 | { |
|
78 | 0 | Preferences prefs = user.getUserAttributes(); |
79 | 0 | String[] prefKeys = prefs.keys(); |
80 | 0 | Map prefsSet = new HashMap(); |
81 | 0 | for(int i = 0; i<prefKeys.length; i++) |
82 | { |
|
83 | 0 | prefsSet.put(prefKeys[i], prefs.get(prefKeys[i], "No value")); |
84 | } |
|
85 | 0 | resultMap.put(USERINFO, prefsSet); |
86 | ||
87 | } |
|
88 | ||
89 | 0 | } |
90 | else |
|
91 | { |
|
92 | 0 | status = "failure"; |
93 | 0 | resultMap.put(REASON, "Not logged in"); |
94 | 0 | return false; |
95 | } |
|
96 | 0 | resultMap.put(STATUS, status); |
97 | } |
|
98 | 0 | catch (Exception e) |
99 | { |
|
100 | 0 | log.error("exception with user account access", e); |
101 | 0 | resultMap.put(REASON, e.toString()); |
102 | 0 | success = false; |
103 | 0 | } |
104 | 0 | return success; |
105 | } |
|
106 | ||
107 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |