User: oconnor 
  Date: 00/10/14 16:23:16

  Added:       src/main/org/jboss/security DatabaseRealmMappingService.java
                        DatabaseRealmMappingServiceMBean.java
                        DatabaseSecurityManagerService.java
                        DatabaseSecurityManagerServiceMBean.java
  Log:
  To add database-based security to JNDI namespace. Still very raw.
  
  Revision  Changes    Path
  1.1                  
jboss/src/main/org/jboss/security/DatabaseRealmMappingService.java
  
  Index: DatabaseRealmMappingService.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
   
  package org.jboss.security;
  
  import java.io.File;
  import java.net.URL;
  import java.rmi.server.UnicastRemoteObject;
  import java.rmi.RemoteException;
  import java.rmi.ServerException;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.Hashtable;
  
  import javax.naming.InitialContext;
  import javax.naming.Context;
  import javax.naming.Reference;
  import javax.naming.Name;
  import javax.naming.spi.ObjectFactory;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  
  import org.jboss.logging.Log;
  import org.jboss.util.ServiceMBeanSupport;
  
  /**
   *   This is a JMX service which manages access to security realms for a bean.
   *      The service creates it and binds a Reference to it into JNDI.
   *      
   *   @see EJBSecurityManager
   *   @author Daniel O'Connor [EMAIL PROTECTED]
   */
  public class DatabaseRealmMappingService
     extends ServiceMBeanSupport
     implements DatabaseRealmMappingServiceMBean, ObjectFactory
  {
     // Constants -----------------------------------------------------
     public static String JNDI_NAME = "DatabaseRealmMapping";
     private static DatabaseRealmMapping drm;
      
     // Attributes ----------------------------------------------------
        MBeanServer server;
     
     // Static --------------------------------------------------------
  
     // ServiceMBeanSupport overrides ---------------------------------
     public String getName()
     {
        return "Database Realm Mapping";
     }
     
     protected ObjectName getObjectName(MBeanServer server, ObjectName name)
        throws javax.management.MalformedObjectNameException
     {
        this.server = server;
        return new ObjectName(OBJECT_NAME);
     }
        
     protected void initService()
        throws Exception
     {
           // Create a new SM
           drm = new DatabaseRealmMapping();
           // Bind reference to JNDI
           Reference ref = new Reference(DatabaseRealmMapping.class.toString(), 
getClass().getName(), null);
           new InitialContext().bind(JNDI_NAME, ref);
     }
  
     protected void startService()
        throws Exception
     {
     }
     
     protected void stopService()
     {
                try
                {
                        // Remove mapping from JNDI
                        new InitialContext().unbind(JNDI_NAME);
                } catch (Exception e)
                {
                        log.exception(e);
                }
     }
        
        // ObjectFactory implementation ----------------------------------
        public Object getObjectInstance(Object obj,
                                  Name name,
                                  Context nameCtx,
                                  Hashtable environment)
                           throws Exception
        {
                // Return the database realm mapping manager
                return drm;
        }
  }
  
  
  
  
  1.1                  
jboss/src/main/org/jboss/security/DatabaseRealmMappingServiceMBean.java
  
  Index: DatabaseRealmMappingServiceMBean.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.security;
  
  public interface DatabaseRealmMappingServiceMBean
        extends org.jboss.util.ServiceMBean
  {
     // Constants -----------------------------------------------------
     public static final String OBJECT_NAME = ":service=DatabaseRealmMappingFactory";
      
     // Public --------------------------------------------------------
  }
  
  
  
  1.1                  
jboss/src/main/org/jboss/security/DatabaseSecurityManagerService.java
  
  Index: DatabaseSecurityManagerService.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
   
  package org.jboss.security;
  
  import java.io.File;
  import java.net.URL;
  import java.rmi.server.UnicastRemoteObject;
  import java.rmi.RemoteException;
  import java.rmi.ServerException;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.Hashtable;
  
  import javax.naming.InitialContext;
  import javax.naming.Context;
  import javax.naming.Reference;
  import javax.naming.Name;
  import javax.naming.spi.ObjectFactory;
  import javax.naming.CommunicationException;
  
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  
  import org.jboss.logging.Log;
  import org.jboss.util.ServiceMBeanSupport;
  
  import org.jboss.system.EJBSecurityManager;
  
  /**
   *   This is a JMX service which manages the EJBSecurityManager.
   *      The service creates it and binds a Reference to it into JNDI.
   *      The EJBSecurityManager is responsible for validating credentials
   *      associated with principals.
   *      
   *   @see EJBSecurityManager
   *   @author Daniel O'Connor [EMAIL PROTECTED]
   *   @author <a href="mailto:[EMAIL PROTECTED]">Hugo Pinto</a>
   */
  public class DatabaseSecurityManagerService
     extends ServiceMBeanSupport
     implements DatabaseSecurityManagerServiceMBean, ObjectFactory
  {
     // Constants -----------------------------------------------------
     public static String JNDI_NAME = "DatabaseSecurityManager";
      
     // Attributes ----------------------------------------------------
      MBeanServer server;
     
     // Static --------------------------------------------------------
     static EJBSecurityManager sm;
  
     // ServiceMBeanSupport overrides ---------------------------------
     public String getName()
     {
        return "Database Security manager";
      }
     
     protected ObjectName getObjectName(MBeanServer server, ObjectName name)
        throws javax.management.MalformedObjectNameException
     {
      this.server = server;
        return new ObjectName(OBJECT_NAME);
     }
      
     protected void initService()
        throws Exception
     {
         // Create a new SM
         sm = new EJBSecurityManagerDatabaseImpl();
         
         // Bind reference to SM in JNDI
         Reference ref = new Reference(sm.getClass().toString(), getClass().getName(), 
null);
         new InitialContext().bind(JNDI_NAME, ref);
     }
      
     protected void startService()
        throws Exception
     {
     }
     
     protected void stopService()
     {
         try
         {
           // Remove SM from JNDI
           new InitialContext().unbind(JNDI_NAME);
          } catch (CommunicationException e) {
              // Do nothing, the naming services is already stopped   
          }
          
         catch (Exception e)
         {
           log.exception(e);
         }
     }
      
      // ObjectFactory implementation ----------------------------------
      public Object getObjectInstance(Object obj,
                                  Name name,
                                  Context nameCtx,
                                  Hashtable environment)
                           throws Exception
      {
         // Return the security manager
         return sm;
      }
  }
  
  
  
  
  1.1                  
jboss/src/main/org/jboss/security/DatabaseSecurityManagerServiceMBean.java
  
  Index: DatabaseSecurityManagerServiceMBean.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.security;
  
  public interface DatabaseSecurityManagerServiceMBean
        extends org.jboss.util.ServiceMBean
  {
     // Constants -----------------------------------------------------
     public static final String OBJECT_NAME = ":service=DatabaseSecurityManager";
      
     // Public --------------------------------------------------------
  }
  
  
  

Reply via email to