[jboss-cvs] JBossAS SVN: r100471 - in projects/ejb3/trunk/core/src: main/java/org/jboss/ejb3/pool and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Feb 5 04:00:55 EST 2010


Author: wolfc
Date: 2010-02-05 04:00:54 -0500 (Fri, 05 Feb 2010)
New Revision: 100471

Added:
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterBean.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterHome.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterLocal.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/unit/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/unit/LegacyCreateTestCase.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/unit/Secured21ViewTestCase.java
Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Container.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/pool/AbstractPool.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
   projects/ejb3/trunk/core/src/main/resources/ejb3-interceptors-aop.xml
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/AbstractEJB3TestCase.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/unit/PassivateContextTestCase.java
Log:
EJBTHREE-1995: invoke init through HomeCallbackStack

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Container.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Container.java	2010-02-05 08:33:18 UTC (rev 100470)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Container.java	2010-02-05 09:00:54 UTC (rev 100471)
@@ -81,7 +81,7 @@
 
    void invokePrePassivate(BeanContext beanContext);
 
-   void invokeInit(Object bean, Class[] initTypes, Object[] initValues);
+   //void invokeInit(Object bean, Class[] initTypes, Object[] initValues);
 
    BeanContext<?> peekContext();
    

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java	2010-02-05 08:33:18 UTC (rev 100470)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java	2010-02-05 09:00:54 UTC (rev 100471)
@@ -1196,11 +1196,13 @@
       throw new RuntimeException("PrePassivate not implemented for container");
    }
 
+   /*
    public void invokeInit(Object bean, Class[] initParameterTypes,
                           Object[] initParameterValues)
    {
       // do nothing, only useful on a stateful session bean
    }
+   */
 
    public static final String MANAGED_ENTITY_MANAGER_FACTORY = "ManagedEntityManagerFactory";
 

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/pool/AbstractPool.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/pool/AbstractPool.java	2010-02-05 08:33:18 UTC (rev 100470)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/pool/AbstractPool.java	2010-02-05 09:00:54 UTC (rev 100471)
@@ -92,8 +92,7 @@
 
       container.invokePostConstruct(ctx, initValues);
 
-      //TODO This needs to be reimplemented as replacement for create() on home interface
-      container.invokeInit(ctx.getInstance(), initTypes, initValues);
+      // the init method only applies to stateful session beans
 
       ++createCount;
 

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java	2010-02-05 08:33:18 UTC (rev 100470)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java	2010-02-05 09:00:54 UTC (rev 100471)
@@ -21,43 +21,19 @@
  */
 package org.jboss.ejb3.stateful;
 
-import java.io.Serializable;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.rmi.RemoteException;
-import java.util.Hashtable;
-import java.util.Map;
-
-import javax.ejb.EJBHome;
-import javax.ejb.EJBLocalObject;
-import javax.ejb.EJBObject;
-import javax.ejb.Handle;
-import javax.ejb.Init;
-import javax.ejb.NoSuchEJBException;
-import javax.ejb.NoSuchObjectLocalException;
-import javax.ejb.PostActivate;
-import javax.ejb.PrePassivate;
-import javax.ejb.RemoteHome;
-import javax.ejb.RemoveException;
-import javax.ejb.TimerService;
-
 import org.jboss.aop.Advisor;
 import org.jboss.aop.Domain;
 import org.jboss.aop.MethodInfo;
+import org.jboss.aop.advice.AdviceStack;
+import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.InvocationResponse;
+import org.jboss.aop.metadata.SimpleMetaData;
 import org.jboss.aop.util.MethodHashing;
 import org.jboss.aop.util.PayloadKey;
 import org.jboss.ejb3.BeanContext;
 import org.jboss.ejb3.Ejb3Deployment;
