User: ejort   
  Date: 01/12/30 00:59:16

  Modified:    src/main/org/jboss/ejb/plugins
                        EntityInstanceInterceptor.java
                        EntityMultiInstanceInterceptor.java
                        MessageDrivenInstanceInterceptor.java
                        StatefulSessionInstanceInterceptor.java
                        StatelessSessionInstanceInterceptor.java
  Log:
  Fixed the security unit tests.
  
  Revision  Changes    Path
  1.48      +43 -35    
jboss/src/main/org/jboss/ejb/plugins/EntityInstanceInterceptor.java
  
  Index: EntityInstanceInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/EntityInstanceInterceptor.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- EntityInstanceInterceptor.java    2001/12/19 05:39:24     1.47
  +++ EntityInstanceInterceptor.java    2001/12/30 08:59:15     1.48
  @@ -19,6 +19,8 @@
   import org.jboss.invocation.Invocation;
   import org.jboss.ejb.CacheKey;
   
  +import org.jboss.security.SecurityAssociation;
  +
   /**
   * The instance interceptors role is to acquire a context representing
   * the target object from the cache.
  @@ -40,7 +42,7 @@
   * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
  -* @version $Revision: 1.47 $
  +* @version $Revision: 1.48 $
   *
   * <p><b>Revisions:</b><br>
   * <p><b>2001/06/28: marcf</b>
  @@ -112,37 +114,40 @@
      {
         return container;
      }
  -     
  +
      // Interceptor implementation --------------------------------------
  -     
  +
      public Object invokeHome(Invocation mi)
         throws Exception
      {
         // Get context
         EntityEnterpriseContext ctx = 
(EntityEnterpriseContext)((EntityContainer)getContainer()).getInstancePool().get();
  -             
  +
                // Pass it to the method invocation
         mi.setEnterpriseContext(ctx);
  -             
  +
         // Give it the transaction
         ctx.setTransaction(mi.getTransaction());
  -             
  +
  +      // Set the current security information
  +      ctx.setPrincipal(SecurityAssociation.getPrincipal());
  +
            // Invoke through interceptors
         Object rtn = getNext().invokeHome(mi);
         // Is the context now with an identity? in which case we need to insert
         if (ctx.getId() != null)
         {
  -         
  +
            BeanLock lock = container.getLockManager().getLock(ctx.getCacheKey());
  -         
  +
            lock.sync(); // lock all access to BeanLock
  -         
  -         try 
  +
  +         try
            {
               // marcf: possible race on creation and usage
  -            // insert instance in cache, 
  +            // insert instance in cache,
               container.getInstanceCache().insert(ctx);
  -            
  +
            }
            finally
            {
  @@ -153,38 +158,41 @@
         //Do not send back to pools in any case, let the instance be GC'ed
         return rtn;
      }
  -     
  +
      public Object invoke(Invocation mi)
         throws Exception
      {
  -             
  +
         // The key
         CacheKey key = (CacheKey) mi.getId();
  -             
  +
         // The context
         EntityEnterpriseContext ctx = (EntityEnterpriseContext) 
container.getInstanceCache().get(key);
  -             
  +
         boolean trace = log.isTraceEnabled();
         if( trace ) log.trace("Begin invoke, key="+key);
  -                     
  -      // Associate transaction, in the new design the lock already has the 
transaction from the 
  +
  +      // Associate transaction, in the new design the lock already has the 
transaction from the
         // previous interceptor
         ctx.setTransaction(mi.getTransaction());
  -             
  +
  +      // Set the current security information
  +      ctx.setPrincipal(SecurityAssociation.getPrincipal());
  +
         // Set context on the method invocation
         mi.setEnterpriseContext(ctx);
  -             
  +
         boolean exceptionThrown = false;
  -             
  +
         try
  -      {      
  +      {
            return getNext().invoke(mi);
         }
         catch (RemoteException e)
         {
            exceptionThrown = true;
            throw e;
  -      } 
  +      }
         catch (RuntimeException e)
         {
            exceptionThrown = true;
  @@ -193,41 +201,41 @@
         {
            exceptionThrown = true;
            throw e;
  -      } 
  +      }
         finally
         {
            // ctx can be null if cache.get throws an Exception, for
            // example when activating a bean.
            if (ctx != null)
  -         {                           
  -                             // If an exception has been thrown, 
  -            if (exceptionThrown &&                                   
  -                // if tx, the ctx has been registered in an 
InstanceSynchronization. 
  +         {
  +                             // If an exception has been thrown,
  +            if (exceptionThrown &&
  +                // if tx, the ctx has been registered in an InstanceSynchronization.
                   // that will remove the context, so we shouldn't.
                   // if no synchronization then we need to do it by hand
  -                !ctx.hasTxSynchronization()) 
  +                !ctx.hasTxSynchronization())
               {
                  // Discard instance
                  // EJB 1.1 spec 12.3.1
                  container.getInstanceCache().remove(key);
  -                                     
  +
                  if( trace ) log.trace("Ending invoke, exceptionThrown, ctx="+ctx);
               }
               else if (ctx.getId() == null)
               {
                  // The key from the Invocation still identifies the right cachekey
                  container.getInstanceCache().remove(key);
  -                                     
  +
                  if( trace )   log.trace("Ending invoke, cache removal, ctx="+ctx);
                  // no more pool return
               }
            }
  -                     
  +
            if( trace ) log.trace("End invoke, key="+key+", ctx="+ctx);
  -             
  -      }      // end invoke           
  +
  +      }      // end invoke
      }
  -     
  +
   }
   
   
  
  
  
  1.5       +20 -12    
jboss/src/main/org/jboss/ejb/plugins/EntityMultiInstanceInterceptor.java
  
  Index: EntityMultiInstanceInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/EntityMultiInstanceInterceptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EntityMultiInstanceInterceptor.java       2001/12/19 05:39:24     1.4
  +++ EntityMultiInstanceInterceptor.java       2001/12/30 08:59:15     1.5
  @@ -17,13 +17,15 @@
   import org.jboss.invocation.Invocation;
   import org.jboss.ejb.CacheKey;
   
  +import org.jboss.security.SecurityAssociation;
  +
   /**
    * The instance interceptors role is to acquire a context representing
    * the target object from the cache.
    *
    *    
    * @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    *
    * <p><b>Revisions:</b><br>
    * <p><b>2001/08/08: billb</b>
  @@ -63,21 +65,24 @@
      {
         // Get context
         EntityEnterpriseContext ctx = 
(EntityEnterpriseContext)((EntityContainer)getContainer()).getInstancePool().get();
  -             
  +
                // Pass it to the method invocation
         mi.setEnterpriseContext(ctx);
  -             
  +
         // Give it the transaction
         ctx.setTransaction(mi.getTransaction());
  -             
  +
  +      // Set the current security information
  +      ctx.setPrincipal(SecurityAssociation.getPrincipal());
  +
         // Invoke through interceptors
         return getNext().invokeHome(mi);
      }
  -     
  +
      public Object invoke(Invocation mi)
         throws Exception
      {
  -             
  +
         // The key
         CacheKey key = (CacheKey) mi.getId();
   
  @@ -93,20 +98,23 @@
            ctx.setId(key.getId());
            container.getPersistenceManager().activateEntity(ctx);
         }
  -             
  +
         boolean trace = log.isTraceEnabled();
         if( trace ) log.trace("Begin invoke, key="+key);
  -                     
  -      // Associate transaction, in the new design the lock already has the 
transaction from the 
  +
  +      // Associate transaction, in the new design the lock already has the 
transaction from the
         // previous interceptor
         ctx.setTransaction(mi.getTransaction());
  -             
  +
  +      // Set the current security information
  +      ctx.setPrincipal(SecurityAssociation.getPrincipal());
  +
         // Set context on the method invocation
         mi.setEnterpriseContext(ctx);
  -             
  +
         return getNext().invoke(mi);
      }
  -     
  +
   }
   
   
  
  
  
  1.10      +17 -9     
jboss/src/main/org/jboss/ejb/plugins/MessageDrivenInstanceInterceptor.java
  
  Index: MessageDrivenInstanceInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/MessageDrivenInstanceInterceptor.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- MessageDrivenInstanceInterceptor.java     2001/12/19 05:40:51     1.9
  +++ MessageDrivenInstanceInterceptor.java     2001/12/30 08:59:16     1.10
  @@ -14,6 +14,8 @@
   import org.jboss.invocation.Invocation;
   import org.jboss.ejb.EnterpriseContext;
   
  +import org.jboss.security.SecurityAssociation;
  +
   /**
    * This container acquires the given instance. This must be used after
    * the EnvironmentInterceptor, since acquiring instances requires a proper
  @@ -22,7 +24,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>.
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  - * @version $Revision: 1.9 $
  + * @version $Revision: 1.10 $
    */
   public class MessageDrivenInstanceInterceptor
      extends AbstractInterceptor
  @@ -37,9 +39,9 @@
       *
       * @throws ClassCastException    Not a <tt>MessageDrivenContainer</tt>.
       */
  -   public void setContainer(final Container container) 
  -   { 
  -      this.container = (MessageDrivenContainer)container; 
  +   public void setContainer(final Container container)
  +   {
  +      this.container = (MessageDrivenContainer)container;
      }
   
      /**
  @@ -51,7 +53,7 @@
      {
         return container;
      }
  -   
  +
      /**
       * Message driven beans do not have homes.
       *
  @@ -62,18 +64,24 @@
      {
         throw new Error("Not valid for MessageDriven beans");
      }
  -   
  +
      // Interceptor implementation --------------------------------------
   
      public Object invoke(final Invocation mi)
         throws Exception
      {
         // Get context
  -      mi.setEnterpriseContext(container.getInstancePool().get());
  -      
  +      EnterpriseContext ctx = container.getInstancePool().get();
  +
  +      // Set the current security information
  +      ctx.setPrincipal(SecurityAssociation.getPrincipal());
  +
  +      // Use this context
  +      mi.setEnterpriseContext(ctx);
  +
         // There is no need for synchronization since the instance is always
         // fresh also there should never be a tx associated with the instance.
  -      
  +
         try
         {
            // Invoke through interceptors
  
  
  
  1.25      +49 -41    
jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.java
  
  Index: StatefulSessionInstanceInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- StatefulSessionInstanceInterceptor.java   2001/12/19 05:45:37     1.24
  +++ StatefulSessionInstanceInterceptor.java   2001/12/30 08:59:16     1.25
  @@ -29,13 +29,15 @@
   import org.jboss.invocation.Invocation;
   import org.jboss.metadata.SessionMetaData;
   
  +import org.jboss.security.SecurityAssociation;
  +
   /**
    * This container acquires the given instance. 
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
  - * @version $Revision: 1.24 $
  + * @version $Revision: 1.25 $
    *
    * <p><b>Revisions:</b>
    * <p><b>20010704 marcf</b>
  @@ -87,7 +89,7 @@
      // Constructors -------------------------------------------------
        
      // Public -------------------------------------------------------
  -     
  +
      public void setContainer(Container container) 
      { 
         this.container = (StatefulSessionContainer)container; 
  @@ -111,30 +113,33 @@
                
         // set the context on the Invocation
         mi.setEnterpriseContext(ctx);
  -             
  +
         // It is a new context for sure so we can lock it
         ctx.lock();
  -             
  +
  +      // Set the current security information
  +      ctx.setPrincipal(SecurityAssociation.getPrincipal());
  +
         try
         {
            // Invoke through interceptors
            return getNext().invokeHome(mi);
         } finally
         {
  -         synchronized (ctx) 
  +         synchronized (ctx)
            {
               // Release the lock
               ctx.unlock();
  -                             
  +
               // Still free? Not free if create() was called successfully
               if (ctx.getId() == null)
               {
  -               container.getInstancePool().free(ctx); 
  +               container.getInstancePool().free(ctx);
               }
            }
         }
      }
  -     
  +
      protected void register(EnterpriseContext ctx, Transaction tx, BeanLock lock)
      {
         // Create a new synchronization
  @@ -148,7 +153,7 @@
                                
               return;
            }
  -                     
  +
            // We want to be notified when the transaction commits
            try
            {
  @@ -161,19 +166,19 @@
               getContainer().getLockManager().removeLockRef(lock.getId());
               throw ex;
            }
  -                     
  +
            // EJB 1.1, 6.5.3
            synch.afterBegin();
  -             
  +
         } catch (RollbackException e) {
  -             
  +
         } catch (Exception e) {
  -                     
  +
            throw new EJBException(e);
  -             
  +
         }
      }
  -     
  +
      public Object invoke(Invocation mi)
         throws Exception
      {
  @@ -181,7 +186,7 @@
            (AbstractInstanceCache)container.getInstanceCache();
         Object id = mi.getId();
         EnterpriseContext ctx = null;
  -             
  +
         BeanLock lock = (BeanLock)container.getLockManager().getLock(id);
         try
         {
  @@ -195,7 +200,7 @@
   
               // BMT beans will lock and replace tx no matter what, CMT do work on 
transaction
               if (!((SessionMetaData)container.getBeanMetaData()).isBeanManagedTx()) {
  -                             
  +
                  // Do we have a running transaction with the context
                  if (ctx.getTransaction() != null &&
                      // And are we trying to enter with another transaction
  @@ -204,27 +209,27 @@
                     // Calls must be in the same transaction
                     throw new RemoteException("Application Error: tried to enter 
Stateful bean with different transaction context");
                  }
  -                             
  +
                  //If the instance will participate in a new transaction we register 
a sync for it
                  if (ctx.getTransaction() == null && mi.getTransaction() != null) {
                     register(ctx, mi.getTransaction(), lock);
                  }
               }
  -                     
  +
               if (!ctx.isLocked())
               {
  -                             
  +
                  //take it!
  -               ctx.lock();  
  -            } 
  -            else 
  +               ctx.lock();
  +            }
  +            else
               {
                  if (!isCallAllowed(mi))
                  {
                     // Concurent calls are not allowed
                     throw new RemoteException("Application Error: no concurrent calls 
on stateful beans");
                  }
  -               else 
  +               else
                  {
                     ctx.lock();
                  }
  @@ -234,7 +239,10 @@
            {
               lock.releaseSync();
            }
  -             
  +
  +         // Set the current security information
  +         ctx.setPrincipal(SecurityAssociation.getPrincipal());
  +
            try
            {
               // Invoke through interceptors
  @@ -244,34 +252,34 @@
               // Discard instance
               container.getInstanceCache().remove(mi.getId());
               ctx = null;
  -                     
  +
               throw e;
            } catch (RuntimeException e)
            {
               // Discard instance
               container.getInstanceCache().remove(mi.getId());
               ctx = null;
  -                     
  +
               throw e;
            } catch (Error e)
            {
               // Discard instance
               container.getInstanceCache().remove(mi.getId());
               ctx = null;
  -                     
  +
               throw e;
  -         } finally 
  +         } finally
            {
               if (ctx != null)
               {
                  // Still a valid instance
  -               lock.sync(); // synchronized(ctx) 
  +               lock.sync(); // synchronized(ctx)
                  try
                  {
  -                                     
  +
                     // release it
                     ctx.unlock();
  -                                     
  +
                     // if removed, remove from cache
                     if (ctx.getId() == null)
                     {
  @@ -291,8 +299,8 @@
            container.getLockManager().removeLockRef(lock.getId());
         }
      }
  -     
  -   protected boolean isCallAllowed(Invocation mi) 
  +
  +   protected boolean isCallAllowed(Invocation mi)
      {
         Method m = mi.getMethod();
         if (m.equals(getEJBHome) ||
  @@ -305,9 +313,9 @@
         }
         return false;
      }
  -     
  +
      // Inner classes -------------------------------------------------
  -     
  +
      private class InstanceSynchronization
         implements Synchronization
      {
  @@ -315,21 +323,21 @@
          *  The transaction we follow.
          */
         private Transaction tx;
  -             
  +
         /**
          *  The context we manage.
          */
         private EnterpriseContext ctx;
  -             
  +
         // a utility boolean for session sync
         private boolean notifySession = false;
  -             
  +
         // Utility methods for the notifications
         private Method afterBegin;
         private Method beforeCompletion;
         private Method afterCompletion;
         private BeanLock lock;
  -             
  +
         /**
          *  Create a new instance synchronization instance.
          */
  @@ -382,7 +390,7 @@
                        
            // lock the context the transaction is being commited (no need for sync)
            ctx.lock();
  -                     
  +
            if (notifySession) {
               try {
                                        
  
  
  
  1.11      +11 -3     
jboss/src/main/org/jboss/ejb/plugins/StatelessSessionInstanceInterceptor.java
  
  Index: StatelessSessionInstanceInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/StatelessSessionInstanceInterceptor.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- StatelessSessionInstanceInterceptor.java  2001/12/19 07:36:50     1.10
  +++ StatelessSessionInstanceInterceptor.java  2001/12/30 08:59:16     1.11
  @@ -13,14 +13,16 @@
   import org.jboss.ejb.EnterpriseContext;
   import org.jboss.ejb.StatelessSessionContainer;
   
  +import org.jboss.security.SecurityAssociation;
   
  +
   /**
    * This container acquires the given instance. This must be used after
    * the EnvironmentInterceptor, since acquiring instances requires a proper
    * JNDI environment to be set
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
  - * @version $Revision: 1.10 $
  + * @version $Revision: 1.11 $
    */
   public class StatelessSessionInstanceInterceptor
      extends AbstractInterceptor
  @@ -58,8 +60,14 @@
      public Object invoke(final Invocation mi) throws Exception
      {
         // Get context
  -      mi.setEnterpriseContext(container.getInstancePool().get());
  -      
  +      EnterpriseContext ctx = container.getInstancePool().get();
  +
  +      // Set the current security information
  +      ctx.setPrincipal(SecurityAssociation.getPrincipal());
  +
  +      // Use this context
  +      mi.setEnterpriseContext(ctx);
  +
         // There is no need for synchronization since the instance is always fresh 
also there should
         // never be a tx associated with the instance.
         
  
  
  

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

Reply via email to