You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@apache.org on 2002/02/10 04:18:38 UTC
cvs commit: jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users BaseForm.java GroupForm.java ListGroupsAction.java ListRolesAction.java ListUsersAction.java RoleForm.java SaveGroupAction.java SaveRoleAction.java SaveUserAction.java SetUpGroupAction.java SetUpRoleAction.java SetUpUserAction.java UserForm.java UsersTreeBuilder.java
craigmcc 02/02/09 19:18:38
Added: webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users
BaseForm.java GroupForm.java ListGroupsAction.java
ListRolesAction.java ListUsersAction.java
RoleForm.java SaveGroupAction.java
SaveRoleAction.java SaveUserAction.java
SetUpGroupAction.java SetUpRoleAction.java
SetUpUserAction.java UserForm.java
UsersTreeBuilder.java
Log:
Synch up the functionality for user database administration. At the moment,
you can add or edit groups, roles, users. TODOs:
* Delete operations for groups, roles, users
* Associate roles with groups or users
* Associate groups with users
These functions will be added shortly.
Revision Changes Path
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/BaseForm.java
Index: BaseForm.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/BaseForm.java,v 1.1 2002/02/10 03:18:37 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:37 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.users;
import javax.management.ObjectName;
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;
/**
* Base class for form beans for the user administration
* options.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/02/10 03:18:37 $
* @since 4.1
*/
public class BaseForm extends ActionForm {
// ----------------------------------------------------- Instance Variables
// ------------------------------------------------------------- Properties
/**
* The MBean Name of UserDatabase containing this object.
*/
private String databaseName = null;
public String getDatabaseName() {
if ((this.databaseName == null) && (this.objectName != null)) {
try {
ObjectName oname = new ObjectName(this.objectName);
this.databaseName = oname.getDomain() + ":" +
"type=UserDatabase,database=" +
oname.getKeyProperty("database");
} catch (Throwable t) {
this.databaseName = null;
}
}
return (this.databaseName);
}
public void setDatabaseName(String databaseName) {
if ((databaseName != null) && (databaseName.length() < 1)) {
this.databaseName = null;
} else {
this.databaseName = databaseName;
}
}
/**
* The node label to be displayed in the user interface.
*/
private String nodeLabel = null;
public String getNodeLabel() {
return (this.nodeLabel);
}
public void setNodeLabel(String nodeLabel) {
this.nodeLabel = nodeLabel;
}
/**
* The MBean object name of this object. A null or zero-length
* value indicates that this is a new object.
*/
private String objectName = null;
public String getObjectName() {
return (this.objectName);
}
public void setObjectName(String objectName) {
if ((objectName != null) && (objectName.length() < 1)) {
this.objectName = null;
} else {
this.objectName = objectName;
}
}
// --------------------------------------------------------- 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) {
databaseName = null;
nodeLabel = null;
objectName = null;
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/GroupForm.java
Index: GroupForm.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/GroupForm.java,v 1.1 2002/02/10 03:18:37 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:37 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.users;
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 group page.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/02/10 03:18:37 $
* @since 4.1
*/
public final class GroupForm extends BaseForm {
// ----------------------------------------------------- Instance Variables
// ------------------------------------------------------------- Properties
/**
* The description of this group.
*/
private String description = null;
public String getDescription() {
return (this.description);
}
public void setDescription(String description) {
this.description = description;
}
/**
* The groupname of this group.
*/
private String groupname = null;
public String getGroupname() {
return (this.groupname);
}
public void setGroupname(String groupname) {
this.groupname = groupname;
}
// --------------------------------------------------------- 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) {
super.reset(mapping, request);
description = null;
groupname = 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) {
// groupname is a required field
if ((groupname == null) || (groupname.length() < 1)) {
errors.add("groupname",
new ActionError("users.error.groupname.required"));
}
// Quotes not allowed in groupname
if ((groupname != null) && (groupname.indexOf('"') >= 0)) {
errors.add("groupname",
new ActionError("users.error.quotes"));
}
// Quotes not allowed in description
if ((description != null) && (description.indexOf('"') > 0)) {
errors.add("description",
new ActionError("users.error.quotes"));
}
}
return (errors);
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/ListGroupsAction.java
Index: ListGroupsAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/ListGroupsAction.java,v 1.1 2002/02/10 03:18:37 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:37 $
*
* ====================================================================
*
* 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", "Tomcat", 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 apache@apache.org.
*
* 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.users;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.modelmbean.ModelMBean;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.webapp.admin.ApplicationServlet;
/**
* Retrieve the Set of MBean namess for all currently defined groups,
* and expose them as a request attribute named "groups".
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/02/10 03:18:37 $
* @since 4.1
*/
public class ListGroupsAction extends Action {
// --------------------------------------------------------- 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 {
// Acquire a reference to the MBeanServer containing our MBeans
MBeanServer mserver = null;
try {
mserver = ((ApplicationServlet) getServlet()).getServer();
} catch (Throwable t) {
throw new ServletException
("Cannot acquire MBeanServer reference", t);
}
// Acquire the set of group MBean names to be listed
// FIXME - limit to global user database?
String pattern = "Users:type=Group,*";
Set results = null;
try {
results = mserver.queryNames(new ObjectName(pattern), null);
} catch (Throwable t) {
throw new ServletException("queryNames(" + pattern + ")", t);
}
TreeSet groups = new TreeSet();
Iterator names = results.iterator();
while (names.hasNext()) {
ObjectName name = (ObjectName) names.next();
groups.add(name.toString());
}
// Forward the Set as a request attribute
request.setAttribute("groups", groups);
return (mapping.findForward("Groups List"));
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/ListRolesAction.java
Index: ListRolesAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/ListRolesAction.java,v 1.1 2002/02/10 03:18:37 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:37 $
*
* ====================================================================
*
* 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", "Tomcat", 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 apache@apache.org.
*
* 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.users;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.modelmbean.ModelMBean;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.webapp.admin.ApplicationServlet;
/**
* Retrieve the Set of MBean namess for all currently defined roles,
* and expose them as a request attribute named "roles". Requires a
* request parameter <code>databaseName</code> containing the MBean
* Name of our associated UserDatabase instance.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/02/10 03:18:37 $
* @since 4.1
*/
public class ListRolesAction extends Action {
// --------------------------------------------------------- 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 {
// Acquire a reference to the MBeanServer containing our MBeans
MBeanServer mserver = null;
try {
mserver = ((ApplicationServlet) getServlet()).getServer();
} catch (Throwable t) {
throw new ServletException
("Cannot acquire MBeanServer reference", t);
}
// Acquire the set of user MBean names to be listed
// FIXME - limit to global user database
// FIXME - pass databaseName reference on
// FIXME - set transaction control token
String pattern = "Users:type=Role,*";
Set results = null;
try {
results = mserver.queryNames(new ObjectName(pattern), null);
} catch (Throwable t) {
throw new ServletException("queryNames(" + pattern + ")", t);
}
TreeSet roles = new TreeSet();
Iterator names = results.iterator();
while (names.hasNext()) {
ObjectName name = (ObjectName) names.next();
roles.add(name.toString());
}
// Forward the Set as a request attribute
request.setAttribute("roles", roles);
return (mapping.findForward("Roles List"));
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/ListUsersAction.java
Index: ListUsersAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/ListUsersAction.java,v 1.1 2002/02/10 03:18:37 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:37 $
*
* ====================================================================
*
* 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", "Tomcat", 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 apache@apache.org.
*
* 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.users;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.modelmbean.ModelMBean;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.webapp.admin.ApplicationServlet;
/**
* Retrieve the Set of MBean namess for all currently defined users,
* and expose them as a request attribute named "users".
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/02/10 03:18:37 $
* @since 4.1
*/
public class ListUsersAction extends Action {
// --------------------------------------------------------- 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 {
// Acquire a reference to the MBeanServer containing our MBeans
MBeanServer mserver = null;
try {
mserver = ((ApplicationServlet) getServlet()).getServer();
} catch (Throwable t) {
throw new ServletException
("Cannot acquire MBeanServer reference", t);
}
// Acquire the set of user MBean names to be listed
// FIXME - limit to global user database?
String pattern = "Users:type=User,*";
Set results = null;
try {
results = mserver.queryNames(new ObjectName(pattern), null);
} catch (Throwable t) {
throw new ServletException("queryNames(" + pattern + ")", t);
}
TreeSet users = new TreeSet();
Iterator names = results.iterator();
while (names.hasNext()) {
ObjectName name = (ObjectName) names.next();
users.add(name.toString());
}
// Forward the Set as a request attribute
request.setAttribute("users", users);
return (mapping.findForward("Users List"));
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/RoleForm.java
Index: RoleForm.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/RoleForm.java,v 1.1 2002/02/10 03:18:37 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:37 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.users;
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 role page.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/02/10 03:18:37 $
* @since 4.1
*/
public final class RoleForm extends BaseForm {
// ----------------------------------------------------- Instance Variables
// ------------------------------------------------------------- Properties
/**
* The description of this role.
*/
private String description = null;
public String getDescription() {
return (this.description);
}
public void setDescription(String description) {
this.description = description;
}
/**
* The rolename of this role.
*/
private String rolename = null;
public String getRolename() {
return (this.rolename);
}
public void setRolename(String rolename) {
this.rolename = rolename;
}
// --------------------------------------------------------- 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) {
super.reset(mapping, request);
description = null;
rolename = 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) {
// rolename is a required field
if ((rolename == null) || (rolename.length() < 1)) {
errors.add("rolename",
new ActionError("users.error.rolename.required"));
}
// Quotes not allowed in rolename
if ((rolename != null) && (rolename.indexOf('"') >= 0)) {
errors.add("rolename",
new ActionError("users.error.quotes"));
}
// Quotes not allowed in description
if ((description != null) && (description.indexOf('"') > 0)) {
errors.add("description",
new ActionError("users.error.quotes"));
}
}
return (errors);
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/SaveGroupAction.java
Index: SaveGroupAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/SaveGroupAction.java,v 1.1 2002/02/10 03:18:37 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:37 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.users;
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;
import org.apache.webapp.admin.ApplicationServlet;
/**
* <p>Implementation of <strong>Action</strong> that saves a new or
* updated Group back to the underlying database.</p>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/02/10 03:18:37 $
* @since 4.1
*/
public final class SaveGroupAction 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);
// Has this transaction been cancelled?
if (isCancelled(request)) {
return (mapping.findForward("List Roles Setup"));
}
// Check the transaction token
if (!isTokenValid(request)) {
response.sendError
(HttpServletResponse.SC_BAD_REQUEST,
resources.getMessage(locale, "users.error.token"));
return (null);
}
// Perform any extra validation that is required
GroupForm groupForm = (GroupForm) form;
String databaseName = groupForm.getDatabaseName();
String objectName = groupForm.getObjectName();
// Perform an "Add Group" transaction
if (objectName == null) {
String signature[] = new String[2];
signature[0] = "java.lang.String";
signature[1] = "java.lang.String";
Object params[] = new Object[2];
params[0] = groupForm.getGroupname();
params[1] = groupForm.getDescription();
ObjectName oname = null;
try {
// Construct the MBean Name for our UserDatabase
oname = new ObjectName(databaseName);
// Create the new object and associated MBean
mserver.invoke(oname, "createGroup",
params, signature);
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale, "users.error.invoke",
"createGroup"), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage(locale, "users.error.invoke",
"createGroup"));
return (null);
}
}
// Perform an "Update Group" transaction
else {
ObjectName oname = null;
String attribute = null;
try {
// Construct an object name for this object
oname = new ObjectName(objectName);
// Update the specified role
attribute = "description";
mserver.setAttribute
(oname,
new Attribute(attribute, groupForm.getDescription()));
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale, "users.error.set.attribute",
attribute), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage(locale, "users.error.set.attribute",
attribute));
return (null);
}
}
// Save the updated database information
try {
ObjectName dname = new ObjectName(databaseName);
mserver.invoke(dname, "save",
new Object[0], new String[0]);
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale, "users.error.invoke",
"save"), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage(locale, "users.error.invoke",
"save"));
return (null);
}
// Proceed to the list roles screen
return (mapping.findForward("Groups List Setup"));
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/SaveRoleAction.java
Index: SaveRoleAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/SaveRoleAction.java,v 1.1 2002/02/10 03:18:37 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:37 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.users;
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;
import org.apache.webapp.admin.ApplicationServlet;
/**
* <p>Implementation of <strong>Action</strong> that saves a new or
* updated Role back to the underlying database.</p>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/02/10 03:18:37 $
* @since 4.1
*/
public final class SaveRoleAction 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);
// Has this transaction been cancelled?
if (isCancelled(request)) {
return (mapping.findForward("List Roles Setup"));
}
// Check the transaction token
if (!isTokenValid(request)) {
response.sendError
(HttpServletResponse.SC_BAD_REQUEST,
resources.getMessage(locale, "users.error.token"));
return (null);
}
// Perform any extra validation that is required
RoleForm roleForm = (RoleForm) form;
String databaseName = roleForm.getDatabaseName();
String objectName = roleForm.getObjectName();
// Perform an "Add Role" transaction
if (objectName == null) {
String signature[] = new String[2];
signature[0] = "java.lang.String";
signature[1] = "java.lang.String";
Object params[] = new Object[2];
params[0] = roleForm.getRolename();
params[1] = roleForm.getDescription();
ObjectName oname = null;
try {
// Construct the MBean Name for our UserDatabase
oname = new ObjectName(databaseName);
// Create the new object and associated MBean
mserver.invoke(oname, "createRole",
params, signature);
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale, "users.error.invoke",
"createRole"), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage(locale, "users.error.invoke",
"createRole"));
return (null);
}
}
// Perform an "Update Role" transaction
else {
ObjectName oname = null;
String attribute = null;
try {
// Construct an object name for this object
oname = new ObjectName(objectName);
// Update the specified role
attribute = "description";
mserver.setAttribute
(oname,
new Attribute(attribute, roleForm.getDescription()));
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale, "users.error.set.attribute",
attribute), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage(locale, "users.error.set.attribute",
attribute));
return (null);
}
}
// Save the updated database information
try {
ObjectName dname = new ObjectName(databaseName);
mserver.invoke(dname, "save",
new Object[0], new String[0]);
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale, "users.error.invoke",
"save"), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage(locale, "users.error.invoke",
"save"));
return (null);
}
// Proceed to the list roles screen
return (mapping.findForward("Roles List Setup"));
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/SaveUserAction.java
Index: SaveUserAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/SaveUserAction.java,v 1.1 2002/02/10 03:18:37 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:37 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.users;
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;
import org.apache.webapp.admin.ApplicationServlet;
/**
* <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/02/10 03:18:37 $
* @since 4.1
*/
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)) {
return (mapping.findForward("List Users Setup"));
}
// Check the transaction token
if (!isTokenValid(request)) {
response.sendError
(HttpServletResponse.SC_BAD_REQUEST,
resources.getMessage(locale, "users.error.token"));
return (null);
}
// Perform any extra validation that is required
UserForm userForm = (UserForm) form;
String databaseName = userForm.getDatabaseName();
String objectName = userForm.getObjectName();
// Perform an "Add User" transaction
if (objectName == null) {
String signature[] = new String[3];
signature[0] = "java.lang.String";
signature[1] = "java.lang.String";
signature[2] = "java.lang.String";
Object params[] = new Object[3];
params[0] = userForm.getUsername();
params[1] = userForm.getPassword();
params[2] = userForm.getFullName();
ObjectName oname = null;
try {
// Construct the MBean Name for our UserDatabase
oname = new ObjectName(databaseName);
// Create the new object and associated MBean
mserver.invoke(oname, "createUser",
params, signature);
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale, "users.error.invoke",
"createUser"), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage(locale, "users.error.invoke",
"createUser"));
return (null);
}
}
// Perform an "Update User" transaction
else {
ObjectName oname = null;
String attribute = null;
try {
// Construct an object name for this object
oname = new ObjectName(objectName);
// Update the specified user
attribute = "fullName";
mserver.setAttribute
(oname,
new Attribute(attribute, userForm.getFullName()));
attribute = "password";
mserver.setAttribute
(oname,
new Attribute(attribute, userForm.getPassword()));
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale, "users.error.set.attribute",
attribute), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage(locale, "users.error.set.attribute",
attribute));
return (null);
}
}
// Save the updated database information
try {
ObjectName dname = new ObjectName(databaseName);
mserver.invoke(dname, "save",
new Object[0], new String[0]);
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale, "users.error.invoke",
"save"), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage(locale, "users.error.invoke",
"save"));
return (null);
}
// Proceed to the list roles screen
return (mapping.findForward("Users List Setup"));
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/SetUpGroupAction.java
Index: SetUpGroupAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/SetUpGroupAction.java,v 1.1 2002/02/10 03:18:37 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:37 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.users;
import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;
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 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 org.apache.struts.util.MessageResources;
import org.apache.webapp.admin.ApplicationServlet;
/**
* <p>Implementation of <strong>Action</strong> that sets up and stashes
* a <code>GroupForm</code> bean in request scope. The form bean will have
* a null <code>objectName</code> property if this form represents a group
* being added, or a non-null value for an existing group.</p>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/02/10 03:18:37 $
* @since 4.1
*/
public final class SetUpGroupAction 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");
GroupForm groupForm = new GroupForm();
if (objectName == null) {
groupForm.setNodeLabel
(resources.getMessage(locale, "users.group.newGroup"));
groupForm.setObjectName(null);
} else {
groupForm.setNodeLabel
(resources.getMessage(locale, "users.group.oldGroup"));
groupForm.setObjectName(objectName);
String attribute = null;
try {
ObjectName oname = new ObjectName(objectName);
attribute = "groupname";
groupForm.setGroupname
((String) mserver.getAttribute(oname, attribute));
attribute = "description";
groupForm.setDescription
((String) mserver.getAttribute(oname, attribute));
// FIXME - roles list
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale,
"users.error.attribute.get", attribute), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage
(locale, "users.error.attribute.get", attribute));
return (null);
}
}
groupForm.setDatabaseName(request.getParameter("databaseName"));
// Stash the form bean and forward to the display page
saveToken(request);
session.setAttribute("groupForm", groupForm);
return (mapping.findForward("Group"));
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/SetUpRoleAction.java
Index: SetUpRoleAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/SetUpRoleAction.java,v 1.1 2002/02/10 03:18:38 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:38 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.users;
import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;
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 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 org.apache.struts.util.MessageResources;
import org.apache.webapp.admin.ApplicationServlet;
/**
* <p>Implementation of <strong>Action</strong> that sets up and stashes
* a <code>RoleForm</code> bean in request scope. The form bean will have
* a null <code>objectName</code> property if this form represents a role
* being added, or a non-null value for an existing role.</p>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/02/10 03:18:38 $
* @since 4.1
*/
public final class SetUpRoleAction 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");
RoleForm roleForm = new RoleForm();
if (objectName == null) {
roleForm.setNodeLabel
(resources.getMessage(locale, "users.role.newRole"));
roleForm.setObjectName(null);
} else {
roleForm.setNodeLabel
(resources.getMessage(locale, "users.role.oldRole"));
roleForm.setObjectName(objectName);
String attribute = null;
try {
ObjectName oname = new ObjectName(objectName);
attribute = "rolename";
roleForm.setRolename
((String) mserver.getAttribute(oname, attribute));
attribute = "description";
roleForm.setDescription
((String) mserver.getAttribute(oname, attribute));
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale,
"users.error.attribute.get", attribute), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage
(locale, "users.error.attribute.get", attribute));
return (null);
}
}
roleForm.setDatabaseName(request.getParameter("databaseName"));
// Stash the form bean and forward to the display page
saveToken(request);
session.setAttribute("roleForm", roleForm);
return (mapping.findForward("Role"));
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/SetUpUserAction.java
Index: SetUpUserAction.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/SetUpUserAction.java,v 1.1 2002/02/10 03:18:38 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:38 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.users;
import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;
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 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 org.apache.struts.util.MessageResources;
import org.apache.webapp.admin.ApplicationServlet;
/**
* <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>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/02/10 03:18:38 $
* @since 4.1
*/
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, "users.user.newUser"));
userForm.setObjectName(null);
} else {
userForm.setNodeLabel
(resources.getMessage(locale, "users.user.oldUser"));
userForm.setObjectName(objectName);
String attribute = null;
try {
ObjectName oname = new ObjectName(objectName);
attribute = "username";
userForm.setUsername
((String) mserver.getAttribute(oname, attribute));
attribute = "password";
userForm.setPassword
((String) mserver.getAttribute(oname, attribute));
attribute = "fullName";
userForm.setFullName
((String) mserver.getAttribute(oname, attribute));
// FIXME - groups list
// FIXME - roles list
} catch (Throwable t) {
getServlet().log
(resources.getMessage(locale,
"users.error.attribute.get", attribute), t);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
resources.getMessage
(locale, "users.error.attribute.get", attribute));
return (null);
}
}
userForm.setDatabaseName(request.getParameter("databaseName"));
// Stash the form bean and forward to the display page
saveToken(request);
session.setAttribute("userForm", userForm);
return (mapping.findForward("User"));
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/UserForm.java
Index: UserForm.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/UserForm.java,v 1.1 2002/02/10 03:18:38 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:38 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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.users;
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/02/10 03:18:38 $
* @since 4.1
*/
public final class UserForm extends BaseForm {
// ----------------------------------------------------- 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 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) {
super.reset(mapping, request);
fullName = null;
groups = 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) || (username.length() < 1)) {
errors.add("username",
new ActionError("users.error.username.required"));
}
// uassword is a required field
if ((password == null) || (username.length() < 1)) {
errors.add("password",
new ActionError("users.error.password.required"));
}
// Quotes not allowed in username
if ((username != null) && (username.indexOf('"') >= 0)) {
errors.add("username",
new ActionError("users.error.quotes"));
}
// Quotes not allowed in password
if ((password != null) && (password.indexOf('"') > 0)) {
errors.add("description",
new ActionError("users.error.quotes"));
}
// Quotes not allowed in fullName
if ((fullName != null) && (fullName.indexOf('"') > 0)) {
errors.add("fullName",
new ActionError("users.error.quotes"));
}
}
return (errors);
}
}
1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/UsersTreeBuilder.java
Index: UsersTreeBuilder.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/users/UsersTreeBuilder.java,v 1.1 2002/02/10 03:18:38 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/02/10 03:18:38 $
*
* ====================================================================
*
* 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", "Tomcat", 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 apache@apache.org.
*
* 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.users;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.Action;
import org.apache.struts.util.MessageResources;
import org.apache.webapp.admin.ApplicationServlet;
import org.apache.webapp.admin.TreeBuilder;
import org.apache.webapp.admin.TreeControl;
import org.apache.webapp.admin.TreeControlNode;
/**
* Implementation of <code>TreeBuilder</code> that adds the nodes required
* for administering the user database.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2002/02/10 03:18:38 $
* @since 4.1
*/
public class UsersTreeBuilder implements TreeBuilder {
// ----------------------------------------------------- Instance Variables
// ---------------------------------------------------- TreeBuilder Methods
/**
* Add the required nodes to the specified <code>treeControl</code>
* instance.
*
* @param treeControl The <code>TreeControl</code> to which we should
* add our nodes
* @param servlet The controller servlet for the admin application
* @param request The servlet request we are processing
*/
public void buildTree(TreeControl treeControl,
ApplicationServlet servlet,
HttpServletRequest request) {
MessageResources resources = (MessageResources)
servlet.getServletContext().getAttribute(Action.MESSAGES_KEY);
addSubtree(treeControl.getRoot(), resources);
}
// ------------------------------------------------------ Protected Methods
/**
* Add the subtree of nodes required for user administration.
*
* @param root The root node of our tree control
* @param resources The MessageResources for our localized messages
* messages
*/
protected void addSubtree(TreeControlNode root,
MessageResources resources) {
String databaseName = URLEncoder.encode
("Users:type=UserDatabase,database=UserDatabase");
TreeControlNode subtree = new TreeControlNode
("Global User and Group Administration",
"folder_16_pad.gif",
resources.getMessage("users.treeBuilder.subtreeNode"),
null,
"content",
true);
TreeControlNode groups = new TreeControlNode
("Global Administer Groups",
"folder_16_pad.gif",
resources.getMessage("users.treeBuilder.groupsNode"),
"users/listGroups.do?databaseName=" + databaseName,
"content",
false);
TreeControlNode roles = new TreeControlNode
("Global Administer Roles",
"folder_16_pad.gif",
resources.getMessage("users.treeBuilder.rolesNode"),
"users/listRoles.do?databaseName=" + databaseName,
"content",
false);
TreeControlNode users = new TreeControlNode
("Global Administer Users",
"folder_16_pad.gif",
resources.getMessage("users.treeBuilder.usersNode"),
"users/listUsers.do?databaseName=" + databaseName,
"content",
false);
root.addChild(subtree);
subtree.addChild(groups);
subtree.addChild(roles);
subtree.addChild(users);
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>