-import org.jboss.ejb3.annotation.Cache;
-import org.jboss.ejb3.annotation.CacheConfig;
-import org.jboss.ejb3.annotation.Clustered;
-import org.jboss.ejb3.annotation.LocalBinding;
-import org.jboss.ejb3.annotation.RemoteBinding;
-import org.jboss.ejb3.annotation.RemoteHomeBinding;
+import org.jboss.ejb3.annotation.*;
 import org.jboss.ejb3.cache.CacheFactoryRegistry;
 import org.jboss.ejb3.cache.Ejb3CacheFactory;
 import org.jboss.ejb3.cache.StatefulCache;
@@ -91,6 +67,17 @@
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
 import org.jboss.util.NotImplementedException;
 
+import javax.ejb.*;
+import java.io.Serializable;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.rmi.RemoteException;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.Map;
+
 /**
  * Comment
  *
@@ -121,6 +108,9 @@
       this.sessionFactory = this;
    }
 
+   /**
+    * @see org.jboss.ejb3.cache.StatefulObjectFactory#create(Class[], Object[]) 
+    */
    public StatefulBeanContext create(Class<?>[] initTypes, Object[] initValues)
    {
       StatefulBeanContext sfctx = (StatefulBeanContext) createBeanContext();
@@ -149,11 +139,8 @@
          sfctx.popContainedIn();
       }
 
-      invokePostConstruct(sfctx, initValues);
+      invokePostConstruct(sfctx);
 
-      //TODO This needs to be reimplemented as replacement for create() on home interface
-      invokeInit(sfctx.getInstance(), initTypes, initValues);
-
       return sfctx;
    }
 
@@ -326,8 +313,6 @@
 
    /**
     * Performs a synchronous or asynchronous local invocation
-    *
-    * @param provider If null a synchronous invocation, otherwise an asynchronous
     */
    public Object localInvoke(Object id, Method method, Object[] args) throws Throwable
    {
@@ -642,6 +627,26 @@
       }
    }
 
+   private Method findInitMethod(Class<?> cls, Class<?> parameterTypes[])
+   {
+      if(cls == null || cls.equals(Object.class))
+         return null;
+      
+      // will fail comparison in Arrays.equals
+      assert parameterTypes != null : "parameterTypes is null";
+
+      for(Method m : cls.getDeclaredMethods())
+      {
+         if(getAnnotation(Init.class, m) == null)
+            continue;
+
+         if(Arrays.equals(m.getParameterTypes(), parameterTypes))
+            return m;
+      }
+
+      return findInitMethod(cls.getSuperclass(), parameterTypes);
+   }
+
    public TimerService getTimerService()
    {
       throw new UnsupportedOperationException("stateful bean doesn't support TimerService (EJB3 18.2#2)");
@@ -694,125 +699,58 @@
    }
    */
 
-   public void invokeInit(Object bean, Class[] initParameterTypes, Object[] initParameterValues)
+   private Invocation invokeInit(SimpleMetaData metaData, Method createMethod, Serializable sessionId, Class<?>[] initParameterTypes, final Object[] initParameterValues) throws Exception
    {
-      invokeInit(bean, bean.getClass(), initParameterTypes, initParameterValues);
-   }
-
-   private void invokeInit(Object bean, Class<?> cls, Class<?>[] initParameterTypes, Object[] initParameterValues)
-   {
-      Class<?> superclass = cls.getSuperclass();
-      if (superclass != null)
-         invokeInit(bean, superclass, initParameterTypes, initParameterValues);
-      int numParameters = 0;
-      if (initParameterTypes != null)
-         numParameters = initParameterTypes.length;
-      try
+      // TODO: optimize
+      Method initMethod = findInitMethod(getBeanClass(), initParameterTypes);
+      if(initMethod == null)
       {
-         for (Method method : cls.getDeclaredMethods())
-         {
-            if (numParameters != method.getParameterTypes().length)
-               continue;
-
-            if ((method.getAnnotation(Init.class) != null) || (resolveAnnotation(method, Init.class) != null))
-            {
-               if (initParameterTypes != null)
-               {
-                  Object[] parameters = getInitParameters(method, initParameterTypes, initParameterValues);
-
-                  if (parameters != null)
-                     method.invoke(bean, parameters);
-               }
-               else
-               {
-                  method.invoke(bean);
-               }
-            }
-         }
+         log.warn("EJBTHREE-1995: EJB 3.0 4.3.10.1: no matching init method found for " + createMethod);
       }
-      catch (Exception e)
+      else
       {
-         throw new RuntimeException(e);
+         initMethod.setAccessible(true);
       }
-   }
 
