User: juhalindfors
  Date: 01/04/16 14:47:56

  Added:       src/org/jboss/admin/beans AdminServerBean.java
                        NoRootException.java
  Log:
  some initial sketches for the management model
  
  Revision  Changes    Path
  1.1                  admin/src/org/jboss/admin/beans/AdminServerBean.java
  
  Index: AdminServerBean.java
  ===================================================================
  /*
   * Class AdminServerBean.java
   * Copyright (C) 2001  Juha Lindfors
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Library General Public
   * License as published by the Free Software Foundation; either
   * version 2 of the License, or (at your option) any later version.
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Library General Public License for more details.
   *
   * You should have received a copy of the GNU Library General Public
   * License along with this library; if not, write to the
   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   * Boston, MA  02111-1307, USA.
   *
   * This package and its source code is available at www.jboss.org
   * $Id: AdminServerBean.java,v 1.1 2001/04/16 21:47:56 juhalindfors Exp $
   */     
  package org.jboss.admin.beans;
  
  // standard imports
  import javax.ejb.CreateException;
  import javax.ejb.SessionBean;
  import javax.ejb.SessionContext;
  import javax.management.MalformedObjectNameException;
   
  // JBoss classes
  import org.jboss.util.MBeanProxy;
  import org.jboss.admin.mbean.AdminServerMBean;
  
  /**
   * ...
   *
   * @ejb-name AdminServer
   *     The EJB name for this bean. Used in both ejb-jar.xml and jboss.xml
   *     descriptors.
   *
   * @security-role-ref new_install temp
   * @stateful-session
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>
   * @version $Revision: 1.1 $
   */     
  public class AdminServerBean implements SessionBean {
      
      /** Security role reference used to identify a newly installed server instance */
      private final static String NEW_INSTALL = "new_install";
  
      // serializable fields (for passivation)
      private SessionContext ctx     = null;
      private AdminServerMBean admin = null;
       
       
  /*
   *************************************************************************
   *
   *      PUBLIC INSTANCE METHODS
   *
   *************************************************************************
   */     
  
      /**
       * @create-method
       * @permission root
       * 
       */
      public void ejbCreate() throws CreateException { 
          try {
              admin = createAdminProxy();
          }
          catch (MalformedObjectNameException e) {
              throw new CreateException("Unable to create an MBean proxy to " + 
AdminServerMBean.OBJECT_NAME + " due to malformed object name.");
          }
      }
      
      /**
       * @create-method
       * @permission temp
       */
      public void ejbCreate(String user, char[] password) throws CreateException {
          try {
              admin = createAdminProxy();
              admin.createRoot(user, password);
          
              // User root = admin.createUser(user, password);
              // Role role = admin.createRole("root");
          
              // this constructor should be accessible only once
              // admin.deleteUser("jboss");
              // admin.deleteRole("temp");
          }
          catch (MalformedObjectNameException e) {
              throw new CreateException("Unable to create an MBean proxy to " + 
AdminServerMBean.OBJECT_NAME + " due to malformed object name.");
          }
      }
      
      /**
       * @remote-method
       * @permission root
       * @permission temp
       */
      public boolean isAdminServerEnabled() throws NoRootException {
          
          if (ctx.isCallerInRole(NEW_INSTALL))
             throw new NoRootException("Root not installed");
             
          return true;
      }
      
      
  /*
   *************************************************************************
   *
   *      IMPLEMENTS  SESSION_BEAN  INTERFACE
   *
   *************************************************************************
   */ 
  
      /**
       * Stores the session context upon creation.
       *
       * @param   ctx     session context object
       */
      public void setSessionContext(SessionContext ctx) {
          this.ctx = ctx;    
      }
      
      public void ejbActivate()  {    }
  
      public void ejbPassivate() {    }
      
      public void ejbRemove() { }
  
  /*
   *************************************************************************
   *
   *      PRIVATE INSTANCE METHODS
   *
   *************************************************************************
   */     
  
      /*
       * returns proxy implementing the mbean interface (proxy should be serializable)
       */
      private AdminServerMBean createAdminProxy() throws MalformedObjectNameException {
          return (AdminServerMBean)MBeanProxy.create(
                  AdminServerMBean.class, AdminServerMBean.OBJECT_NAME);               
                      
      }
      
      
  }
  
  
  
  1.1                  admin/src/org/jboss/admin/beans/NoRootException.java
  
  Index: NoRootException.java
  ===================================================================
  /*
   * JBoss, the OpenSource EJB server
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.admin.beans;
  
  
  /**
   *   ... 
   *      
   *   @author Juha Lindfors ([EMAIL PROTECTED])
   *   @version $Revision: 1.1 $
   */
  public class NoRootException extends Exception {
  
      public NoRootException() {
          super();
      }
      
      public NoRootException(String msg) {
          super(msg);
      }
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to