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/11 04:03:57 UTC

cvs commit: jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm JDBCRealmAction.java JDBCRealmForm.java SetUpJDBCRealmAction.java

manveen     02/02/10 19:03:57

  Added:       webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm
                        JDBCRealmAction.java JDBCRealmForm.java
                        SetUpJDBCRealmAction.java
  Log:
  Added functionality to display and edit JDBC properties through the admin tool.
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/JDBCRealmAction.java
  
  Index: JDBCRealmAction.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/JDBCRealmAction.java,v 1.1 2002/02/11 03:03:57 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/11 03:03:57 $
   *
   * ====================================================================
   *
   * 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.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;
  import org.apache.webapp.admin.LabelValueBean;
  
  /**
   * Implementation of <strong>Action</strong> that validates
   * actions on a JDBC Realm.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/11 03:03:57 $
   */
  
  public final class JDBCRealmAction extends Action {
      
      private static MBeanServer mBServer = 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 {
                  
          Locale locale = (Locale)request.getSession().getAttribute(Action.LOCALE_KEY);
  
          if (resources == null) {
              resources = getServlet().getResources();
          }
          
          try{
              
              // front end validation and checking.
              // ===================================================
              
              // 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 connectionPassword = request.getParameter("connectionPassword");
              if(connectionPassword != null) {
                  mBServer.setAttribute(realmObjName,
                  new Attribute(SetUpJDBCRealmAction.CONN_PWD_PROP_NAME,
                  connectionPassword));
              }
              
              String connectionURL = request.getParameter("connectionURL");
              if(connectionURL != null) {
                  mBServer.setAttribute(realmObjName,
                  new Attribute(SetUpJDBCRealmAction.CONN_URL_PROP_NAME,
                  connectionURL));
              }
              
              String connectionName = request.getParameter("connectionName");
              if(connectionName != null) {
                  mBServer.setAttribute(realmObjName,
                  new Attribute(SetUpJDBCRealmAction.CONN_NAME_PROP_NAME,
                  connectionName));
              }
              
              String debugLvlTxt = request.getParameter("debugLvl");
              if(debugLvlTxt != null) {
                  Integer debugLvl = Integer.valueOf(debugLvlTxt);
                  mBServer.setAttribute(realmObjName,
                  new Attribute(SetUpJDBCRealmAction.DEBUG_PROP_NAME,
                  debugLvl));
              }
              
              String digest = request.getParameter("digest");
              if(digest != null) {
                  mBServer.setAttribute(realmObjName,
                  new Attribute(SetUpJDBCRealmAction.DIGEST_PROP_NAME,
                  digest));
              }
              
              String passwordCol = request.getParameter("passwordCol");
              if(passwordCol != null) {
                  mBServer.setAttribute(realmObjName,
                  new Attribute(SetUpJDBCRealmAction.PWD_COL_PROP_NAME,
                  passwordCol));
              }
              
              String roleNameCol = request.getParameter("roleNameCol");
              if(roleNameCol != null) {
                  mBServer.setAttribute(realmObjName,
                  new Attribute(SetUpJDBCRealmAction.ROLE_COL_PROP_NAME,
                  roleNameCol));
              }
              
              String roleTable = request.getParameter("roleTable");
              if(roleTable != null) {
                  mBServer.setAttribute(realmObjName,
                  new Attribute(SetUpJDBCRealmAction.ROLE_TABLE_PROP_NAME,
                  roleTable));
              }
              
              String userTable = request.getParameter("userTable");
              if(userTable != null) {
                  mBServer.setAttribute(realmObjName,
                  new Attribute(SetUpJDBCRealmAction.USER_TABLE_PROP_NAME,
                  userTable));
              }
              
          }catch(Throwable t){
              getServlet().log
              (resources.getMessage(locale, "error.set.attributes"), t);
              response.sendError
              (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              resources.getMessage(locale, "error.set.attributes"));
              return (null);
          }
          
          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/JDBCRealmForm.java
  
  Index: JDBCRealmForm.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/JDBCRealmForm.java,v 1.1 2002/02/11 03:03:57 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/11 03:03:57 $
   *
   * ====================================================================
   *
   * 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 jdbc realm page.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/11 03:03:57 $
   */
  
  public final class JDBCRealmForm 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 or MemoryRealm.
       */
      private String realmType = null;
      
      /**
       * Set of valid values for debug level.
       */
      private ArrayList debugLvlVals = null;
      
      /**
       * The text for the digest.
       */
      private String digest = null;
      
      /**
       * The text for the roleNameCol.
       */
      private String roleNameCol = null;
      
      /**
       * The text for the passwordCol.
       */
      private String passwordCol = null;
      
      /**
       * The text for the driver.
       */
      private String driver = null;
      
      /**
       * The text for the node label.
       */
      private String nodeLabel = null;
      
      /**
       * The text for the role table.
       */
      private String roleTable = null;
      
      /**
       * The text for the user table.
       */
      private String userTable = null;
          
      /**
       * The text for the connection user name.
       */
      private String connectionName = null;
      
      /**
       * The text for the connection Password.
       */
      private String connectionPassword = null;
      
      /**
       * The text for the connection URL.
       */
      private String connectionURL = 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 digest.
       */
      public String getDigest() {
          
          return this.digest;
          
      }
      
      /**
       * Set the digest.
       */
      public void setDigest(String digest) {
          
          this.digest = digest;
          
      }
      
      /**
       * Return the roleNameCol.
       */
      public String getRoleNameCol() {
          
          return this.roleNameCol;
          
      }
      
      /**
       * Set the roleNameCol.
       */
      public void setRoleNameCol(String roleNameCol) {
          
          this.roleNameCol = roleNameCol;
          
      }
      /**
       * Return the driver.
       */
      public String getDriver() {
          
          return this.driver;
          
      }
      
      /**
       * Set the driver.
       */
      public void setDriver(String driver) {
          
          this.driver = driver;
          
      }
      
      /**
       * Return the role table.
       */
      public String getRoleTable() {
          
          return this.roleTable;
          
      }
      
      /**
       * Set the roleTable.
       */
      public void setRoleTable(String roleTable) {
          
          this.roleTable = roleTable;
          
      }
      
      /**
       * Return the user table.
       */
      public String getUserTable() {
          
          return this.userTable;
          
      }
      
      /**
       * Set the user Table.
       */
      public void setUserTable(String userTable) {
          
          this.userTable = userTable;
          
      }
      
      /**
       * 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;
          
      }
      
      /**
       * Return the passwordCol.
       */
      public String getPasswordCol() {
          
          return this.passwordCol;
          
      }
      
      /**
       * Set the passwordCol.
       */
      public void setPasswordCol(String passwordCol) {
          
          this.passwordCol = passwordCol;
          
      }
      
      
      /**
       * Return the connection name.
       */
      public String getConnectionName() {
          
          return this.connectionName;
          
      }
      
      /**
       * Set the connectionName.
       */
      public void setConnectionName(String connectionName) {
          
          this.connectionName = connectionName;
          
      }
      
      
      /**
       * Return the connection password.
       */
      public String getConnectionPassword() {
          
          return this.connectionPassword;
          
      }
      
      /**
       * Set the connection password.
       */
      public void setConnectionPassword(String connectionPassword) {
          
          this.connectionPassword = connectionPassword;
          
      }
      
      
      /**
       * Return the connection URL.
       */
      public String getConnectionURL() {
          
          return this.connectionURL;
          
      }
      
      /**
       * Set the connectionURL.
       */
      public void setConnectionURL(String connectionURL) {
          
          this.connectionURL = connectionURL;
          
      }
      
      // --------------------------------------------------------- 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.digest = null;
          this.driver = null;
          
          this.roleNameCol = null;
          this.passwordCol = null;
          this.userTable = null;
          this.roleTable = null;
          
          this.connectionName = null;
          this.connectionPassword = null;
          this.connectionURL = 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");
          String type = request.getParameter("realmType");
          
          // front end validation when save is clicked.        
           if (submit != null) {
               // the following fields are required.
              
              if ((driver == null) || (driver.length() < 1)) {
                  errors.add("driver",
                  new ActionError("error.driver.required"));
              }
           
              if ((roleNameCol == null) || (roleNameCol.length() < 1)) {
                  errors.add("roleNameCol",
                  new ActionError("error.roleNameCol.required"));
              }
           
               if ((passwordCol == null) || (passwordCol.length() < 1)) {
                  errors.add("passwordCol",
                  new ActionError("error.passwordCol.required"));
              }
              
              if ((userTable == null) || (userTable.length() < 1)) {
                  errors.add("userTable",
                  new ActionError("error.userTable.required"));
              }
              
              if ((roleTable == null) || (roleTable.length() < 1)) {
                  errors.add("roleTable",
                  new ActionError("error.roleTable.required"));
              }
              
              if ((connectionName == null) || (connectionName.length() < 1)) {
                  errors.add("connectionName",
                  new ActionError("error.connectionName.required"));
              }
              
              if ((connectionPassword == null) || (connectionPassword.length() < 1)) {
                  errors.add("connectionPassword",
                  new ActionError("error.connectionPassword.required"));
              }
              
               if ((connectionURL == null) || (connectionURL.length() < 1)) {
                  errors.add("connectionURL",
                  new ActionError("error.connectionURL.required"));
              }
          }
                   
          return errors;
      }
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/SetUpJDBCRealmAction.java
  
  Index: SetUpJDBCRealmAction.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/realm/SetUpJDBCRealmAction.java,v 1.1 2002/02/11 03:03:57 manveen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/11 03:03:57 $
   *
   * ====================================================================
   *
   * 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.MBeanServerFactory;
  import javax.management.QueryExp;
  import javax.management.Query;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  
  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 realm is chosen.
   * A realm can be one of three types, namely, Memory, JNDI and JDBC realm.
   *
   * @author Manveen Kaur
   * @version $Revision: 1.1 $ $Date: 2002/02/11 03:03:57 $
   */
  
  public class SetUpJDBCRealmAction extends Action {
      
      private static MBeanServer mBServer = null;
      
      public final static String CONN_NAME_PROP_NAME = "connectionName";
      public final static String CONN_PWD_PROP_NAME = "connectionPassword";
      public final static String CONN_URL_PROP_NAME = "connectionURL";
      
      public final static String DRIVER_PROP_NAME = "driverName";
      public final static String DEBUG_PROP_NAME = "debug";
      public final static String DIGEST_PROP_NAME = "digest";
      public final static String ROLE_COL_PROP_NAME = "roleNameCol";
      public final static String PWD_COL_PROP_NAME = "userCredCol";
      public final static String ROLE_TABLE_PROP_NAME = "userRoleTable";
      public final static String USER_TABLE_PROP_NAME = "userTable";
      
      private String selectedName = null;
      private String realmType = null;
      private String nodeLabel = null;
      private ArrayList debugLvlList = 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 {
          
          HttpSession session = request.getSession();
          realmType = request.getParameter("type");
          Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
          
          if (resources == null) {
              resources = getServlet().getResources();
          }
          
          if (form == null) {
              getServlet().log(" Creating new JDBCRealmForm bean under key "
              + mapping.getAttribute());
              
              form = new JDBCRealmForm();
              
              if ("request".equals(mapping.getScope()))
                  request.setAttribute(mapping.getAttribute(), form);
              else
                  session.setAttribute(mapping.getAttribute(), form);
          }
          
          selectedName = request.getParameter("select");
          realmType = request.getParameter("type");
          nodeLabel = request.getParameter("nodeLabel");
          
          JDBCRealmForm realmFm = (JDBCRealmForm) 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.setDebugLvl(
              ((Integer) mBServer.getAttribute(realmObjName, DEBUG_PROP_NAME)).toString());
              
              realmFm.setDriver(
              ((String) mBServer.getAttribute(realmObjName, DRIVER_PROP_NAME)));
              
              realmFm.setConnectionPassword(
              ((String) mBServer.getAttribute(realmObjName, CONN_PWD_PROP_NAME)));
              
              realmFm.setConnectionName(
              ((String) mBServer.getAttribute(realmObjName, CONN_NAME_PROP_NAME)));
              
              realmFm.setConnectionURL(
              ((String) mBServer.getAttribute(realmObjName, CONN_URL_PROP_NAME)));
              
              // FIXME --digest should be displayed as a pull down menu??
              // But no operation yet to get list of digests.
              realmFm.setDigest(
              ((String) mBServer.getAttribute(realmObjName, DIGEST_PROP_NAME)));
              
              realmFm.setPasswordCol(
              ((String) mBServer.getAttribute(realmObjName, PWD_COL_PROP_NAME)));
              
              realmFm.setRoleNameCol(
              ((String) mBServer.getAttribute(realmObjName, ROLE_COL_PROP_NAME)));
              
              realmFm.setRoleTable(
              ((String) mBServer.getAttribute(realmObjName, ROLE_TABLE_PROP_NAME)));
              
              realmFm.setUserTable(
              ((String) mBServer.getAttribute(realmObjName, USER_TABLE_PROP_NAME)));
              
              
          } catch(Throwable t){
              getServlet().log
              (resources.getMessage(locale, "error.get.attributes"), t);
              response.sendError
              (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              resources.getMessage(locale, "error.get.attributes"));
              return (null);
          }
          
          realmFm.setRealmName(selectedName);
          realmFm.setNodeLabel(nodeLabel);
          
          realmFm.setRealmType(realmType);
          realmFm.setDebugLvlVals(debugLvlList);
          
          // Forward back to the appropriate Realm page
          return (mapping.findForward("JDBCRealm"));
          
      }
  }
  
  
  
  

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