-   protected Object[] getInitParameters(Method method, Class[] initParameterTypes, Object[] initParameterValues)
-   {
-      if (method.getParameterTypes().length == initParameterTypes.length)
+      AdviceStack stack = getAdvisor().getManager().getAdviceStack("HomeCallbackStack");
+      Interceptor interceptors[];
+      if(stack == null)
       {
-         for (int i = 0; i < initParameterTypes.length; ++i)
-         {
-            Class formal = method.getParameterTypes()[i];
-            Class actual = initParameterTypes[i];
-            if (!isMethodInvocationConvertible(formal, actual == null ? null : actual))
-               return null;
-         }
-         return initParameterValues;
+         throw new IllegalStateException("EJBTHREE-1995: " + getAdvisor().getManager().getManagerFQN() + " does not define a HomeCallbackStack");
       }
-      return null;
-   }
+      else
+      {
+         // we could do a joinpoint, but why bother
+         interceptors = stack.createInterceptors(getAdvisor(), null);
+      }
 
-   /**
-    * Determines whether a type represented by a class object is convertible to
-    * another type represented by a class object using a method invocation
-    * conversion, treating object types of primitive types as if they were
-    * primitive types (that is, a Boolean actual parameter type matches boolean
-    * primitive formal type). This behavior is because this method is used to
-    * determine applicable methods for an actual parameter list, and primitive
-    * types are represented by their object duals in reflective method calls.
-    *
-    * @param formal the formal parameter type to which the actual parameter type
-    *               should be convertible
-    * @param actual the actual parameter type.
-    * @return true if either formal type is assignable from actual type, or
-    *         formal is a primitive type and actual is its corresponding object
-    *         type or an object type of a primitive type that can be converted
-    *         to the formal type.
-    */
-   private static boolean isMethodInvocationConvertible(Class formal, Class actual)
-   {
-      /*
-       * if it's a null, it means the arg was null
-       */
-      if (actual == null && !formal.isPrimitive())
+      StatefulContainerInvocation invocation = new StatefulContainerInvocation(interceptors, 0L, initMethod, initMethod, getAdvisor(), sessionId);
+      invocation.setArguments(initParameterValues);
+      if(metaData != null)
+         invocation.setMetaData(metaData);
+
+      // for now we'll only complain and not error
+      if(initMethod == null)
+         return invocation;
+
+      try
       {
-         return true;
+         invocation.invokeNext();
       }
-      /*
-       * Check for identity or widening reference conversion
-       */
-      if (actual != null && formal.isAssignableFrom(actual))
+      catch(Error e)
       {
-         return true;
+         throw e;
       }
-      /*
-       * Check for boxing with widening primitive conversion. Note that actual
-       * parameters are never primitives.
-       */
-      if (formal.isPrimitive())
+      catch(RuntimeException e)
       {
-         if (formal == Boolean.TYPE && actual == Boolean.class)
-            return true;
-         if (formal == Character.TYPE && actual == Character.class)
-            return true;
-         if (formal == Byte.TYPE && actual == Byte.class)
-            return true;
-         if (formal == Short.TYPE && (actual == Short.class || actual == Byte.class))
-            return true;
-         if (formal == Integer.TYPE && (actual == Integer.class || actual == Short.class || actual == Byte.class))
-            return true;
-         if (formal == Long.TYPE
-               && (actual == Long.class || actual == Integer.class || actual == Short.class || actual == Byte.class))
-            return true;
-         if (formal == Float.TYPE
-               && (actual == Float.class || actual == Long.class || actual == Integer.class || actual == Short.class || actual == Byte.class))
-            return true;
-         if (formal == Double.TYPE
-               && (actual == Double.class || actual == Float.class || actual == Long.class || actual == Integer.class
-                     || actual == Short.class || actual == Byte.class))
-            return true;
+         throw e;
       }
-      return false;
+      catch(Throwable t)
+      {
+         throw new RuntimeException(t);
+      }
+
+      return invocation;
    }
 
    private Object invokeEJBLocalObjectMethod(Object id, MethodInfo info, Object[] args) throws Exception
