craigmcc 02/01/29 18:05:44
Modified: catalina/src/share/org/apache/catalina/mbeans UserMBean.java
webapps/admin listUsers.jsp
webapps/admin/WEB-INF controls.tld struts-config.xml
webapps/admin/WEB-INF/classes/org/apache/webapp/admin
ActionTag.java ApplicationResources_en.properties
Added: webapps/admin user.jsp
webapps/admin/WEB-INF/classes/org/apache/webapp/admin
SaveUserAction.java SetUpUserAction.java
UserForm.java
Log:
Initial checkin of logic to update existing users (including saving the
update to disk).
TODOs:
* Support add and delete user options as well.
* Display group memberships and authorized roles as sets of checkboxes
for easier updates.
* Fix bug in modeler's support for setting a String-array property.
* Add the notion of a Role (name,description) in the UserDatabase,
and the corresponding MBeans.
Revision Changes Path
1.2 +18 -3
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/UserMBean.java
Index: UserMBean.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/UserMBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UserMBean.java 22 Jan 2002 23:22:24 -0000 1.1
+++ UserMBean.java 30 Jan 2002 02:05:44 -0000 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/UserMBean.java,v
1.1 2002/01/22 23:22:24 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2002/01/22 23:22:24 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/UserMBean.java,v
1.2 2002/01/30 02:05:44 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2002/01/30 02:05:44 $
*
* ====================================================================
*
@@ -84,7 +84,7 @@
* <code>org.apache.catalina.User</code> component.</p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2002/01/22 23:22:24 $
+ * @version $Revision: 1.2 $ $Date: 2002/01/30 02:05:44 $
*/
public class UserMBean extends BaseModelMBean {
@@ -172,6 +172,21 @@
results.add(roles.next());
}
return ((String[]) results.toArray(new String[results.size()]));
+
+ }
+
+
+ /**
+ * Update the set of authorized roles for this user.
+ */
+ public void setRoles(String roles[]) {
+
+ if (roles != null) {
+ User user = (User) this.resource;
+ for (int i = 0; i < roles.length; i++) {
+ user.addRole(roles[i]);
+ }
+ }
}
1.2 +7 -5 jakarta-tomcat-4.0/webapps/admin/listUsers.jsp
Index: listUsers.jsp
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/listUsers.jsp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- listUsers.jsp 23 Jan 2002 23:06:53 -0000 1.1
+++ listUsers.jsp 30 Jan 2002 02:05:44 -0000 1.2
@@ -33,12 +33,11 @@
<controls:action>
---------------------------------
</controls:action>
- <controls:action url="">
+<%--
+ <controls:action url="/setUpUser.do">
<bean:message key="actions.user.create"/>
</controls:action>
- <controls:action url="">
- <bean:message key="actions.user.delete"/>
- </controls:action>
+--%>
<!-- add the urls later once those screens get implemented -->
</controls:actions>
</div>
@@ -68,7 +67,10 @@
<logic:iterate name="users" id="user">
<tr class="line-row">
<td><div align="left" class="table-normal-text">
- <controls:attribute name="user" attribute="username"/>
+ <html:link page='<%= "/setUpUser.do?objectName=" +
+ java.net.URLEncoder.encode(user.toString()) %>'>
+ <controls:attribute name="user" attribute="username"/>
+ </html:link>
</div></td>
<td><div align="left" class="table-normal-text">
<controls:attribute name="user" attribute="fullName"/>
1.1 jakarta-tomcat-4.0/webapps/admin/user.jsp
Index: user.jsp
===================================================================
<!-- Standard Struts Entries -->
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/controls.tld" prefix="controls" %>
<html:html locale="true">
<%@ include file="header.jsp" %>
<!-- Body -->
<body bgcolor="white">
<!--Form -->
<html:errors/>
<html:form method="POST" action="/saveUser" focus="username">
<html:hidden property="objectName"/>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="page-title-row">
<td align="left" nowrap>
<div class="page-title-text">
<bean:write name="userForm" property="nodeLabel"/>
</div>
</td>
<td align="right" nowrap>
<div class="page-title-text">
<controls:actions>
<controls:action selected="true">
----<bean:message key="actions.available.actions"/>----
</controls:action>
<controls:action>
---------------------------------
</controls:action>
<!-- will add the urls later once those screens get implemented -->
<%--
<controls:action url="">
<bean:message key="actions.services.create"/>
</controls:action>
<controls:action url="">
<bean:message key="actions.services.delete"/>
</controls:action>
--%>
</controls:actions>
</div>
</td>
</tr>
</table>
<%@ include file="buttons.jsp" %>
<br>
<table class="back-table" border="0" cellspacing="0" cellpadding="1"
width="100%">
<tr>
<td>
<controls:table tableStyle="front-table" lineStyle="line-row">
<controls:row header="true"
labelStyle="table-header-text" dataStyle="table-header-text">
<controls:label>
<bean:message key="user.properties"/>
</controls:label>
<controls:data>
</controls:data>
</controls:row>
<controls:row labelStyle="table-label-text"
dataStyle="table-normal-text">
<controls:label>
<bean:message key="user.username"/>:
</controls:label>
<controls:data>
<logic:present name="userForm" property="objectName">
<bean:write name="userForm" property="username"/>
<html:hidden property="username"/>
</logic:present>
<logic:notPresent name="userForm" property="objectName">
<html:text property="username" size="24" maxlength="32"/>
</logic:notPresent>
</controls:data>
</controls:row>
<controls:row labelStyle="table-label-text"
dataStyle="table-normal-text">
<controls:label>
<bean:message key="user.password"/>:
</controls:label>
<controls:data>
<html:text property="password" size="24" maxlength="32"/>
</controls:data>
</controls:row>
<controls:row labelStyle="table-label-text"
dataStyle="table-normal-text">
<controls:label>
<bean:message key="user.fullName"/>:
</controls:label>
<controls:data>
<html:text property="fullName" size="24" maxlength="64"/>
</controls:data>
</controls:row>
<controls:row labelStyle="table-label-text"
dataStyle="table-normal-text">
<controls:label>
<bean:message key="user.groups"/>:
</controls:label>
<controls:data>
<%-- FIXME - list of checkboxes --%>
<logic:present name="userForm" property="groups">
<bean:write name="userForm" property="groups"/>
</logic:present>
</controls:data>
</controls:row>
<controls:row labelStyle="table-label-text"
dataStyle="table-normal-text">
<controls:label>
<bean:message key="user.roles"/>:
</controls:label>
<controls:data>
<%-- FIXME - list of checkboxes --%>
<logic:present name="userForm" property="roles">
<bean:write name="userForm" property="roles"/>
</logic:present>
</controls:data>
</controls:row>
</controls:table>
</td>
</tr>
</table>
<%@ include file="buttons.jsp" %>
</html:form>
<!-- Standard Footer -->
<%@ include file="footer.jsp" %>
</body>
</html:html>
1.5 +4 -0 jakarta-tomcat-4.0/webapps/admin/WEB-INF/controls.tld
Index: controls.tld
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/controls.tld,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- controls.tld 23 Jan 2002 23:06:53 -0000 1.4
+++ controls.tld 30 Jan 2002 02:05:44 -0000 1.5
@@ -215,6 +215,10 @@
URL is specified, no action will be taken (useful for "(None)"
options and dividers).
+ If this URL starts with a slash, it will be assumed to be
+ context-relative, and will be prefixed with the context path
+ of this request. Otherwise, it will be used unmodified.
+
NOTE: This URL will be passed through URL rewriting so that it
will maintain session identity even in environments were cookies
are not being used.
1.19 +24 -1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/struts-config.xml
Index: struts-config.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/struts-config.xml,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- struts-config.xml 26 Jan 2002 22:39:45 -0000 1.18
+++ struts-config.xml 30 Jan 2002 02:05:44 -0000 1.19
@@ -51,6 +51,10 @@
<form-bean name="listUsersForm"
type="org.apache.webapp.admin.ListUsersForm"/>
+ <!-- User form bean -->
+ <form-bean name="userForm"
+ type="org.apache.webapp.admin.UserForm"/>
+
</form-beans>
@@ -110,10 +114,18 @@
path="/listUsers.jsp"
redirect="false"/>
+ <forward name="Users List Setup"
+ path="/listUsers.do"
+ redirect="false"/>
+
<forward name="Logger"
path="/logger.jsp"
redirect="false"/>
+ <forward name="User"
+ path="/user.jsp"
+ redirect="false"/>
+
</global-forwards>
@@ -270,10 +282,21 @@
name="listGroupsForm"
type="org.apache.webapp.admin.ListGroupsAction"/>
- <!-- Set up users list axction -->
+ <!-- Set up users list action -->
<action path="/listUsers"
name="listUsersForm"
type="org.apache.webapp.admin.ListUsersAction"/>
+
+ <!-- Set up user action -->
+ <action path="/setUpUser"
+ type="org.apache.webapp.admin.SetUpUserAction"/>
+
+ <!-- Save user action -->
+ <action path="/saveUser"
+ input="/user.jsp"
+ name="userForm"
+ scope="request"
+ type="org.apache.webapp.admin.SaveUserAction"/>
</action-mappings>
1.2 +14 -5
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ActionTag.java
Index: ActionTag.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ActionTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ActionTag.java 19 Dec 2001 01:58:10 -0000 1.1
+++ ActionTag.java 30 Jan 2002 02:05:44 -0000 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ActionTag.java,v
1.1 2001/12/19 01:58:10 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2001/12/19 01:58:10 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ActionTag.java,v
1.2 2002/01/30 02:05:44 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2002/01/30 02:05:44 $
*
* ====================================================================
*
@@ -66,6 +66,7 @@
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
@@ -91,7 +92,7 @@
* <strong>FIXME</strong> - Internationalize the exception messages!
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/12/19 01:58:10 $
+ * @version $Revision: 1.2 $ $Date: 2002/01/30 02:05:44 $
*/
public class ActionTag extends BodyTagSupport {
@@ -189,10 +190,18 @@
// Register the information for the action represented by
// this action
+ HttpServletRequest request =
+ (HttpServletRequest) pageContext.getRequest();
HttpServletResponse response =
(HttpServletResponse) pageContext.getResponse();
+ String path = null;
+ if ((url != null) && (url.startsWith("/"))) {
+ path = request.getContextPath() + url;
+ } else {
+ path = url;
+ }
actions.addAction(label, selected,
- response.encodeURL(url));
+ response.encodeURL(path));
return (EVAL_PAGE);
1.17 +12 -0
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_en.properties
Index: ApplicationResources_en.properties
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_en.properties,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ApplicationResources_en.properties 29 Jan 2002 01:15:55 -0000 1.16
+++ ApplicationResources_en.properties 30 Jan 2002 02:05:44 -0000 1.17
@@ -151,3 +151,15 @@
error.directory.required=<li>Directory cannot be empty.</li>
error.prefix.required=<li>Prefix cannot be empty.</li>
error.suffix.required=<li>Suffix cannot be empty.</li>
+user.fullName=Full Name
+user.groups=Member in Groups
+user.newUser=Create New User Properties
+user.oldUser=Edit Existing User Properties
+user.password=Password
+user.properties=User Properties
+user.roles=Security Roles
+user.username=Username
+error.password.required=<li>Password is required</li>
+error.username.required=<li>Username is required</li>
+error.get.attributes=Error retrieving information properties
+error.set.attributes=Error setting information properties
1.1
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SaveUserAction.java
Index: SaveUserAction.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SaveUserAction.java,v
1.1 2002/01/30 02:05:44 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/01/30 02:05:44 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.webapp.admin;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.QueryExp;
import javax.management.Query;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.JMException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanInfo;
import org.apache.struts.util.MessageResources;
/**
* <p>Implementation of <strong>Action</strong> that saves a new or
* updated User back to the underlying database.</p>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/01/30 02:05:44 $
*/
public final class SaveUserAction extends Action {
// ----------------------------------------------------- Instance Variables
/**
* The MessageResources we will be retrieving messages from.
*/
private MessageResources resources = null;
/**
* The MBeanServer we will be interacting with.
*/
private MBeanServer mserver = null;
// --------------------------------------------------------- Public Methods
/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it).
* Return an <code>ActionForward</code> instance describing where and how
* control should be forwarded, or <code>null</code> if the response has
* already been completed.
*
* @param mapping The ActionMapping used to select this instance
* @param actionForm The optional ActionForm bean for this request (if any)
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet exception occurs
*/
public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// Look up the components we will be using as needed
if (mserver == null) {
mserver = ((ApplicationServlet) getServlet()).getServer();
}
if (resources == null) {
resources = getServlet().getResources();
}
HttpSession session = request.getSession();
Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
// Has this transaction been cancelled?
if (isCancelled(request)) {
; // FIXME - confirmation message?
return (mapping.findForward("List Users Setup"));
}
// Perform any extra validation that is required
; // FIXME - (set and) check transaction token
UserForm userForm = (UserForm) form;
String objectName = userForm.getObjectName();
// Perform an "Add User" transaction
if (objectName == null) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Add User not yet supported");
return (null);
}
// Perform an "Update User" transaction
else {
try {
ObjectName oname = new ObjectName(objectName);
// Update the specified user
; // NOTE - cannot change username on an update
mserver.setAttribute
(oname,
new Attribute("password", userForm.getPassword()));
mserver.setAttribute
(oname,
new Attribute("fullName", userForm.getFullName()));
/* FIXME - does not work yet
String values = userForm.getRoles();
if (values == null) {
values = "";
}
ArrayList results = new ArrayList();
while (values.length() > 0) {
int comma = values.indexOf(",");
if (comma < 0) {
break;
}
results.add(values.substring(0, comma).trim());
values = values.substring(comma + 1);
}
values = values.trim();
if (values.length() > 0) {
results.add(values);
}
String roles[] = new String[results.size()];
roles = (String[]) results.toArray(roles);
mserver.setAttribute
(oname,
new Attribute("roles", roles));
*/
// Tell the database to save the updated information
ObjectName dname =
new ObjectName(oname.getDomain() +
":type=UserDatabase,database=" +
oname.getKeyProperty("database"));
mserver.invoke(dname, "save",
new Object[0], new String[0]);
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale, "error.set.attributes"), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage(locale, "error.set.attributes"));
return (null);
}
return (mapping.findForward("Users List Setup"));
}
}
}
1.1
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpUserAction.java
Index: SetUpUserAction.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpUserAction.java,v
1.1 2002/01/30 02:05:44 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/01/30 02:05:44 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.webapp.admin;
import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.QueryExp;
import javax.management.Query;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.JMException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanInfo;
import org.apache.struts.util.MessageResources;
/**
* <p>Implementation of <strong>Action</strong> that sets up and stashes
* a <code>UserForm</code> bean in request scope. The form bean will have
* a null <code>objectName</code> property if this form represents a user
* being added, or a non-null value for an existing user.</p>
*
* <p>The object name of the user to be edited (if any) is specified by
* a request parameter named <code>objectName</code> included on the
* request that selected this action.</p>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/01/30 02:05:44 $
*/
public final class SetUpUserAction extends Action {
// ----------------------------------------------------- Instance Variables
/**
* The MBeanServer we will be interacting with.
*/
private MBeanServer mserver = null;
/**
* The MessageResources we will be retrieving messages from.
*/
private MessageResources resources = null;
// --------------------------------------------------------- Public Methods
/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it).
* Return an <code>ActionForward</code> instance describing where and how
* control should be forwarded, or <code>null</code> if the response has
* already been completed.
*
* @param mapping The ActionMapping used to select this instance
* @param actionForm The optional ActionForm bean for this request (if any)
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet exception occurs
*/
public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// Look up the components we will be using as needed
if (mserver == null) {
mserver = ((ApplicationServlet) getServlet()).getServer();
}
if (resources == null) {
resources = getServlet().getResources();
}
HttpSession session = request.getSession();
Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
// Set up the form bean based on the creating or editing state
String objectName = request.getParameter("objectName");
UserForm userForm = new UserForm();
if (objectName == null) {
userForm.setNodeLabel
(resources.getMessage(locale, "user.newUser"));
} else {
userForm.setNodeLabel
(resources.getMessage(locale, "user.oldUser"));
userForm.setObjectName(objectName);
try {
ObjectName oname = new ObjectName(objectName);
userForm.setUsername
((String) mserver.getAttribute(oname, "username"));
userForm.setPassword
((String) mserver.getAttribute(oname, "password"));
userForm.setFullName
((String) mserver.getAttribute(oname, "fullName"));
String groups[] =
(String[]) mserver.getAttribute(oname, "groups");
if (groups == null) {
groups = new String[0];
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < groups.length; i++) {
if (i > 0) {
sb.append(',');
}
sb.append(groups[i]);
}
if (groups.length > 0) {
userForm.setGroups(sb.toString());
}
String roles[] =
(String[]) mserver.getAttribute(oname, "roles");
if (roles == null) {
roles = new String[0];
}
sb = new StringBuffer();
for (int i = 0; i < roles.length; i++) {
if (i > 0) {
sb.append(',');
}
sb.append(roles[i]);
}
if (roles.length > 0) {
userForm.setRoles(sb.toString());
}
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale, "error.get.attributes"), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage(locale, "error.get.attributes"));
return (null);
}
}
// Stash the form bean and forward to the display page
request.setAttribute("userForm", userForm);
return (mapping.findForward("User"));
}
}
1.1
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/UserForm.java
Index: UserForm.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/UserForm.java,v
1.1 2002/01/30 02:05:44 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/01/30 02:05:44 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.webapp.admin;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
* Form bean for the individual user page.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/01/30 02:05:44 $
*/
public final class UserForm extends ActionForm {
// ----------------------------------------------------- Instance Variables
// ------------------------------------------------------------- Properties
/**
* The full name of the associated user.
*/
private String fullName = null;
public String getFullName() {
return (this.fullName);
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
/**
* A comma-delimited list of the groups this user is a member of.
*/
private String groups = null;
public String getGroups() {
return (this.groups);
}
public void setGroups(String groups) {
this.groups = groups;
}
/**
* The node label to be displayed in the user interface (not a property
* of the underlying database object).
*/
private String nodeLabel = null;
public String getNodeLabel() {
return (this.nodeLabel);
}
public void setNodeLabel(String nodeLabel) {
this.nodeLabel = nodeLabel;
}
/**
* The MBean object name of this user, or <code>null</code> if this
* form represents a new user.
*/
private String objectName = null;
public String getObjectName() {
return (this.objectName);
}
public void setObjectName(String objectName) {
this.objectName = objectName;
}
/**
* The password of the associated user.
*/
private String password = null;
public String getPassword() {
return (this.password);
}
public void setPassword(String password) {
this.password = password;
}
/**
* A comma-delimited list of the security roles associated
* with this user. <strong>FIXME</strong> - implement as a
* List instead, with predefined values?
*/
private String roles = null;
public String getRoles() {
return (this.roles);
}
public void setRoles(String roles) {
this.roles = roles;
}
/**
* The username of the associated user.
*/
private String username = null;
public String getUsername() {
return (this.username);
}
public void setUsername(String username) {
this.username = username;
}
// --------------------------------------------------------- Public Methods
/**
* Reset all properties to their default values.
*
* @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
fullName = null;
groups = null;
nodeLabel = null;
password = null;
roles = null;
username = null;
}
/**
* Validate the properties that have been set from this HTTP request,
* and return an <code>ActionErrors</code> object that encapsulates any
* validation errors that have been found. If no errors are found, return
* <code>null</code> or an <code>ActionErrors</code> object with no
* recorded error messages.
*
* @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
String submit = request.getParameter("submit");
if (submit != null) {
// Username is a required field
if (username == null) {
errors.add("username",
new ActionError("error.username.required"));
}
// Password is a required field
if (password == null) {
errors.add("password",
new ActionError("error.password.required"));
}
}
return (errors);
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>