You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2002/02/07 06:06:53 UTC

cvs commit: jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm SetUpUserDBRealmAction.java UserDBRealmAction.java UserDBRealmForm.java

manveen     02/02/06 21:06:53

  Modified:    webapps/admin/WEB-INF struts-config.xml
               webapps/admin/WEB-INF/classes/org/apache/webapp/admin
                        ApplicationResources_en.properties
                        ApplicationResources_es.properties
                        TomcatTreeBuilder.java
  Added:       webapps/admin userDBRealm.jsp
               webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm
                        SetUpUserDBRealmAction.java UserDBRealmAction.java
                        UserDBRealmForm.java
  Log:
  Realms visible from the tree, (added to TomcatTreeBuilder).
  Added UserDatabase Realm screen and functionality.
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-4.0/webapps/admin/userDBRealm.jsp
  
  Index: userDBRealm.jsp
  ===================================================================
  <!-- Standard Struts Entries -->
  <%@ page language="java" %>
  <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
  <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
  <%@ taglib uri="/WEB-INF/controls.tld" prefix="controls" %>
  
  <html:html locale="true">
  
  <%@ include file="header.jsp" %>
  
  <!-- Body -->
  <body bgcolor="white">
  
  <!--Form -->
  
  <html:errors/>
  
  <html:form method="POST" action="/UserDBRealm">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr bgcolor="7171A5">
        <td width="81%"> 
          <html:hidden property="realmName"/>
          <html:hidden property="realmType"/>
          <div class="page-title-text" align="left"> 
            <bean:write name="userdbRealmForm" property="nodeLabel" scope="session"/>
          </div>
        </td>
        <td width="19%"> 
          <div align="right">
        <controls:actions>
              <controls:action selected="true"> ----<bean:message key="actions.available.actions"/>---- </controls:action>
              <controls:action> --------------------------------- </controls:action>
              <!-- will add the urls later once those screens get implemented -->
              <controls:action url="">  <bean:message key="actions.thisrealm.delete"/> </controls:action>
         </controls:actions>   
           </div>
        </td>
      </tr>
    </table>
      <%@ include file="buttons.jsp" %>
    <br>
  
    <table class="back-table" border="0" cellspacing="0" cellpadding="0" width="100%">
      <tr> 
        <td> 
         <controls:table tableStyle="front-table" lineStyle="line-row">
              <controls:row header="true" 
                  labelStyle="table-header-text" dataStyle="table-header-text">
              <controls:label><bean:message key="service.property"/></controls:label>
              <controls:data><bean:message key="service.value"/></controls:data>
          </controls:row>
  
        <controls:row labelStyle="table-label-text" dataStyle="table-normal-text">
              <controls:label><bean:message key="connector.type"/>:</controls:label>
              <controls:data>
                <bean:write name="userdbRealmForm" property="realmType" scope="session"/>
              </controls:data>
          </controls:row>
  
          <controls:row labelStyle="table-label-text" dataStyle="table-normal-text">
              <controls:label><bean:message key="server.debuglevel"/>:</controls:label>
              <controls:data>
                 <html:select property="debugLvl">
                       <bean:define id="debugLvlVals" name="userdbRealmForm" property="debugLvlVals"/>
                       <html:options collection="debugLvlVals" property="value"
                          labelProperty="label"/>
                  </html:select>
              </controls:data>
          </controls:row>
  
          <controls:row labelStyle="table-label-text" dataStyle="table-normal-text">
              <controls:label><bean:message key="realm.resource"/>:</controls:label>
              <controls:data>
                  <html:text property="resource" size="25" maxlength="25"/>
              </controls:data>
          </controls:row>
      
        </controls:table>
        </td>
      </tr>
    </table>
      
      <%@ include file="buttons.jsp" %>
    <br>
    </html:form>
  <p>&nbsp;</p>
  </body>
  </html:html>
  
  
  
  1.23      +40 -0     jakarta-tomcat-4.0/webapps/admin/WEB-INF/struts-config.xml
  
  Index: struts-config.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/struts-config.xml,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- struts-config.xml	4 Feb 2002 17:59:19 -0000	1.22
  +++ struts-config.xml	7 Feb 2002 05:06:52 -0000	1.23
  @@ -63,6 +63,14 @@
       <form-bean      name="userForm"
                       type="org.apache.webapp.admin.UserForm"/>
   
  +    <!-- JDBC Realm form bean -->
  +    <form-bean      name="realmForm"
  +                    type="org.apache.webapp.admin.realm.JDBCRealmForm"/>
  +
  +   <!-- UserDB Realm form bean -->
  +    <form-bean      name="userdbRealmForm"
  +                    type="org.apache.webapp.admin.realm.UserDBRealmForm"/>
  +
     </form-beans>
   
   
  @@ -142,6 +150,14 @@
                       path="/user.jsp"
                   redirect="false"/>
   
  +    <forward        name="JDBCRealm"
  +                    path="/jdbcRealm.jsp"
  +                redirect="false"/>
  +
  +    <forward        name="UserDBRealm"
  +                    path="/userDBRealm.jsp"
  +                redirect="false"/>
  +
     </global-forwards>
   
   
  @@ -239,6 +255,16 @@
                         path="/logger.jsp"
                     redirect="true"/>
       </action>
  +        
  +    <!-- Set up Realm datastructure -->
  +    <action    path="/setUpUserDBRealm"
  +               type="org.apache.webapp.admin.realm.SetUpUserDBRealmAction"
  +               name="userdbRealmForm"
  +               scope="session">
  +      <forward        name="SetUpDBRealm"
  +                      path="/userdbRealm.jsp"
  +                  redirect="true"/>
  +    </action>
       
       <!-- Log out of the application -->
       <action    path="/logOut"
  @@ -341,7 +367,21 @@
                  name="addServiceForm"
                 scope="request"
                  type="org.apache.webapp.admin.service.AddServiceAction"/>
  +
  +    <!-- JDBC realm action -->
  +    <action    path="/JDBCRealm"
  +              input="/jdbcRealm.jsp"
  +               name="realmForm"
  +              scope="request"
  +               type="org.apache.webapp.admin.realm.JDBCRealmAction"/>
                  
  +    <!-- UserDB realm action -->
  +    <action    path="/UserDBRealm"
  +              input="/userDBRealm.jsp"
  +               name="userdbRealmForm"
  +              scope="request"
  +               type="org.apache.webapp.admin.realm.UserDBRealmAction"/>
  +
     </action-mappings>  
       
   </struts-config>
  
  
  
  1.21      +2 -2      jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_en.properties
  
  Index: ApplicationResources_en.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_en.properties,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ApplicationResources_en.properties	7 Feb 2002 02:22:58 -0000	1.20
  +++ ApplicationResources_en.properties	7 Feb 2002 05:06:53 -0000	1.21
  @@ -166,7 +166,7 @@
   error.set.attributes=<li>Error setting information properties.<li>
   actions.delete=Delete
   error.defaultHost.required=<li>Default Hostname required</li>
  -error.serviceName.required=<li>Service el nombre required</li>
  +error.serviceName.required=<li>Service Name required</li>
   actions.thisrealm.delete=Delete this User Realm
   realm.driver=Database Driver
   realm.passwd=Database Password
  @@ -178,4 +178,4 @@
   realm.userRoleTable=User Role Table
   realm.userTable=User Table
   realm.resource=Resource Name
  -error.resource.required=<li>Resource Name is required</li>
  +error.resource.required=<li>Resource Name is required.</li>
  
  
  
  1.22      +1 -1      jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_es.properties
  
  Index: ApplicationResources_es.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/ApplicationResources_es.properties,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ApplicationResources_es.properties	7 Feb 2002 02:22:58 -0000	1.21
  +++ ApplicationResources_es.properties	7 Feb 2002 05:06:53 -0000	1.22
  @@ -178,4 +178,4 @@
   realm.userRoleTable=Vector Del Papel Del Utilizador
   realm.userTable=Vector De Utilizador
   realm.resource=Nombre Del Recurso
  -error.resource.required=<li>Se requiere el nombre del recurso</li>
  +error.resource.required=<li>Se requiere el nombre del recurso.</li>
  
  
  
  1.13      +123 -23   jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java
  
  Index: TomcatTreeBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TomcatTreeBuilder.java	29 Jan 2002 01:15:55 -0000	1.12
  +++ TomcatTreeBuilder.java	7 Feb 2002 05:06:53 -0000	1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java,v 1.12 2002/01/29 01:15:55 manveen Exp $
  - * $Revision: 1.12 $
  - * $Date: 2002/01/29 01:15:55 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java,v 1.13 2002/02/07 05:06:53 manveen Exp $
  + * $Revision: 1.13 $
  + * $Date: 2002/02/07 05:06:53 $
    *
    * ====================================================================
    *
  @@ -85,13 +85,15 @@
   import javax.management.MBeanAttributeInfo;
   import javax.management.MBeanInfo;
   
  +import org.apache.webapp.admin.realm.SetUpUserDBRealmAction;
  +
   /**
    * <p> Implementation of TreeBuilder interface for Tomcat Tree Controller
    *     to build plugin components into the tree
    *
    * @author Jazmin Jonson
    * @author Manveen Kaur
  - * @version $Revision: 1.12 $ $Date: 2002/01/29 01:15:55 $
  + * @version $Revision: 1.13 $ $Date: 2002/02/07 05:06:53 $
    */
   
   
  @@ -101,6 +103,7 @@
       private final static String SERVER_LABEL = "Tomcat Server";
       
       public final static String SERVER_TYPE = "Catalina:type=Server";
  +    public final static String FACTORY_TYPE = "Catalina:type=MBeanFactory";
       public final static String SERVICE_TYPE = "Catalina:type=Service";
       public final static String ENGINE_TYPE = "Catalina:type=Engine";
       public final static String CONNECTOR_TYPE = "Catalina:type=Connector";
  @@ -109,10 +112,12 @@
       public final static String LOADER_TYPE = "Catalina:type=Loader";
       public final static String MANAGER_TYPE = "Catalina:type=Manager";
       public final static String LOGGER_TYPE = "Catalina:type=Logger";
  -
  +    public final static String REALM_TYPE = "Catalina:type=Realm";
  +    
       public final static String WILDCARD = ",*";
       
       private static MBeanServer mBServer = null;
  +    //private static ObjectInstance mBeanFactory = null;
       
       public void buildTree(TreeControl treeControl,
       ApplicationServlet servlet,
  @@ -129,6 +134,17 @@
           }
       }
       
  +    public static ObjectInstance getMBeanFactory()
  +    throws JMException, ServletException {
  +        
  +        Iterator factoryItr =
  +        mBServer.queryMBeans(new ObjectName(FACTORY_TYPE + WILDCARD), null).iterator();
  +        ObjectInstance mBeanFactory = (ObjectInstance)factoryItr.next();
  +        
  +        System.out.println(" mbean factory= " + (mBeanFactory.getObjectName()).toString());
  +        return mBeanFactory;
  +    }
  +    
       public TreeControlNode getServer()
       throws JMException, ServletException {
           
  @@ -197,6 +213,7 @@
               getConnectors(serviceNode, serviceName);
               getHosts(serviceNode, serviceName);
               getLoggers(serviceNode, serviceName, null, null, 0);
  +            getRealms(serviceNode, serviceName, null, null, 0);
           }
       }
       
  @@ -225,20 +242,20 @@
               String encodedNodeLabel =  URLEncoder.encode(nodeLabel);
               
               connectorNode =
  -                new TreeControlNode(connectorObj.getObjectName().toString(),
  -                "folder_16_pad.gif",
  -                nodeLabel,
  -                "setUpConnector.do?select=" + encodedConnectorName
  -                + "&nodeLabel="+ encodedNodeLabel,
  -                "content", true);
  -                
  +            new TreeControlNode(connectorObj.getObjectName().toString(),
  +            "folder_16_pad.gif",
  +            nodeLabel,
  +            "setUpConnector.do?select=" + encodedConnectorName
  +            + "&nodeLabel="+ encodedNodeLabel,
  +            "content", true);
  +            
               serviceNode.addChild(connectorNode);
  -        }        
  +        }
       }
       
       public void getHosts(TreeControlNode serviceNode, String serviceName)
       throws JMException{
  - 
  +        
           Iterator HostItr =
           (mBServer.queryMBeans(new ObjectName(HOST_TYPE + WILDCARD +
           ",service=" + serviceName), null)).iterator();
  @@ -271,13 +288,13 @@
               
               getContexts(hostNode, hostName, serviceName);
               getLoggers(hostNode, serviceName, hostName, null, 1);
  +            getRealms(hostNode, serviceName, hostName, null, 1);
           }
  -        
       }
       
       public void getContexts(TreeControlNode hostNode, String hostName, String serviceName)
       throws JMException{
  -    
  +        
           Iterator contextItr =
           (mBServer.queryMBeans(new ObjectName(CONTEXT_TYPE + WILDCARD +
           ",host=" + hostName + ",service=" + serviceName), null)).iterator();
  @@ -307,12 +324,14 @@
               
               hostNode.addChild(contextNode);
               //get all loggers for this context
  -            if (contextName.length() > 0)
  -                getLoggers(contextNode, serviceName, hostName, contextName, 2);            
  -        }        
  +            if (contextName.length() > 0) {
  +                getLoggers(contextNode, serviceName, hostName, contextName, 2);
  +                getRealms(contextNode, serviceName, hostName, contextName, 2);
  +            }
  +        }
       }
       
  -        
  +    
       /**
        * Add the required logger nodes to the specified node instance.
        *
  @@ -351,11 +370,11 @@
           while(loggerItr.hasNext()){
               
               ObjectInstance loggerObj = (ObjectInstance)loggerItr.next();
  -            ObjectName loggerObjName = loggerObj.getObjectName();            
  +            ObjectName loggerObjName = loggerObj.getObjectName();
               encodedLoggerName =  URLEncoder.encode(loggerObj.getObjectName().toString());
               
               String className =
  -            (String)mBServer.getAttribute(loggerObj.getObjectName(), 
  +            (String)mBServer.getAttribute(loggerObj.getObjectName(),
               SetUpLoggerAction.CLASSNAME_PROP_NAME);
               
               String loggerType = null;
  @@ -379,5 +398,86 @@
               
               node.addChild(loggerNode);
           }
  -    }    
  +    }
  +    
  +    /**
  +     * Add the required realm nodes to the specified node instance.
  +     *
  +     * @param node The <code>TreeControlNode</code> to which we should
  +     * add our realm nodes.
  +     * @param serviceName The service to which this realm belongs.
  +     * @param hostName The host to which this realm belongs.
  +     * @param contextName The context to which this realm belongs.
  +     * @param type (0,1,2)  Get all realms for a particular service(0),
  +     * host(1), context (2).
  +     */
  +    public void getRealms(TreeControlNode node, String serviceName,
  +    String hostName, String contextName, int type)
  +    throws JMException{
  +        
  +        Iterator realmItr = null;
  +        
  +        if (type == 0) {
  +            realmItr =
  +            (mBServer.queryMBeans(new ObjectName(REALM_TYPE +
  +            ",service=" + serviceName), null)).iterator();
  +        }  else if (type == 1) {
  +            realmItr =
  +            (mBServer.queryMBeans(new ObjectName(REALM_TYPE +
  +            ",host=" + hostName + ",service=" + serviceName), null)).iterator();
  +        } else if (type == 2) {
  +            realmItr =
  +            (mBServer.queryMBeans(new ObjectName(REALM_TYPE +
  +            ",path=" + contextName + ",host=" + hostName +
  +            ",service=" + serviceName), null)).iterator();
  +        }
  +        
  +        TreeControlNode realmNode = null;
  +        String encodedRealmName;
  +        
  +        while(realmItr.hasNext()){
  +            
  +            ObjectInstance realmObj = (ObjectInstance)realmItr.next();
  +            ObjectName realmObjName = realmObj.getObjectName();
  +            encodedRealmName =  URLEncoder.encode(realmObj.getObjectName().toString());
  +            
  +            String className =
  +            (String)mBServer.getAttribute(realmObj.getObjectName(),
  +            SetUpLoggerAction.CLASSNAME_PROP_NAME);
  +            
  +            String realmType = null;
  +            int period = className.lastIndexOf(".");
  +            if (period >= 0)
  +                realmType = className.substring(period + 1);
  +            
  +            String setUpAction = null;
  +            if ((SetUpUserDBRealmAction.JDBC_REALM).equalsIgnoreCase(realmType)) {
  +                setUpAction = "setUpJDBCRealm";
  +            } else if ((SetUpUserDBRealmAction.JNDI_REALM).equalsIgnoreCase(realmType)) {
  +                setUpAction = "setUpJNDIRealm";
  +            } else if ((SetUpUserDBRealmAction.MEMORY_REALM).equalsIgnoreCase(realmType)) {
  +                setUpAction = "setUpMemoryRealm";
  +            } else {
  +                // UserDatabaseRealm
  +                setUpAction = "setUpUserDBRealm";
  +            }
  +            
  +            String encodedRealmType =  URLEncoder.encode(realmType);
  +            
  +            String nodeLabel= "Realm";
  +            String encodedNodeLabel =  URLEncoder.encode(nodeLabel);
  +            
  +            realmNode =
  +            new TreeControlNode(realmObj.getObjectName().toString(),
  +            "folder_16_pad.gif",
  +            nodeLabel,
  +            setUpAction +".do?select=" + encodedRealmName            
  +            +"&nodeLabel="+ encodedNodeLabel
  +            +"&type="+ encodedRealmType,
  +            "content", true);
  +            
  +            node.addChild(realmNode);
  +        }
  +    }
  +    
   }
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/SetUpUserDBRealmAction.java
  
  Index: SetUpUserDBRealmAction.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/SetUpUserDBRealmAction.java,v 1.1 2002/02/07 05:06:53 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/07 05:06:53 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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.realm;
  
  import java.io.IOException;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Locale;
  import java.util.ArrayList;
  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.MBeanServer;
  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.webapp.admin.ApplicationServlet;
  import org.apache.webapp.admin.LabelValueBean;
  
  import org.apache.struts.util.MessageResources;
  
  /**
   * Test <code>Action</code> that handles events from the tree control when
   * a UserDatabase realm is chosen.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/07 05:06:53 $
   */
  
  public class SetUpUserDBRealmAction extends Action {
      
      private static MBeanServer mBServer = null;
      
  //    public final static String CLASSNAME_PROP_NAME = "className";
      public final static String DEBUG_PROP_NAME = "debug";
      public final static String RESOURCE_PROP_NAME = "resourceName";
      
      // the different types of realms
      public final static String JDBC_REALM = "JDBCRealm";
      public final static String JNDI_REALM = "JNDIRealm";
      public final static String MEMORY_REALM = "MemoryRealm";
      public final static String USERDB_REALM = "UserDatabaseRealm";
      
      private ArrayList debugLvlList = 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 {
          
          HttpSession session = request.getSession();
       
          if (form == null) {
              getServlet().log(" Creating new RealmForm bean under key "
              + mapping.getAttribute());
              
              form = new UserDBRealmForm();
          }
          
          if ("request".equals(mapping.getScope()))
              request.setAttribute(mapping.getAttribute(), form);
          else
              session.setAttribute(mapping.getAttribute(), form);
          
          String selectedName = request.getParameter("select");
          String realmType = request.getParameter("type");
          String nodeLabel = request.getParameter("nodeLabel");
          
          UserDBRealmForm realmFm = (UserDBRealmForm) form;
          
          if(debugLvlList == null) {
              debugLvlList = new ArrayList();
              debugLvlList.add(new LabelValueBean("0", "0"));
              debugLvlList.add(new LabelValueBean("1", "1"));
              debugLvlList.add(new LabelValueBean("2", "2"));
              debugLvlList.add(new LabelValueBean("3", "3"));
              debugLvlList.add(new LabelValueBean("4", "4"));
              debugLvlList.add(new LabelValueBean("5", "5"));
              debugLvlList.add(new LabelValueBean("6", "6"));
              debugLvlList.add(new LabelValueBean("7", "7"));
              debugLvlList.add(new LabelValueBean("8", "8"));
              debugLvlList.add(new LabelValueBean("9", "9"));
          }
          
          try{
              
              if(mBServer == null) {
                  ApplicationServlet servlet = (ApplicationServlet)getServlet();
                  mBServer = servlet.getServer();
              }
              
              Iterator realmItr =
              mBServer.queryMBeans(new
              ObjectName(selectedName), null).iterator();
              
              ObjectInstance objInstance = (ObjectInstance)realmItr.next();
              ObjectName realmObjName = (objInstance).getObjectName();
              
              realmFm.setRealmName(selectedName);
              realmFm.setRealmType(realmType);
              realmFm.setNodeLabel(nodeLabel);
              
              realmFm.setDebugLvlVals(debugLvlList);
              realmFm.setDebugLvl(
              ((Integer) mBServer.getAttribute(realmObjName, DEBUG_PROP_NAME)).toString());
              
              realmFm.setResource(
              (String) mBServer.getAttribute(realmObjName, RESOURCE_PROP_NAME));
              
          } catch(Throwable t){
              t.printStackTrace(System.out);
              //forward to error page
          }
          
          // Stash the form bean and forward to the display page
          request.setAttribute("userdbRealmForm", realmFm);
          // Forward back to the appropriate Realm page
          return (mapping.findForward("UserDBRealm"));
          
      }
  }
  
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/UserDBRealmAction.java
  
  Index: UserDBRealmAction.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/UserDBRealmAction.java,v 1.1 2002/02/07 05:06:53 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/07 05:06:53 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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.realm;
  
  import java.util.Iterator;
  import java.util.Locale;
  import java.io.IOException;
  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.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.QueryExp;
  import javax.management.Query;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  import javax.management.JMException;
  import org.apache.struts.util.MessageResources;
  
  import org.apache.webapp.admin.ApplicationServlet;
  import org.apache.webapp.admin.LabelValueBean;
  
  /**
   * Implementation of <strong>Action</strong> that validates
   * actions on a user database Realm.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/07 05:06:53 $
   */
  
  public final class UserDBRealmAction extends Action {
      
      private static MBeanServer mBServer = 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 {
          
          try{
              
              // front end validation and checking.
              // ===================================================
              MessageResources messages = getResources();
              Locale locale = (Locale)request.getSession().getAttribute(Action.LOCALE_KEY);
              
              // Validate the request parameters specified by the user
              ActionErrors errors = new ActionErrors();
              
              // Report any errors we have discovered back to the original form
              if (!errors.empty()) {
                  saveErrors(request, errors);
                  return (new ActionForward(mapping.getInput()));
              }
              
              if(mBServer == null) {
                  ApplicationServlet servlet = (ApplicationServlet)getServlet();
                  mBServer = servlet.getServer();
              }
              
              /**
               * Get the realm Name from the form.
               * This is used to lookup the MBeanServer and
               * retrieve this realm's MBean.
               */
              String realmName = request.getParameter("realmName");
              
              Iterator realmItr =
              mBServer.queryMBeans(new
              ObjectName(realmName), null).iterator();
              
              ObjectInstance objInstance = (ObjectInstance)realmItr.next();
              ObjectName realmObjName = (objInstance).getObjectName();
              
              /**
               * Extracting the values from the form and
               * updating the MBean with the new values.
               */            
              String debugLvlText = request.getParameter("debugLvl");
              if(debugLvlText != null) {
                  Integer debugLvl = new Integer(debugLvlText);
                  mBServer.setAttribute(realmObjName,
                  new Attribute(SetUpUserDBRealmAction.DEBUG_PROP_NAME,
                  debugLvl));
              }
              
              String resource = request.getParameter("resource");
              if(resource != null) {
                  mBServer.setAttribute(realmObjName,
                  new Attribute(SetUpUserDBRealmAction.RESOURCE_PROP_NAME,
                  resource));
              }
              
          }catch(Throwable t){
              t.printStackTrace(System.out);
              //forward to error page
          }
          if (servlet.getDebug() >= 1)
              servlet.log(" Forwarding to success page");
          // Forward back to the test page
          return (mapping.findForward("Save Successful"));
          
      }
      
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/UserDBRealmForm.java
  
  Index: UserDBRealmForm.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/UserDBRealmForm.java,v 1.1 2002/02/07 05:06:53 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/07 05:06:53 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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.realm;
  
  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;
  import java.net.InetAddress;
  import java.util.ArrayList;
  
  import org.apache.webapp.admin.ApplicationServlet;
  import org.apache.webapp.admin.LabelValueBean;
  
  /**
   * Form bean for the User Database realm page.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/07 05:06:53 $
   */
  
  public final class UserDBRealmForm extends ActionForm {
      
      // ----------------------------------------------------- Instance Variables
      
      /**
       * The text for the debug level.
       */
      private String debugLvl = "0";
      
      /**
       * The text for the realm name, used to retrieve
       * the corresponding realm mBean.
       */
      private String realmName = null;
      
      /**
       * The text for the realm type.
       * Specifies if it is a JNDI, JDBC, Userdatabase or Memory Realm.
       */
      private String realmType = null;
      
      /**
       * Set of valid values for debug level.
       */
      private ArrayList debugLvlVals = null;
      
      /**
       * The text for the resource name.
       */
      private String resource = null;
      
      /**
       * The text for the node label.
       */
      private String nodeLabel = null;
      
      // ------------------------------------------------------------- Properties
      
      /**
       * Return the Realm Name.
       */
      public String getRealmName() {
          
          return this.realmName;
          
      }
      
      /**
       * Set the Realm Name.
       */
      public void setRealmName(String realmName) {
          
          this.realmName = realmName;
          
      }
      
      /**
       * Return the Realm type.
       */
      public String getRealmType() {
          
          return this.realmType;
          
      }
      
      /**
       * Set the Realm type.
       */
      public void setRealmType(String realmType) {
          
          this.realmType = realmType;
          
      }
      
      /**
       * Return the debugVals.
       */
      public ArrayList getDebugLvlVals() {
          
          return this.debugLvlVals;
          
      }
      
      /**
       * Set the debugVals.
       */
      public void setDebugLvlVals(ArrayList debugLvlVals) {
          
          this.debugLvlVals = debugLvlVals;
          
      }
      
      /**
       * Return the Debug Level Text.
       */
      public String getDebugLvl() {
          
          return this.debugLvl;
          
      }
      
      /**
       * Set the Debug Level Text.
       */
      public void setDebugLvl(String debugLvl) {
          
          this.debugLvl = debugLvl;
          
      }
      
      /**
       * Return the resource Name.
       */
      public String getResource() {
          
          return this.resource;
          
      }
      
      /**
       * Set the resource Name.
       */
      public void setResource(String resource) {
          
          this.resource = resource;
          
      }
      
      /**
       * Return the label of the node that was clicked.
       */
      public String getNodeLabel() {
          
          return this.nodeLabel;
          
      }
      
      /**
       * Set the node label.
       */
      public void setNodeLabel(String nodeLabel) {
          
          this.nodeLabel = nodeLabel;
          
      }
      
      // --------------------------------------------------------- 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) {
          
          this.debugLvl = "0";
          this.resource = 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");
          
          // front end validation when save is clicked.
          if (submit != null) {
              if ((resource == null) || (resource.length() < 1)) {
                  errors.add("resource",
                  new ActionError("error.resource.required"));
              }
          }
          return errors;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>