@@ -984,7 +922,9 @@
       }
 
       Serializable sessionId = createSession(method.getParameterTypes(), args);
-      
+
+      invokeInit(null, method, sessionId, method.getParameterTypes(), args);
+
       // Allow override of the remote proxy
       if(!isLocal)
       {
@@ -1015,6 +955,8 @@
       Method unadvisedMethod = info.getUnadvisedMethod();
       if (unadvisedMethod.getName().startsWith("create"))
       {
+         Serializable sessionId = createSession();
+         
          Class<?>[] initParameterTypes =
          {};
          Object[] initParameterValues =
@@ -1025,9 +967,8 @@
             initParameterValues = statefulInvocation.getArguments();
          }
 
-         StatefulSessionContainerMethodInvocation newStatefulInvocation = buildNewInvocation(info, statefulInvocation,
-               initParameterTypes, initParameterValues);
-
+         Invocation invocation = invokeInit(statefulInvocation.getMetaData(), unadvisedMethod, sessionId, initParameterTypes, initParameterValues);
+         
          // Get JNDI Registrar
          JndiSessionRegistrarBase sfsbJndiRegistrar = this.getJndiRegistrar();
 
@@ -1048,12 +989,10 @@
                StatefulSessionProxyFactory.class);
 
          // Create a new EJB2.x Proxy
-         Object proxy = proxyFactory.createProxyEjb2x((Serializable) newStatefulInvocation.getSessionId());
+         Object proxy = proxyFactory.createProxyEjb2x(sessionId);
 
-         InvocationResponse response = marshallResponse(statefulInvocation, proxy, newStatefulInvocation
-               .getResponseContextInfo());
-         if (newStatefulInvocation.getSessionId() != null)
-            response.addAttachment(StatefulConstants.NEW_ID, newStatefulInvocation.getSessionId());
+         InvocationResponse response = marshallResponse(statefulInvocation, proxy, invocation.getResponseContextInfo());
+         response.addAttachment(StatefulConstants.NEW_ID, sessionId);
          return response;
       }
       else if (unadvisedMethod.getName().equals("remove"))
@@ -1222,7 +1161,7 @@
       }
    }
 
