Source code: org/apache/webapp/admin/users/ListUsersAction.java
1 /*
2 * Copyright 2002,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 package org.apache.webapp.admin.users;
19
20
21 import java.io.IOException;
22 import java.net.URLDecoder;
23 import java.util.Locale;
24 import javax.management.MBeanServer;
25 import javax.management.ObjectName;
26 import javax.servlet.ServletException;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import javax.servlet.http.HttpSession;
30 import org.apache.struts.action.Action;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34 import org.apache.struts.util.MessageResources;
35 import org.apache.webapp.admin.ApplicationServlet;
36 import org.apache.webapp.admin.TomcatTreeBuilder;
37
38 /**
39 * <p>Retrieve the set of MBean names for all currently defined users,
40 * and expose them in a request attribute named "usersForm". This action
41 * requires the following request parameters to be set:</p>
42 * <ul>
43 * <li><strong>databaseName</strong> - Object name of the UserDatabase
44 * MBean from which we should retrieve the users list.</li>
45 * <li><strong>forward</strong> - Global forward to which we should
46 * go after stashing the users list.</li>
47 * </ul>
48 *
49 * @author Craig R. McClanahan
50 * @version $Revision: 303390 $ $Date: 2004-10-18 02:37:56 -0400 (Mon, 18 Oct 2004) $
51 * @since 4.1
52 */
53
54 public class ListUsersAction extends Action {
55
56
57 // ----------------------------------------------------- Instance Variables
58
59
60 /**
61 * The MBeanServer we will be interacting with.
62 */
63 private MBeanServer mserver = null;
64
65
66 // --------------------------------------------------------- Public Methods
67
68
69 /**
70 * Process the specified HTTP request, and create the corresponding HTTP
71 * response (or forward to another web component that will create it).
72 * Return an <code>ActionForward</code> instance describing where and how
73 * control should be forwarded, or <code>null</code> if the response has
74 * already been completed.
75 *
76 * @param mapping The ActionMapping used to select this instance
77 * @param actionForm The optional ActionForm bean for this request (if any)
78 * @param request The HTTP request we are processing
79 * @param response The HTTP response we are creating
80 *
81 * @exception IOException if an input/output error occurs
82 * @exception ServletException if a servlet exception occurs
83 */
84 public ActionForward execute(ActionMapping mapping,
85 ActionForm form,
86 HttpServletRequest request,
87 HttpServletResponse response)
88 throws IOException, ServletException {
89
90
91 // Look up the components we will be using as needed
92 if (mserver == null) {
93 mserver = ((ApplicationServlet) getServlet()).getServer();
94 }
95 MessageResources resources = getResources(request);
96 HttpSession session = request.getSession();
97 Locale locale = getLocale(request);
98
99
100 // Create a form bean containing the requested MBean Names
101 String databaseName =
102 URLDecoder.decode(request.getParameter("databaseName"),TomcatTreeBuilder.URL_ENCODING);
103 UsersForm usersForm = null;
104 try {
105 usersForm = UserUtils.getUsersForm(mserver, databaseName);
106 } catch (Exception e) {
107 getServlet().log(resources.getMessage
108 (locale,
109 "users.error.attribute.get", "users"), e);
110 response.sendError
111 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
112 resources.getMessage
113 (locale, "users.error.attribute.get", "users"));
114 return null;
115 }
116
117 // Stash the results in request scope
118 request.setAttribute("usersForm", usersForm);
119 saveToken(request);
120 String forward =
121 URLDecoder.decode(request.getParameter("forward"),TomcatTreeBuilder.URL_ENCODING);
122 return (mapping.findForward(forward));
123
124 }
125
126 }