User: user57  
  Date: 01/07/09 22:03:17

  Modified:    src/main/org/jboss/ejb/plugins AbstractInterceptor.java
                        SecurityProxyInterceptor.java
  Log:
   o documented AbstractInterceptor a bit more.
   o changed logging in SecurityProxyInterceptor to log4j
  
  Revision  Changes    Path
  1.6       +30 -22    jboss/src/main/org/jboss/ejb/plugins/AbstractInterceptor.java
  
  Index: AbstractInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/AbstractInterceptor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractInterceptor.java  2001/06/18 20:01:23     1.5
  +++ AbstractInterceptor.java  2001/07/10 05:03:16     1.6
  @@ -13,11 +13,11 @@
   import org.jboss.ejb.MethodInvocation;
   
   /**
  - *   <description> 
  + * An abstract base class for container interceptors.
    *      
  - *   @see <related>
  - *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
  - *   @version $Revision: 1.5 $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  + * @version $Revision: 1.6 $
    */
   public abstract class AbstractInterceptor
      implements Interceptor
  @@ -25,6 +25,8 @@
      // Constants -----------------------------------------------------
       
      // Attributes ----------------------------------------------------
  +
  +   /** The next interceptor in the chain. */
      protected Interceptor nextInterceptor;
   
      // Static --------------------------------------------------------
  @@ -34,39 +36,45 @@
      // Public --------------------------------------------------------
   
      // Interceptor implementation ------------------------------------
  +   
      public abstract void setContainer(Container container);
  +   
      public abstract Container getContainer();
  -   public void setNext(Interceptor interceptor) { nextInterceptor = interceptor; }
  -   public Interceptor getNext() { return nextInterceptor; }
  +   
  +   public void setNext(final Interceptor interceptor) {
  +      // assert interceptor != null
  +      nextInterceptor = interceptor;
  +   }
      
  -   public void init()
  -      throws Exception
  -   {
  +   public Interceptor getNext() {
  +      return nextInterceptor;
  +   }
  +
  +   public void init() throws Exception {
  +      // empty
      }
      
  -   public void start()
  -      throws Exception
  -   {
  +   public void start() throws Exception {
  +      // empty
      }
      
  -   public void stop()
  -   {
  +   public void stop() {
  +      // empty
      }
   
  -   public void destroy()
  -   {
  +   public void destroy() {
  +      // empty
      }
   
  -   public Object invokeHome(MethodInvocation mi)
  -      throws Exception
  -   {
  +   public Object invokeHome(final MethodInvocation mi) throws Exception {
  +      // assert mi != null;
         return getNext().invokeHome(mi);
      }
   
  -   public Object invoke(MethodInvocation mi)
  -      throws Exception
  -   {
  +   public Object invoke(final MethodInvocation mi) throws Exception {
  +      // assert mi != null;
         return getNext().invoke(mi);
      }
  +   
      // Protected -----------------------------------------------------
   }
  
  
  
  1.4       +149 -138  
jboss/src/main/org/jboss/ejb/plugins/SecurityProxyInterceptor.java
  
  Index: SecurityProxyInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/SecurityProxyInterceptor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SecurityProxyInterceptor.java     2001/06/18 20:01:23     1.3
  +++ SecurityProxyInterceptor.java     2001/07/10 05:03:16     1.4
  @@ -12,6 +12,8 @@
   import javax.ejb.EJBContext;
   import javax.naming.InitialContext;
   
  +import org.apache.log4j.Category;
  +
   import org.jboss.ejb.Container;
   import org.jboss.ejb.ContainerInvokerContainer;
   import org.jboss.ejb.EnterpriseContext;
  @@ -21,147 +23,156 @@
   import org.jboss.security.SecurityProxy;
   import org.jboss.security.SecurityProxyFactory;
   
  -/** The SecurityProxyInterceptor is where the EJB custom security proxy
  -integration is performed. This interceptor is dynamically added to container
  -interceptors when the deployment descriptors specifies a security
  -proxy. It is added just before the container interceptor so that the
  -interceptor has access to the EJB instance and context.
  -
  -@author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>.
  -@version $Revision: 1.3 $
  -*/
  -public class SecurityProxyInterceptor extends AbstractInterceptor
  +/**
  + * The SecurityProxyInterceptor is where the EJB custom security proxy
  + * integration is performed. This interceptor is dynamically added to container
  + * interceptors when the deployment descriptors specifies a security
  + * proxy. It is added just before the container interceptor so that the
  + * interceptor has access to the EJB instance and context.
  + * 
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>.
  + * @version $Revision: 1.4 $
  + */
  +public class SecurityProxyInterceptor
  +   extends AbstractInterceptor
   {
  -    /** The JNDI name of the SecurityProxyFactory used to wrap security
  -        proxy objects that do not implement the SecurityProxy interface
  -     */
  -    public final String SECURITY_PROXY_FACTORY_NAME = "java:/SecurityProxyFactory";
  -
  -    /**
  -     * @clientCardinality 0..1
  -     * @supplierCardinality 1 
  -     */
  -    protected Container container;
  -    protected EJBSecurityManager securityManager;
  -
  -    /**
  -     * @supplierCardinality 0..1
  -     * @clientCardinality 1 
  -     * @supplierQualifier custom security
  -     */
  -    protected SecurityProxy securityProxy;
  -
  -    public SecurityProxyInterceptor()
  -    {
  -    }
  -
  -    public void setContainer(Container container)
  -    {
  -        this.container = container;
  -        securityManager = container.getSecurityManager();
  -        Object secProxy = container.getSecurityProxy();
  -        if( secProxy != null )
  -        {
  -            /* If this is not a SecurityProxy instance then use the default
  -                SecurityProxy implementation
  -            */
  -            if( (secProxy instanceof SecurityProxy) == false )
  -            {
  -                try
  -                {
  -                    // Get default SecurityProxyFactory from JNDI at
  -                    InitialContext iniCtx = new InitialContext();
  -                    SecurityProxyFactory proxyFactory = (SecurityProxyFactory) 
iniCtx.lookup(SECURITY_PROXY_FACTORY_NAME);
  -                    securityProxy = proxyFactory.create(secProxy);
  -                }
  -                catch(Exception e)
  -                {
  -                    System.out.println("Failed to initialze DefaultSecurityProxy");
  -                    e.printStackTrace();
  -                }
  -            }
  -            else
  -            {
  -                securityProxy = (SecurityProxy) secProxy;
  -            }
  -
  -            // Initialize the securityProxy
  +   /** 
  +    * The JNDI name of the SecurityProxyFactory used to wrap security
  +    * proxy objects that do not implement the SecurityProxy interface
  +    */
  +   public final String SECURITY_PROXY_FACTORY_NAME =
  +      "java:/SecurityProxyFactory";
  +
  +   /** Instance logger. */
  +   protected Category log = Category.getInstance(this.getClass());
  +   
  +   /**
  +    * @clientCardinality 0..1
  +    * @supplierCardinality 1 
  +    */
  +   protected Container container;
  +
  +   protected EJBSecurityManager securityManager;
  +
  +   /**
  +    * @supplierCardinality 0..1
  +    * @clientCardinality 1 
  +    * @supplierQualifier custom security
  +    */
  +   protected SecurityProxy securityProxy;
  +
  +   public SecurityProxyInterceptor()
  +   {
  +      super();
  +   }
  +
  +   public void setContainer(Container container)
  +   {
  +      this.container = container;
  +      securityManager = container.getSecurityManager();
  +      Object secProxy = container.getSecurityProxy();
  +      if( secProxy != null )
  +      {
  +         // If this is not a SecurityProxy instance then use the default
  +         // SecurityProxy implementation
  +         if( (secProxy instanceof SecurityProxy) == false )
  +         {
               try
  -            {
  -                ContainerInvokerContainer ic = (ContainerInvokerContainer) 
container;
  -                Class beanHome = ic.getHomeClass();
  -                Class beanRemote = ic.getRemoteClass();
  -                securityProxy.init(beanHome, beanRemote, securityManager);
  -            }
  -            catch(Exception e)
               {
  -                System.out.println("Failed to initialze SecurityProxy");
  -                e.printStackTrace();
  -            }
  -            System.out.println("Initialized SecurityProxy="+securityProxy);
  -        }
  -    }
  -
  -    public Container getContainer()
  -    {
  -        return container;
  -    }
  +               // Get default SecurityProxyFactory from JNDI at
  +               InitialContext iniCtx = new InitialContext();
  +               SecurityProxyFactory proxyFactory =
  +                  (SecurityProxyFactory)iniCtx.lookup(SECURITY_PROXY_FACTORY_NAME);
  +               securityProxy = proxyFactory.create(secProxy);
  +            }
  +            catch (Exception e)
  +            {
  +               log.error("Failed to initialze DefaultSecurityProxy", e);
  +            }
  +         }
  +         else
  +         {
  +            securityProxy = (SecurityProxy) secProxy;
  +         }
  +
  +         // Initialize the securityProxy
  +         try
  +         {
  +            ContainerInvokerContainer ic =
  +               (ContainerInvokerContainer)container;
  +            Class beanHome = ic.getHomeClass();
  +            Class beanRemote = ic.getRemoteClass();
  +            securityProxy.init(beanHome, beanRemote, securityManager);
  +         }
  +         catch(Exception e)
  +         {
  +            log.error("Failed to initialze SecurityProxy", e);
  +         }
  +         log.info("Initialized SecurityProxy=" + securityProxy);
  +      }
  +   }
  +
  +   public Container getContainer()
  +   {
  +      return container;
  +   }
   
      // Container implementation --------------------------------------
  -    public void start() throws Exception
  -    {
  -        super.start();
  -    }
  -
  -    public Object invokeHome(MethodInvocation mi) throws Exception
  -    {
  -        // Apply any custom security checks
  -        if( securityProxy != null )
  -        {
  -            EJBContext ctx = null;
  -            EnterpriseContext ectx = mi.getEnterpriseContext();
  -            if( ectx != null )
  -                ctx = ectx.getEJBContext();
  -            Object[] args = mi.getArguments();
  -            securityProxy.setEJBContext(ctx);
  -            try
  -            {
  -                securityProxy.invokeHome(mi.getMethod(), args);
  -            }
  -            catch(SecurityException e)
  -            {
  -                Principal principal = mi.getPrincipal();
  -                String msg = "SecurityProxy.invokeHome exception, 
principal="+principal;
  -                System.err.println(msg);
  -                SecurityException se = new SecurityException(msg);
  -                throw new RemoteException("SecurityProxy.invokeHome failure", se);
  -            }
  -        }
  -        return getNext().invokeHome(mi);
  -    }
  -    public Object invoke(MethodInvocation mi) throws Exception
  -    {
  -        // Apply any custom security checks
  -        if( securityProxy != null )
  -        {
  -            Object bean = mi.getEnterpriseContext().getInstance();
  -            EJBContext ctx = mi.getEnterpriseContext().getEJBContext();
  -            Object[] args = mi.getArguments();
  -            securityProxy.setEJBContext(ctx);
  -            try
  -            {
  -                securityProxy.invoke(mi.getMethod(), args, bean);
  -            }
  -            catch(SecurityException e)
  -            {
  -                Principal principal = mi.getPrincipal();
  -                String msg = "SecurityProxy.invoke exception, principal="+principal;
  -                System.err.println(msg);
  -                SecurityException se = new SecurityException(msg);
  -                throw new RemoteException("SecurityProxy.invoke failure", se);
  -            }
  -        }
  -        return getNext().invoke(mi);
  -    }
  -
  +   
  +   public void start() throws Exception
  +   {
  +      super.start();
  +   }
  +
  +   public Object invokeHome(MethodInvocation mi) throws Exception
  +   {
  +      // Apply any custom security checks
  +      if( securityProxy != null )
  +      {
  +         EJBContext ctx = null;
  +         EnterpriseContext ectx = mi.getEnterpriseContext();
  +         if( ectx != null )
  +            ctx = ectx.getEJBContext();
  +         Object[] args = mi.getArguments();
  +         securityProxy.setEJBContext(ctx);
  +         try
  +         {
  +            securityProxy.invokeHome(mi.getMethod(), args);
  +         }
  +         catch(SecurityException e)
  +         {
  +            Principal principal = mi.getPrincipal();
  +            String msg = "SecurityProxy.invokeHome exception, principal=" + 
principal;
  +            log.error(msg, e);
  +            SecurityException se = new SecurityException(msg);
  +            throw new RemoteException("SecurityProxy.invokeHome failure", se);
  +         }
  +      }
  +      return getNext().invokeHome(mi);
  +   }
  +   
  +   public Object invoke(MethodInvocation mi) throws Exception
  +   {
  +      // Apply any custom security checks
  +      if( securityProxy != null )
  +      {
  +         Object bean = mi.getEnterpriseContext().getInstance();
  +         EJBContext ctx = mi.getEnterpriseContext().getEJBContext();
  +         Object[] args = mi.getArguments();
  +         securityProxy.setEJBContext(ctx);
  +         try
  +         {
  +            securityProxy.invoke(mi.getMethod(), args, bean);
  +         }
  +         catch(SecurityException e)
  +         {
  +            Principal principal = mi.getPrincipal();
  +            String msg = "SecurityProxy.invoke exception, principal="+principal;
  +            log.error(msg, e);
  +            SecurityException se = new SecurityException(msg);
  +            throw new RemoteException("SecurityProxy.invoke failure", se);
  +         }
  +      }
  +      return getNext().invoke(mi);
  +   }
   }
  
  
  

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

Reply via email to