-   private StatefulSessionContainerMethodInvocation buildNewInvocation(MethodInfo info,
+   private StatefulSessionContainerMethodInvocation _buildNewInvocation(MethodInfo info,
          StatefulRemoteInvocation statefulInvocation, Class<?>[] initParameterTypes, Object[] initParameterValues)
    {
       StatefulSessionContainerMethodInvocation newStatefulInvocation = null;
@@ -1234,10 +1173,7 @@
 
       try
       {
-         if (initParameterTypes.length > 0)
-            ctx = getCache().create(initParameterTypes, initParameterValues);
-         else
-            ctx = getCache().create(null, null);
+         ctx = getCache().create(initParameterTypes, initParameterValues);
       }
       finally
       {

Modified: projects/ejb3/trunk/core/src/main/resources/ejb3-interceptors-aop.xml
===================================================================
--- projects/ejb3/trunk/core/src/main/resources/ejb3-interceptors-aop.xml	2010-02-05 08:33:18 UTC (rev 100470)
+++ projects/ejb3/trunk/core/src/main/resources/ejb3-interceptors-aop.xml	2010-02-05 09:00:54 UTC (rev 100471)
@@ -201,6 +201,14 @@
    </domain>
 
    <domain name="Base Stateful Bean" extends="Intercepted Bean" inheritBindings="true">
+      <!-- EJBTHREE-1995: establish a security context during init -->
+      <stack name="HomeCallbackStack">
+         <interceptor-ref name="org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor"/>
+         <!-- advice name="setup" aspect="InvocationContextInterceptor"/ -->
+         <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulInstanceInterceptor"/>
+      </stack>
+
       <bind pointcut="execution(public * *->*(..))">
          <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
          <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>

Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/AbstractEJB3TestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/AbstractEJB3TestCase.java	2010-02-05 08:33:18 UTC (rev 100470)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/AbstractEJB3TestCase.java	2010-02-05 09:00:54 UTC (rev 100471)
@@ -134,6 +134,8 @@
    @BeforeClass
    public static void beforeClass() throws Exception
    {
+      System.setProperty("xb.builder.useUnorderedSequence", "true");
+      
       // FIXME: weirdness in InitialContextFactory (see EJBTHREE-1097)
       InitialContextFactory.close(null, null);
 

Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/unit/PassivateContextTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/unit/PassivateContextTestCase.java	2010-02-05 08:33:18 UTC (rev 100470)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1846/unit/PassivateContextTestCase.java	2010-02-05 09:00:54 UTC (rev 100471)
@@ -21,12 +21,6 @@
  */
 package org.jboss.ejb3.core.test.ejbthree1846.unit;
 
-import static org.junit.Assert.assertEquals;
-
-import java.io.Serializable;
-import java.lang.reflect.Method;
-import java.util.concurrent.TimeUnit;
-
 import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
 import org.jboss.ejb3.core.test.ejbthree1846.MyStateful;
 import org.jboss.ejb3.core.test.ejbthree1846.MyStatefulBean;
@@ -35,7 +29,15 @@
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+
 /**
+ * Make sure an injected SessionContext is still valid after passivation.
+ * 
  * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
  * @version $Revision: $
  */
@@ -61,7 +63,7 @@
    @Test
    public void test1() throws Throwable
    {
-      Serializable id = container.getSessionFactory().createSession(null, null);
+      Serializable id = container.getSessionFactory().createSession(new Class[] { }, new Object[] { });
       
       Method method = MyStateful.class.getMethod("getBusinessObject");
       MyStateful bean = (MyStateful) container.invoke(id, MyStateful.class, method, null);

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterBean.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterBean.java	2010-02-05 09:00:54 UTC (rev 100471)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1995;
+
+import javax.ejb.*;
+import java.rmi.RemoteException;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Stateful
+ at LocalHome(LegacyGreeterHome.class)
+public class LegacyGreeterBean implements SessionBean
+{
+   private SessionContext ctx;
+   private String name;
+
+   public void ejbActivate() throws EJBException, RemoteException
+   {
+
+   }
+
+   public void ejbCreate(String name) throws CreateException, RemoteException
+   {
+      this.name = name;
+   }
+
+   public void ejbPassivate() throws EJBException, RemoteException
+   {
+
+   }
+   
+   public void ejbRemove() throws EJBException, RemoteException
+   {
+      
+   }
+
+   public String sayHi()
+   {
+      return "Hi " + name;
+   }
+
+   public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException
+   {
+      this.ctx = ctx;
+   }
+}


Property changes on: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterBean.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterHome.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterHome.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterHome.java	2010-02-05 09:00:54 UTC (rev 100471)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1995;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBLocalHome;
+import java.rmi.RemoteException;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public interface LegacyGreeterHome extends EJBLocalHome
+{
+   LegacyGreeterLocal create(String name) throws CreateException, RemoteException;
+}


Property changes on: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterHome.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterLocal.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterLocal.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterLocal.java	2010-02-05 09:00:54 UTC (rev 100471)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1995;
+
+import javax.ejb.EJBLocalObject;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public interface LegacyGreeterLocal extends EJBLocalObject
+{
+   String sayHi();
+}


Property changes on: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/LegacyGreeterLocal.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/unit/LegacyCreateTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/unit/LegacyCreateTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/unit/LegacyCreateTestCase.java	2010-02-05 09:00:54 UTC (rev 100471)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1995.unit;
+
+import org.jboss.ejb3.annotation.impl.InitImpl;
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.core.test.ejbthree1995.LegacyGreeterBean;
+import org.jboss.ejb3.core.test.ejbthree1995.LegacyGreeterHome;
+import org.jboss.ejb3.core.test.ejbthree1995.LegacyGreeterLocal;
+import org.jboss.ejb3.session.SessionContainer;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.ejb.Init;
+import java.lang.reflect.Method;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Make sure we call ejbCreate on a session bean implementing SessionBean.
+ * 
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class LegacyCreateTestCase extends AbstractEJB3TestCase
+{
+   @BeforeClass
+   public static void beforeClass() throws Exception
+   {
+      AbstractEJB3TestCase.beforeClass();
+
+      SessionContainer container = deploySessionEjb(LegacyGreeterBean.class);
+
+      // normally done in Ejb3DescriptorHandler.addEjb21Annotations
+      Method method = LegacyGreeterBean.class.getMethod("ejbCreate", String.class);
+      container.getAnnotations().addAnnotation(method, Init.class, new InitImpl());
+   }
+
+   @Test
+   public void testCreate() throws Exception
+   {
+      LegacyGreeterHome home = lookup("LegacyGreeterBean/localHome", LegacyGreeterHome.class);
+
+      LegacyGreeterLocal bean = home.create("testCreate");
+
+      String result = bean.sayHi();
+
+      assertEquals("Hi testCreate", result);
+   }
+}


Property changes on: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/unit/LegacyCreateTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/unit/Secured21ViewTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/unit/Secured21ViewTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/unit/Secured21ViewTestCase.java	2010-02-05 09:00:54 UTC (rev 100471)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1995.unit;
+
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.core.test.ejbthree1995.SecuredGreeter21Bean;
+import org.jboss.ejb3.core.test.ejbthree1995.SecuredGreeter21Remote;
+import org.jboss.ejb3.core.test.ejbthree1995.SecuredGreeter21RemoteHome;
+import org.jboss.ejb3.session.SessionContainer;
+import org.jboss.security.*;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.security.auth.Subject;
+import java.security.Principal;
+
+import static junit.framework.Assert.assertEquals;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class Secured21ViewTestCase extends AbstractEJB3TestCase
+{
+   @After
+   public void after()
+   {
+      SecurityContextAssociation.setSecurityContext(null);
+   }
+
+   @BeforeClass
+   public static void beforeClass() throws Exception
+   {
+      AbstractEJB3TestCase.beforeClass();
+
+      deploy("securitymanager-beans.xml");
+
+      SessionContainer container = deploySessionEjb(SecuredGreeter21Bean.class);
+      container.setJaccContextId("test");
+   }
+
+   private SecurityContext login(String name, Object credential) throws Exception
+   {
+      SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
+      SecurityContextUtil util = sc.getUtil();
+      Principal principal = new SimplePrincipal(name);
+      Subject subject = new Subject();
+      subject.getPrincipals().add(principal);
+      subject.getPrivateCredentials().add(credential);
+      util.createSubjectInfo(principal, credential, subject);
+      SecurityContextAssociation.setSecurityContext(sc);
+      return sc;
+   }
+
+   @Test
+   public void testAnonymous() throws Exception
+   {
+      SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
+      SecurityContextAssociation.setSecurityContext(sc);
+            
+      SecuredGreeter21RemoteHome home = lookup("SecuredGreeter21Bean/home", SecuredGreeter21RemoteHome.class);
+      SecuredGreeter21Remote bean = home.create("testAnonymous");
+      String result = bean.sayHi();
+
+      assertEquals("Hi testAnonymous (anonymous)", result);
+   }
+
+   @Test
+   public void testSomebody() throws Exception
+   {
+      login("somebody", null);
+      
+      SecuredGreeter21RemoteHome home = lookup("SecuredGreeter21Bean/home", SecuredGreeter21RemoteHome.class);
+      SecuredGreeter21Remote bean = home.create("testSomebody");
+      String result = bean.sayHi();
+
+      assertEquals("Hi testSomebody (somebody)", result);
+   }
+}


Property changes on: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1995/unit/Secured21ViewTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list