[Jboss-cvs] JBossAS SVN: r54985 - in trunk: aspects/src/main/org/jboss/aspects/security ejb3 ejb3/src/main/org/jboss/ejb3 ejb3/src/main/org/jboss/ejb3/embedded ejb3/src/main/org/jboss/ejb3/mdb ejb3/src/main/org/jboss/ejb3/security ejb3/src/resources ejb3/src/resources/test/standalone/standard ejb3/src/test/org/jboss/ejb3/test/mdb/unit ejb3/src/test/org/jboss/ejb3/test/security/unit ejb3/src/test/org/jboss/ejb3/test/standalone/unit

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 1 13:38:52 EDT 2006


Author: bdecoste
Date: 2006-08-01 13:38:44 -0400 (Tue, 01 Aug 2006)
New Revision: 54985

Modified:
   trunk/aspects/src/main/org/jboss/aspects/security/SecurityContext.java
   trunk/ejb3/build-test.xml
   trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java
   trunk/ejb3/src/main/org/jboss/ejb3/InitialContextFactory.java
   trunk/ejb3/src/main/org/jboss/ejb3/Pool.java
   trunk/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
   trunk/ejb3/src/main/org/jboss/ejb3/embedded/EJB3StandaloneDeployer.java
   trunk/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/security/Ejb3AuthenticationInterceptor.java
   trunk/ejb3/src/resources/ejb3-interceptors-aop.xml
   trunk/ejb3/src/resources/test/standalone/standard/testjms.xml
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/MDBUnitTestCase.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/security/unit/EJBSpecUnitTestCase.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/standalone/unit/StandardTestCase.java
Log:
implemented <unauthenticated-principal>, modified MDB and Consumer instance pooling to support MDB singletons

Modified: trunk/aspects/src/main/org/jboss/aspects/security/SecurityContext.java
===================================================================
--- trunk/aspects/src/main/org/jboss/aspects/security/SecurityContext.java	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/aspects/src/main/org/jboss/aspects/security/SecurityContext.java	2006-08-01 17:38:44 UTC (rev 54985)
@@ -38,6 +38,11 @@
 public class SecurityContext
 {
    protected static ThreadLocal currentDomain = new ThreadLocal();
+   
+   public static ThreadLocal getCurrentDomain()
+   {
+      return currentDomain;
+   }
 
    /**
     * Get the caller's principal

Modified: trunk/ejb3/build-test.xml
===================================================================
--- trunk/ejb3/build-test.xml	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/build-test.xml	2006-08-01 17:38:44 UTC (rev 54985)
@@ -1063,6 +1063,24 @@
          </fileset>
       </jar>
    </target>
+   
+   <target name="unauthenticatedprincipal"
+      description="Builds all jar files."
+      depends="compile-classes">
+      
+      <mkdir dir="${build.lib}"/>
+      
+      <jar jarfile="${build.lib}/unauthenticatedprincipal.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/unauthenticatedprincipal/*.class"/>
+         </fileset>
+         <fileset dir="${resources}/test/unauthenticatedprincipal">
+            <include name="META-INF/*.xml"/>
+            <include name="users.properties"/>
+            <include name="roles.properties"/>
+         </fileset>
+      </jar>
+   </target>
 
    <target name="reference21_30"
       description="Builds all jar files."
@@ -2493,7 +2511,7 @@
       </jar>
    </target>
    
-   <target name="jars" depends="clusteredservice, invoker, classloader, circulardependency, jsp, timerdependency, servicedependency, servlet, stateless14, webservices, ejbthree440, ejbthree454, aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, securitydomain, enventry, jms/managed, naming, bmt, jca/inflowmdb, pool, jms, security, reference21_30, factory, dd/web, txexceptions, exception, dd/override, stateless, standalone-jar, dd/mdb, bank, dd, longlived, xmlcfg, hbm, pkg, regressionHHH275, entityexception, asynchronous, consumer, clusteredentity, secondary, stateful, service, lob,cache,initial,timer,benchmark,entity,joininheritance, singletable, tableperclass, dependent, mdb, manytomany, regression, composite, composite2, entitycallback, relationships, ssl, ssladvanced, clusteredsession, strictpool, jacc, localcall, interceptors, interceptors2, clientinterceptor"/>
+   <target name="jars" depends="unauthenticatedprincipal, clusteredservice, invoker, classloader, circulardependency, jsp, timerdependency, servicedependency, servlet, stateless14, webservices, ejbthree440, ejbthree454, aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, securitydomain, enventry, jms/managed, naming, bmt, jca/inflowmdb, pool, jms, security, reference21_30, factory, dd/web, txexceptions, exception, dd/override, stateless, standalone-jar, dd/mdb, bank, dd, longlived, xmlcfg, hbm, pkg, regressionHHH275, entityexception, asynchronous, consumer, clusteredentity, secondary, stateful, service, lob,cache,initial,timer,benchmark,entity,joininheritance, singletable, tableperclass, dependent, mdb, manytomany, regression, composite, composite2, entitycallback, relationships, ssl, ssladvanced, clusteredsession, strictpool, jacc, localcall, interceptors, interceptors2, clientinterceptor"/>
 
    <target name="test" depends="init" if="test"
       description="Execute all tests in the given test directory.">
@@ -2573,6 +2591,7 @@
             <path refid="jboss.common.classpath"/>
             <path refid="jboss.aop50.classpath"/>
             <path refid="jboss.aspects.classpath"/>
+            <path refid="jboss.jbossxb.classpath"/>
          	<!-- for Corba -->
          	<path refid="jacorb.jacorb.classpath"/>
          	<path refid="apache.avalon.classpath"/>
@@ -3110,6 +3129,9 @@
          <param name="test" value="mail"/>
       </antcall>
       <antcall target="test" inheritRefs="true">
+         <param name="test" value="unauthenticatedprincipal"/>
+      </antcall>
+      <antcall target="test" inheritRefs="true">
          <param name="test" value="securitydomain"/>
       </antcall>
       <antcall target="test" inheritRefs="true">

Modified: trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java	2006-08-01 17:38:44 UTC (rev 54985)
@@ -52,6 +52,10 @@
       this.contextClass = contextClass;
       this.container = container;
    }
+   
+   public void setMaxSize(int maxSize)
+   {
+   }
 
    protected BeanContext create()
    {

Modified: trunk/ejb3/src/main/org/jboss/ejb3/InitialContextFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/InitialContextFactory.java	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/main/org/jboss/ejb3/InitialContextFactory.java	2006-08-01 17:38:44 UTC (rev 54985)
@@ -23,6 +23,7 @@
 
 import java.util.Properties;
 
+import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
@@ -33,14 +34,23 @@
 public class InitialContextFactory
 {
    private static Properties props = null;
-   private static InitialContext jndiContext = null;
+   private static Properties securityProperties = null;
    
    public static InitialContext getInitialContext() throws NamingException
    {
-      if (jndiContext == null)
+      InitialContext jndiContext;
+      
+      if (props == null)
+         jndiContext = new InitialContext();
+      else
       {
-         if (props == null)
-            jndiContext = new InitialContext();
+         if (securityProperties != null)
+         {
+            Properties combinedProps = new Properties();
+            combinedProps.putAll(props);
+            combinedProps.putAll(securityProperties);
+            jndiContext = new InitialContext(combinedProps);
+         }
          else
             jndiContext = new InitialContext(props);
       }
@@ -53,5 +63,16 @@
       props = properties;
    }
    
+   public static void setSecurity(String user, String password)
+   {
+      if (props != null)
+      {
+         securityProperties = new Properties();
+         securityProperties.put(Context.SECURITY_PRINCIPAL, user);
+         securityProperties.put(Context.SECURITY_CREDENTIALS, password);
+         securityProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory");
+      }
+   }
+   
 }
 

Modified: trunk/ejb3/src/main/org/jboss/ejb3/Pool.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Pool.java	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Pool.java	2006-08-01 17:38:44 UTC (rev 54985)
@@ -60,4 +60,6 @@
    public void setInjectors(Injector[] injectors);
 
    void initialize(Container container, Class contextClass, Class beanClass, int maxSize, long timeout);
+
+   void setMaxSize(int maxSize);
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java	2006-08-01 17:38:44 UTC (rev 54985)
@@ -77,6 +77,12 @@
       this.strictMaxSize = new FIFOSemaphore(maxSize);
       this.strictTimeout = timeout;
    }
+   
+   public void setMaxSize(int maxSize)
+   {
+      this.maxSize = maxSize;
+      this.strictMaxSize = new FIFOSemaphore(maxSize);
+   }
 
    /**
     * Get an instance without identity.

Modified: trunk/ejb3/src/main/org/jboss/ejb3/embedded/EJB3StandaloneDeployer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/embedded/EJB3StandaloneDeployer.java	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/main/org/jboss/ejb3/embedded/EJB3StandaloneDeployer.java	2006-08-01 17:38:44 UTC (rev 54985)
@@ -437,7 +437,6 @@
             DeployerUnit du = new DeployerUnit(classLoader, archive, defaultPersistenceProperties, jndiProperties);
             EJB3StandaloneDeployment deployment = new EJB3StandaloneDeployment(du, kernel, mbeanServer);
             deployments.add(deployment);
-            System.out.println("!! archive " + archive);
             deployment.create();
          }
       }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java	2006-08-01 17:38:44 UTC (rev 54985)
@@ -300,7 +300,6 @@
 
    protected void registerProducers() throws Exception
    {
-      log.info("!!! registerProducers " + getDestination());
       Destination dest = (Destination) getInitialContext().lookup(getDestination());
       Class[] producers = getProducerInterfaces(this);
       MessageProperties props = (MessageProperties) resolveAnnotation(MessageProperties.class);

Modified: trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java	2006-08-01 17:38:44 UTC (rev 54985)
@@ -21,20 +21,16 @@
 */
 package org.jboss.ejb3.mdb;
 
-import org.jboss.annotation.ejb.AcknowledgementMode;
-import org.jboss.annotation.ejb.DefaultActivationSpecs;
 import org.jboss.annotation.ejb.ResourceAdapter;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.MethodInfo;
 import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.util.MethodHashing;
 import org.jboss.deployment.DeploymentException;
 import org.jboss.ejb3.*;
 import org.jboss.ejb3.mdb.inflow.JBossMessageEndpointFactory;
 import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
 import org.jboss.ejb3.timerservice.TimedObjectInvoker;
 import org.jboss.ejb3.timerservice.TimerServiceFactory;
-import org.jboss.jms.ConnectionFactoryHelper;
 import org.jboss.jms.jndi.JMSProviderAdapter;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ActivationConfigPropertyMetaData;
@@ -43,7 +39,6 @@
 import javax.ejb.Timer;
 import javax.jms.*;
 import javax.jms.Queue;
-import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import javax.naming.Context;
@@ -148,7 +143,7 @@
       super.start();
 
       populateActivationSpec();
-      
+         
       innerStart();
 
       timerService = TimerServiceFactory.createTimerService(this.getObjectName(), this);
@@ -296,12 +291,24 @@
    }
    
    // ********* JMS Specific
-   
    protected static final String JMS_ADAPTOR = "jms-ra.rar";
    protected static final String DESTINATION = "destination";
    protected static final String DESTINATION_TYPE = "destinationType";
    protected static final String PROVIDER_ADAPTER_JNDI = "providerAdapterJNDI";
+   protected static final String MAX_SESSION = "maxSession";
    
+   public void initializePool() throws Exception
+   {
+     super.initializePool();
+     
+     String maxSession = getMaxSession();
+     if (maxSession != null)
+     {
+        log.info("!!! setting max pool size " + this.getEjbName() + " " + Integer.parseInt(maxSession));
+        pool.setMaxSize(Integer.parseInt(maxSession));
+     }
+   }
+   
    protected String getProviderAdapterJNDI()
    {
       ActivationConfigPropertyMetaData property = (ActivationConfigPropertyMetaData)getActivationConfigProperties().get(PROVIDER_ADAPTER_JNDI);
@@ -310,6 +317,14 @@
       return "java:/DefaultJMSProvider";
    }
    
+   protected String getMaxSession()
+   {
+      ActivationConfigPropertyMetaData property = (ActivationConfigPropertyMetaData)getActivationConfigProperties().get(MAX_SESSION);
+      if (property != null)
+         return property.getValue();
+      return null;
+   }
+   
    protected String getDestination()
    {
       ActivationConfigPropertyMetaData property = (ActivationConfigPropertyMetaData)getActivationConfigProperties().get(DESTINATION);
@@ -598,4 +613,4 @@
 
       return destType;
    }
-}
+}
\ No newline at end of file

Modified: trunk/ejb3/src/main/org/jboss/ejb3/security/Ejb3AuthenticationInterceptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/security/Ejb3AuthenticationInterceptor.java	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/main/org/jboss/ejb3/security/Ejb3AuthenticationInterceptor.java	2006-08-01 17:38:44 UTC (rev 54985)
@@ -35,8 +35,10 @@
 import org.jboss.logging.Logger;
 
 import org.jboss.annotation.security.SecurityDomain;
+import org.jboss.aop.joinpoint.MethodInvocation;
 
 import org.jboss.aspects.security.AuthenticationInterceptor;
+import org.jboss.aspects.security.SecurityContext;
 import org.jboss.security.AuthenticationManager;
 import org.jboss.security.RealmMapping;
 import org.jboss.security.RunAsIdentity;
@@ -68,5 +70,35 @@
       throw new EJBAccessException("Authentication failure", gse);
    }
 
+   public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable
+   {
+      MethodInvocation mi = (MethodInvocation)invocation;
+      SecurityDomain domain = (SecurityDomain)container.resolveAnnotation(SecurityDomain.class);
+      
+      if (domain != null && domain.unauthenticatedPrincipal() != null)
+      {
+         Principal principal = (Principal)invocation.getMetaData("security", "principal");
+         if (principal == null)
+            principal = SecurityAssociation.getPrincipal();
+           
+         if (principal == null)
+         {
+            invocation.getMetaData().addMetaData("security", "principal", new SimplePrincipal(domain.unauthenticatedPrincipal()));
+            
+            Object oldDomain = SecurityContext.getCurrentDomain().get();
+            
+            try
+            {
+               SecurityContext.getCurrentDomain().set(authenticationManager);
+               return invocation.invokeNext();
+            }
+            finally
+            {
+               SecurityContext.getCurrentDomain().set(oldDomain);
+            }
+         }
+      }
 
+      return super.invoke(invocation);
+   }
 }

Modified: trunk/ejb3/src/resources/ejb3-interceptors-aop.xml
===================================================================
--- trunk/ejb3/src/resources/ejb3-interceptors-aop.xml	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/resources/ejb3-interceptors-aop.xml	2006-08-01 17:38:44 UTC (rev 54985)
@@ -281,10 +281,10 @@
          <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
       </bind>
       <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
-         @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
+         @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=30, timeout=10000)
       </annotation>
    </domain>
-
+   
    <domain name="Consumer Bean">
       <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
          <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
@@ -302,7 +302,7 @@
          <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
       </bind>
       <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
-         @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
+         @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=30, timeout=10000)
       </annotation>
    </domain>
 

Modified: trunk/ejb3/src/resources/test/standalone/standard/testjms.xml
===================================================================
--- trunk/ejb3/src/resources/test/standalone/standard/testjms.xml	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/resources/test/standalone/standard/testjms.xml	2006-08-01 17:38:44 UTC (rev 54985)
@@ -1,21 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-            xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
-            xmlns="urn:jboss:bean-deployer">
- 
-   <bean name="jboss.mq.destination:service=Queue,name=defaultedqueuetest" class="org.jboss.mq.kernel.Queue">
-      <property name="destinationManagerPojo"><inject bean="jboss.mq:service=DestinationManager"/></property>
-      <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
-      <property name="destinationName"><value>defaultedmdbtest</value></property>
-    </bean>
+  xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
+  xmlns="urn:jboss:bean-deployer">
   
+  <bean name="jboss.mq.destination:service=Queue,name=defaultedqueuetest" class="org.jboss.mq.kernel.Queue">
+    <property name="destinationManagerPojo"><inject bean="jboss.mq:service=DestinationManager"/></property>
+    <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
+    <property name="destinationName"><value>defaultedmdbtest</value></property>
+  </bean>
+  
   <bean name="jboss.mq.destination:service=Queue,name=overridedefaultedqueuetest" class="org.jboss.mq.kernel.Queue">
     <property name="destinationManagerPojo"><inject bean="jboss.mq:service=DestinationManager"/></property>
     <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
     <property name="destinationName"><value>overridedefaultedmdbtest</value></property>
   </bean>
- 
+  
   <bean name="jboss.mq.destination:service=Queue,name=nondurablequeuetest" class="org.jboss.mq.kernel.Queue">
     <property name="destinationManagerPojo"><inject bean="jboss.mq:service=DestinationManager"/></property>
     <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
@@ -39,6 +39,26 @@
     <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
     <property name="destinationName"><value>mdbtest</value></property>
   </bean>
-
+  
+  <bean name="jboss.mq.destination:service=Queue,name=queuetest" class="org.jboss.mq.kernel.Queue">
+    <property name="destinationManagerPojo"><inject bean="jboss.mq:service=DestinationManager"/></property>
+    <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
+    <property name="destinationName"><value>mdbtest</value></property>
+  </bean>
+  
+  <bean name="jboss.mq.destination:service=Queue,name=expirytest" class="org.jboss.mq.kernel.Queue">
+    <property name="destinationManagerPojo"><inject bean="jboss.mq:service=DestinationManager"/></property>
+    <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
+    <property name="destinationName"><value>expirytest</value></property>
+    <property name="expiryDestination"><value>jboss.mq.destination:service=Queue,name=DLQ</value></property>
+  </bean>
+  
+  <bean name="jboss.mq.destination:service=Queue,name=dlqtest" class="org.jboss.mq.kernel.Queue">
+    <property name="destinationManagerPojo"><inject bean="jboss.mq:service=DestinationManager"/></property>
+    <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
+    <property name="destinationName"><value>dlqtest</value></property>
+    <property name="expiryDestination"><value>jboss.mq.destination:service=Queue,name=DLQ</value></property>
+  </bean>
+  
 </deployment>
 

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/MDBUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/MDBUnitTestCase.java	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/MDBUnitTestCase.java	2006-08-01 17:38:44 UTC (rev 54985)
@@ -1,24 +1,24 @@
 /*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, 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.
-  */
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.test.mdb.unit;
 
 import java.util.Enumeration;
@@ -59,18 +59,16 @@
 
 /**
  * Sample client for the jboss container.
- *
+ * 
  * @author <a href="mailto:bill at burkecentral.com">Bill Burke</a>
  * @version $Id$
  */
-
-public class MDBUnitTestCase
-        extends JBossTestCase
+public class MDBUnitTestCase extends JBossTestCase
 {
-   private static final Logger log = Logger
-   .getLogger(MDBUnitTestCase.class);
+   private static final Logger log = Logger.getLogger(MDBUnitTestCase.class);
 
    static boolean deployed = false;
+
    static int test = 0;
 
    public MDBUnitTestCase(String name)
@@ -79,19 +77,21 @@
       super(name);
 
    }
-   
+
    public void testOverrideQueue() throws Exception
    {
       SecurityAssociation.setPrincipal(new SimplePrincipal("anyone"));
       SecurityAssociation.setCredential("password".toCharArray());
-      
-      TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
+
+      TestStatus status = (TestStatus) getInitialContext().lookup(
+            "TestStatusBean/remote");
       clear(status);
       QueueConnection cnn = null;
       QueueSender sender = null;
       QueueSession session = null;
-      
-      Queue queue = (Queue) getInitialContext().lookup("queue/overridequeuetest");
+
+      Queue queue = (Queue) getInitialContext().lookup(
+            "queue/overridequeuetest");
       QueueConnectionFactory factory = getQueueConnectionFactory();
       cnn = factory.createQueueConnection();
       session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
@@ -106,20 +106,22 @@
       Thread.sleep(5000);
       assertEquals(1, status.overrideQueueFired());
    }
-   
+
    public void testNondurableQueue() throws Exception
    {
       SecurityAssociation.setPrincipal(new SimplePrincipal("anyone"));
       SecurityAssociation.setCredential("password".toCharArray());
-      
-      TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
+
+      TestStatus status = (TestStatus) getInitialContext().lookup(
+            "TestStatusBean/remote");
       clear(status);
       QueueConnection cnn = null;
       QueueSender sender = null;
       QueueSession session = null;
 
-      Queue queue = (Queue) getInitialContext().lookup("queue/nondurablemdbtest");
-      QueueConnectionFactory factory = (QueueConnectionFactory) getInitialContext().lookup("ConnectionFactory");
+      Queue queue = (Queue) getInitialContext().lookup(
+            "queue/nondurablemdbtest");
+      QueueConnectionFactory factory = getQueueConnectionFactory();
       cnn = factory.createQueueConnection();
       session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
 
@@ -135,20 +137,22 @@
       Thread.sleep(2000);
       assertEquals(1, status.nondurableQueueFired());
    }
-   
+
    public void testDefaultedQueue() throws Exception
    {
       SecurityAssociation.setPrincipal(new SimplePrincipal("anyone"));
       SecurityAssociation.setCredential("password".toCharArray());
-      
-      TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
+
+      TestStatus status = (TestStatus) getInitialContext().lookup(
+            "TestStatusBean/remote");
       clear(status);
       QueueConnection cnn = null;
       QueueSender sender = null;
       QueueSession session = null;
 
-      Queue queue = (Queue) getInitialContext().lookup("queue/defaultedmdbtest");
-      QueueConnectionFactory factory = (QueueConnectionFactory) getInitialContext().lookup("ConnectionFactory");
+      Queue queue = (Queue) getInitialContext()
+            .lookup("queue/defaultedmdbtest");
+      QueueConnectionFactory factory = getQueueConnectionFactory();
       cnn = factory.createQueueConnection();
       session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
 
@@ -162,20 +166,22 @@
       Thread.sleep(2000);
       assertEquals(1, status.defaultedQueueFired());
    }
-   
+
    public void testOverrideDefaultedQueue() throws Exception
    {
       SecurityAssociation.setPrincipal(new SimplePrincipal("anyone"));
       SecurityAssociation.setCredential("password".toCharArray());
-      
-      TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
+
+      TestStatus status = (TestStatus) getInitialContext().lookup(
+            "TestStatusBean/remote");
       clear(status);
       QueueConnection cnn = null;
       QueueSender sender = null;
       QueueSession session = null;
 
-      Queue queue = (Queue) getInitialContext().lookup("queue/overridedefaultedmdbtest");
-      QueueConnectionFactory factory = (QueueConnectionFactory) getInitialContext().lookup("ConnectionFactory");
+      Queue queue = (Queue) getInitialContext().lookup(
+            "queue/overridedefaultedmdbtest");
+      QueueConnectionFactory factory = getQueueConnectionFactory();
       cnn = factory.createQueueConnection();
       session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
 
@@ -189,20 +195,20 @@
       Thread.sleep(2000);
       assertEquals(1, status.overrideDefaultedQueueFired());
    }
-   
+
    public void testQueue() throws Exception
    {
-      SecurityAssociation.setPrincipal(new SimplePrincipal("anyone"));
-      SecurityAssociation.setCredential("password".toCharArray());
-      
-      TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
+      setSecurity("anyone", "password");
+
+      TestStatus status = (TestStatus) getInitialContext().lookup(
+            "TestStatusBean/remote");
       clear(status);
       QueueConnection cnn = null;
       QueueSender sender = null;
       QueueSession session = null;
 
       Queue queue = (Queue) getInitialContext().lookup("queue/mdbtest");
-      QueueConnectionFactory factory = (QueueConnectionFactory) getInitialContext().lookup("ConnectionFactory");
+      QueueConnectionFactory factory = getQueueConnectionFactory();
       cnn = factory.createQueueConnection();
       session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
 
@@ -223,10 +229,10 @@
       assertTrue(status.postConstruct());
       assertEquals(5, status.messageCount());
 
-      //TODO: Figure out how to test preDestroy gets invoked
-      //assertTrue(status.preDestroy());
-      
-      Stateless stateless = (Stateless)getInitialContext().lookup("Stateless");
+      // TODO: Figure out how to test preDestroy gets invoked
+      // assertTrue(status.preDestroy());
+
+      Stateless stateless = (Stateless) getInitialContext().lookup("Stateless");
       assertNotNull(stateless);
       String state = stateless.getState();
       assertEquals("Set", state);
@@ -234,14 +240,15 @@
 
    public void testTopic() throws Exception
    {
-      TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
+      TestStatus status = (TestStatus) getInitialContext().lookup(
+            "TestStatusBean/remote");
       clear(status);
       TopicConnection cnn = null;
       MessageProducer sender = null;
       TopicSession session = null;
 
       Topic topic = (Topic) getInitialContext().lookup("topic/mdbtest");
-      TopicConnectionFactory factory = (TopicConnectionFactory) getInitialContext().lookup("ConnectionFactory");
+      TopicConnectionFactory factory = getTopicConnectionFactory();
       cnn = factory.createTopicConnection();
       session = cnn.createTopicSession(false, QueueSession.AUTO_ACKNOWLEDGE);
 
@@ -257,11 +264,12 @@
       assertTrue(status.interceptedTopic());
       assertFalse(status.postConstruct());
       assertFalse(status.preDestroy());
-   } 
-   
+   }
+
    public void testRuntimeException() throws Exception
    {
-      TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
+      TestStatus status = (TestStatus) getInitialContext().lookup(
+            "TestStatusBean/remote");
       clear(status);
       QueueConnection cnn = null;
       QueueSender sender = null;
@@ -282,7 +290,7 @@
       Thread.sleep(2000);
       assertEquals(1, status.bmtQueueRan());
    }
-   
+
    /**
     * Test that expired messages are moved to a separate queue.
     */
@@ -291,20 +299,22 @@
       QueueConnection connection = null;
       QueueSender sender = null;
       QueueSession session = null;
-      
+
       QueueConnectionFactory factory = getQueueConnectionFactory();
       connection = factory.createQueueConnection();
       connection.start();
-      session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
-      
+      session = connection.createQueueSession(false,
+            QueueSession.AUTO_ACKNOWLEDGE);
+
       Queue queue = (Queue) getInitialContext().lookup("queue/expirytest");
       sender = session.createSender(queue);
 
-      Queue dlq = (Queue)getInitialContext().lookup("queue/DLQ");
-      
-      ObjectName dlqName = new ObjectName("jboss.mq.destination:service=Queue,name=DLQ");
+      Queue dlq = (Queue) getInitialContext().lookup("queue/DLQ");
+
+      ObjectName dlqName = new ObjectName(
+            "jboss.mq.destination:service=Queue,name=DLQ");
       getServer().invoke(dlqName, "removeAllMessages", null, null);
-   
+
       long now = System.currentTimeMillis();
 
       TextMessage message = session.createTextMessage();
@@ -312,87 +322,91 @@
       message.setStringProperty("null", null);
       String text = "expire on server";
       message.setText(text);
-      
+
       sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
 
       Thread.sleep(1000);
 
-      assertSize(session, queue,  0);
+      assertSize(session, queue, 0);
       assertSize(session, dlq, 1);
-      
+
       QueueReceiver receiver = session.createReceiver(dlq);
       message = (TextMessage) receiver.receiveNoWait();
       assertNotNull(message);
-      assertEquals("QUEUE.expirytest", message.getStringProperty("JBOSS_ORIG_DESTINATION"));
+      assertEquals("QUEUE.expirytest", message
+            .getStringProperty("JBOSS_ORIG_DESTINATION"));
       assertTrue(message.getLongProperty("JBOSS_ORIG_EXPIRATION") > now);
       assertEquals(0L, message.getJMSExpiration());
       assertEquals(text, message.getText());
       assertEquals("bar", message.getStringProperty("foo"));
       assertNull(message.getStringProperty("null"));
-      
+
       sender.close();
       receiver.close();
 
       session.close();
       connection.close();
    }
-   
+
    public void testDlqMaxResent() throws Exception
    {
       QueueConnection connection = null;
       QueueSender sender = null;
       QueueSession session = null;
-      
+
       QueueConnectionFactory factory = getQueueConnectionFactory();
       connection = factory.createQueueConnection();
       connection.start();
-      session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
-      
+      session = connection.createQueueSession(false,
+            QueueSession.AUTO_ACKNOWLEDGE);
+
       Queue queue = (Queue) getInitialContext().lookup("queue/dlqtest");
       sender = session.createSender(queue);
 
-      Queue dlq = (Queue)getInitialContext().lookup("queue/DLQ");
-      
-      ObjectName dlqName = new ObjectName("jboss.mq.destination:service=Queue,name=DLQ");
+      Queue dlq = (Queue) getInitialContext().lookup("queue/DLQ");
+
+      ObjectName dlqName = new ObjectName(
+            "jboss.mq.destination:service=Queue,name=DLQ");
       getServer().invoke(dlqName, "removeAllMessages", null, null);
-   
+
       TextMessage message = session.createTextMessage();
       message.setStringProperty("foo", "bar");
       message.setStringProperty("null", null);
       String text = "expire on server";
       message.setText(text);
-    
+
       sender.send(message);
 
       Thread.sleep(1000);
 
-      assertSize(session, queue,  0);
+      assertSize(session, queue, 0);
       assertSize(session, dlq, 1);
-      
+
       QueueReceiver receiver = session.createReceiver(dlq);
       message = (TextMessage) receiver.receiveNoWait();
       assertNotNull(message);
-      assertEquals("QUEUE.dlqtest", message.getStringProperty("JBOSS_ORIG_DESTINATION"));
+      assertEquals("QUEUE.dlqtest", message
+            .getStringProperty("JBOSS_ORIG_DESTINATION"));
       assertEquals(0L, message.getJMSExpiration());
       assertEquals(text, message.getText());
       assertEquals("bar", message.getStringProperty("foo"));
       assertNull(message.getStringProperty("null"));
-      
+
       sender.close();
       receiver.close();
 
       session.close();
       connection.close();
    }
-   
+
    private List list(QueueSession session, Queue queue) throws Exception
    {
-      QueueBrowser browser = session.createBrowser( queue );
+      QueueBrowser browser = session.createBrowser(queue);
       Enumeration e = browser.getEnumeration();
       List messages = CollectionsUtil.list(e);
-      
+
       browser.close();
-      
+
       return messages;
    }
 
@@ -402,23 +416,40 @@
       return l.size();
    }
 
-   private void assertSize(QueueSession session, Queue queue, int size) throws Exception
+   private void assertSize(QueueSession session, Queue queue, int size)
+         throws Exception
    {
       assertEquals(size, size(session, queue));
    }
-   
-   protected QueueConnectionFactory getQueueConnectionFactory() throws Exception
+
+   protected QueueConnectionFactory getQueueConnectionFactory()
+         throws Exception
    {
       try
       {
-         return (QueueConnectionFactory) getInitialContext().lookup("ConnectionFactory");
+         return (QueueConnectionFactory) getInitialContext().lookup(
+               "ConnectionFactory");
+      } catch (NamingException e)
+      {
+         return (QueueConnectionFactory) getInitialContext().lookup(
+               "java:/ConnectionFactory");
       }
-      catch (NamingException e)
+   }
+
+   protected TopicConnectionFactory getTopicConnectionFactory()
+         throws Exception
+   {
+      try
       {
-         return (QueueConnectionFactory) getInitialContext().lookup("java:/ConnectionFactory");
+         return (TopicConnectionFactory) getInitialContext().lookup(
+               "ConnectionFactory");
+      } catch (NamingException e)
+      {
+         return (TopicConnectionFactory) getInitialContext().lookup(
+               "java:/ConnectionFactory");
       }
    }
-   
+
    protected void clear(TestStatus status)
    {
       status.clear();
@@ -435,7 +466,15 @@
       assertFalse(status.postConstruct());
       assertFalse(status.preDestroy());
    }
-   
+
+   protected void setSecurity(String user, String password)
+   {
+      SecurityAssociation.setPrincipal(new SimplePrincipal(user));
+      SecurityAssociation.setCredential(password.toCharArray());
+
+      InitialContextFactory.setSecurity(user, password);
+   }
+
    protected InitialContext getInitialContext() throws Exception
    {
       return InitialContextFactory.getInitialContext();
@@ -443,7 +482,8 @@
 
    public static Test suite() throws Exception
    {
-      return getDeploySetup(MDBUnitTestCase.class, "mdbtest-service.xml, mdb-test.jar");
+      return getDeploySetup(MDBUnitTestCase.class,
+            "mdbtest-service.xml, mdb-test.jar");
    }
 
-}
+}
\ No newline at end of file

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/security/unit/EJBSpecUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/security/unit/EJBSpecUnitTestCase.java	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/security/unit/EJBSpecUnitTestCase.java	2006-08-01 17:38:44 UTC (rev 54985)
@@ -58,557 +58,564 @@
  @version $Revision$
  */
 public class EJBSpecUnitTestCase
-   extends JBossTestCase
+extends JBossTestCase
 {
-   private static final Logger log = Logger.getLogger(EJBSpecUnitTestCase.class);
-   
-   static String username = "scott";
-   static char[] password = "echoman".toCharArray();
-   static String QUEUE_FACTORY = "ConnectionFactory";
-   
-   LoginContext lc;
-   boolean loggedIn;
+private static final Logger log = Logger.getLogger(EJBSpecUnitTestCase.class);
 
-   public EJBSpecUnitTestCase(String name)
-   {
-      super(name);
-   }
-   
-   protected void tearDown() throws Exception
-   {
-      logout();
-   }
+static String username = "scott";
+static char[] password = "echoman".toCharArray();
+static String QUEUE_FACTORY = "ConnectionFactory";
 
-   /** Validate that the users have the expected logins and roles.
-    * 
-    * @throws Exception
-    */ 
-   public void testSecurityDomain() throws Exception
-   {
-      log.info("+++ testSecurityDomain, domain=spec-test");
-      MBeanServerConnection conn = (MBeanServerConnection) getServer();
-      ObjectName secMgrName = new ObjectName("jboss.security:service=JaasSecurityManager");
-      JaasSecurityManagerServiceMBean secMgr = (JaasSecurityManagerServiceMBean)
-         MBeanServerInvocationHandler.newProxyInstance(conn, secMgrName,
-         JaasSecurityManagerServiceMBean.class, false);
+LoginContext lc;
+boolean loggedIn;
 
-      // Test the spec-test security domain
-      String domain = "spec-test";
-      SimplePrincipal user = new SimplePrincipal("scott");
-      boolean isValid = secMgr.isValid(domain, user, password);
-      assertTrue("scott password is echoman", isValid);
-      HashSet testRole = new HashSet();
-      testRole.add(new SimplePrincipal("Echo"));
-      boolean hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
-      assertTrue("scott has Echo role", hasRole);
-      testRole.clear();
-      testRole.add(new SimplePrincipal("EchoLocal"));
-      hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
-      assertTrue("scott has EchoLocal role", hasRole);
-      testRole.clear();
-      testRole.add(new SimplePrincipal("ProjectUser"));
-      hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
-      assertTrue("scott has ProjectUser role", hasRole);
+public EJBSpecUnitTestCase(String name)
+{
+   super(name);
+}
 
-      isValid = secMgr.isValid(domain, user, "badpass".toCharArray());
-      assertTrue("badpass is an invalid password for scott", isValid == false);
+protected void tearDown() throws Exception
+{
+   logout();
+}
 
-      // Test the spec-test-domain security domain
-      log.info("+++ testSecurityDomain, domain=spec-test-domain");
-      domain = "spec-test-domain";
-      isValid = secMgr.isValid(domain, user, password);
-      assertTrue("scott password is echoman", isValid);
-      hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
-      assertTrue("scott has Echo role", hasRole);
-      testRole.clear();
-      testRole.add(new SimplePrincipal("EchoLocal"));
-      hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
-      assertTrue("scott has EchoLocal role", hasRole);
-      testRole.clear();
-      testRole.add(new SimplePrincipal("ProjectUser"));
-      hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
-      assertTrue("scott has ProjectUser role", hasRole);      
+/** Validate that the users have the expected logins and roles.
+ * 
+ * @throws Exception
+ */ 
+public void testSecurityDomain() throws Exception
+{
+   log.info("+++ testSecurityDomain, domain=spec-test");
+   MBeanServerConnection conn = (MBeanServerConnection) getServer();
+   ObjectName secMgrName = new ObjectName("jboss.security:service=JaasSecurityManager");
+   JaasSecurityManagerServiceMBean secMgr = (JaasSecurityManagerServiceMBean)
+      MBeanServerInvocationHandler.newProxyInstance(conn, secMgrName,
+      JaasSecurityManagerServiceMBean.class, false);
 
-      isValid = secMgr.isValid(domain, user, "badpass".toCharArray());
-      assertTrue("badpass is an invalid password for scott", isValid == false);
-   }
+   // Test the spec-test security domain
+   String domain = "spec-test";
+   SimplePrincipal user = new SimplePrincipal("scott");
+   boolean isValid = secMgr.isValid(domain, user, password);
+   assertTrue("scott password is echoman", isValid);
+   HashSet testRole = new HashSet();
+   testRole.add(new SimplePrincipal("Echo"));
+   boolean hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
+   assertTrue("scott has Echo role", hasRole);
+   testRole.clear();
+   testRole.add(new SimplePrincipal("EchoLocal"));
+   hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
+   assertTrue("scott has EchoLocal role", hasRole);
+   testRole.clear();
+   testRole.add(new SimplePrincipal("ProjectUser"));
+   hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
+   assertTrue("scott has ProjectUser role", hasRole);
 
-   /** Test that:
-    1. SecureBean returns a non-null principal when getCallerPrincipal
-    is called with a security context and that this is propagated
-    to its Entity bean ref.
-    
-    2. UnsecureBean throws an IllegalStateException when getCallerPrincipal
-    is called without a security context.
-    */
-   public void testGetCallerPrincipal() throws Exception
-   {   
-      log.debug("+++ testGetCallerPrincipal()");
-      StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.UnsecureStatelessSession2");
-      log.debug("Created spec.UnsecureStatelessSession2");
-      
-      try
-      {
-         // This should fail because echo calls getCallerPrincipal()
-         bean.echo("Hello from nobody?");
-         fail("Was able to call StatelessSession.echo");
-      }
-      catch(Exception e)
-      {
-         log.debug("echo failed as expected");
-      }
-      
-      login();
-      bean = (StatelessSession)getInitialContext().lookup("spec.StatelessSession2");
-      log.debug("Created spec.StatelessSession2");
-      // Test that the Entity bean sees username as its principal
-      String echo = bean.echo(username);
-      log.debug("bean.echo(username) = "+echo);
-      assertTrue("username == echo", echo.equals(username));
-      
-      logout();
-   }
-   
-   /** Test the use of getCallerPrincipal from within the ejbCreate
-    * in a stateful session bean
-    */
-   public void testStatefulCreateCaller() throws Exception
-   {
-      log.debug("+++ testStatefulCreateCaller");
-      login();
-      InitialContext jndiContext = new InitialContext();
-     
-      StatefulSession bean = (StatefulSession)jndiContext.lookup("spec.StatefulSession");
-      // Need to invoke a method to ensure an ejbCreate call
-      bean.echo("testStatefulCreateCaller");
-      log.debug("Bean.echo(), ok");
+   isValid = secMgr.isValid(domain, user, "badpass".toCharArray());
+   assertTrue("badpass is an invalid password for scott", isValid == false);
 
-      logout();
-   }
+   // Test the spec-test-domain security domain
+   log.info("+++ testSecurityDomain, domain=spec-test-domain");
+   domain = "spec-test-domain";
+   isValid = secMgr.isValid(domain, user, password);
+   assertTrue("scott password is echoman", isValid);
+   hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
+   assertTrue("scott has Echo role", hasRole);
+   testRole.clear();
+   testRole.add(new SimplePrincipal("EchoLocal"));
+   hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
+   assertTrue("scott has EchoLocal role", hasRole);
+   testRole.clear();
+   testRole.add(new SimplePrincipal("ProjectUser"));
+   hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
+   assertTrue("scott has ProjectUser role", hasRole);      
 
-   /**
-    * Test that a call interacting with different security domains does not
-    * change the 
-    * @throws Exception
-    */ 
-   public void testDomainInteraction() throws Exception
+   isValid = secMgr.isValid(domain, user, "badpass".toCharArray());
+   assertTrue("badpass is an invalid password for scott", isValid == false);
+}
+
+/** Test that:
+ 1. SecureBean returns a non-null principal when getCallerPrincipal
+ is called with a security context and that this is propagated
+ to its Entity bean ref.
+ 
+ 2. UnsecureBean throws an IllegalStateException when getCallerPrincipal
+ is called without a security context.
+ */
+public void testGetCallerPrincipal() throws Exception
+{   
+   log.debug("+++ testGetCallerPrincipal()");
+   StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.UnsecureStatelessSession2");
+   log.debug("Created spec.UnsecureStatelessSession2");
+   
+   try
    {
-      logout();
-      login("testDomainInteraction", "testDomainInteraction".toCharArray());
-      log.debug("+++ testDomainInteraction()");
-      SecurityContext bean = (SecurityContext)getInitialContext().lookup("spec.UserInRoleContextSession");
-      log.debug("Created spec.UserInRoleContextSession");
-      HashSet roles = new HashSet();
-      roles.add("Role1");
-      roles.add("Role2");
-      bean.testDomainInteraction(roles);   
+      // This should fail because echo calls getCallerPrincipal()
+      bean.echo("Hello from nobody?");
+      fail("Was able to call StatelessSession.echo");
    }
-
-   /** Test that the calling principal is propagated across bean calls.
-    */
-   public void testPrincipalPropagation() throws Exception
+   catch(Exception e)
    {
-      log.debug("+++ testPrincipalPropagation");
-      logout();
-      login();
-      StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.UnsecureStatelessSession2");
-      log.debug("Created spec.UnsecureStatelessSession2");
-      log.debug("Bean.forward('testPrincipalPropagation') -> "+bean.forward("testPrincipalPropagation"));
+      log.debug("echo failed as expected");
    }
    
-   public void testMethodAccess() throws Exception
-   {
-      log.debug("+++ testMethodAccess");
-      login();
-      StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.StatelessSession");
-      log.debug("Created spec.StatelessSession");
-      log.debug("Bean.echo('Hello') -> "+bean.echo("Hello"));
+   login();
+   bean = (StatelessSession)getInitialContext().lookup("spec.StatelessSession2");
+   log.debug("Created spec.StatelessSession2");
+   // Test that the Entity bean sees username as its principal
+   String echo = bean.echo(username);
+   log.debug("bean.echo(username) = "+echo);
+   assertTrue("username == echo", echo.equals(username));
+   
+   logout();
+}
 
-      // This should be allowed in ejb3
-      bean.noop();
-   }
+/** Test the use of getCallerPrincipal from within the ejbCreate
+ * in a stateful session bean
+ */
+public void testStatefulCreateCaller() throws Exception
+{
+   log.debug("+++ testStatefulCreateCaller");
+   login();
+   InitialContext jndiContext = new InitialContext();
+  
+   StatefulSession bean = (StatefulSession)jndiContext.lookup("spec.StatefulSession");
+   // Need to invoke a method to ensure an ejbCreate call
+   bean.echo("testStatefulCreateCaller");
+   log.debug("Bean.echo(), ok");
 
-   /** Test that the echo method is accessible by an Echo
-    role. Since the excluded() method of the StatelessSession
-    bean has been placed into the excluded set it should not
-    accessible by any user. This uses the security domain of the
-    JaasSecurityDomain service to test its use as an authentication mgr.
-    */
-   public void testDomainMethodAccess() throws Exception
-   {
-      log.debug("+++ testDomainMethodAccess");
-      login();
-      StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.StatelessSessionInDomain");
-      log.debug("Created spec.StatelessSessionInDomain");
-      log.debug("Bean.echo('testDomainMethodAccess') -> "+bean.echo("testDomainMethodAccess"));
+   logout();
+}
 
-      try
-      {
-         // This should not be allowed
-         bean.excluded();
-         fail("Was able to call StatelessSession.excluded");
-      }
-      catch(Exception e)
-      {
-         log.debug("StatelessSession.excluded failed as expected");
-      }
-   }
+/**
+ * Test that a call interacting with different security domains does not
+ * change the 
+ * @throws Exception
+ */ 
+public void testDomainInteraction() throws Exception
+{
+   logout();
+   login("testDomainInteraction", "testDomainInteraction".toCharArray());
+   log.debug("+++ testDomainInteraction()");
+   SecurityContext bean = (SecurityContext)getInitialContext().lookup("spec.UserInRoleContextSession");
+   log.debug("Created spec.UserInRoleContextSession");
+   HashSet roles = new HashSet();
+   roles.add("Role1");
+   roles.add("Role2");
+   bean.testDomainInteraction(roles);   
+}
 
-   /** Test that the permissions assigned to the stateless session bean:
-    with ejb-name=org/jboss/test/security/ejb/StatelessSession_test
-    are read correctly.
-    */
-   public void testMethodAccess2() throws Exception
+/** Test that the calling principal is propagated across bean calls.
+ */
+public void testPrincipalPropagation() throws Exception
+{
+   log.debug("+++ testPrincipalPropagation");
+   logout();
+   login();
+   StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.UnsecureStatelessSession2");
+   log.debug("Created spec.UnsecureStatelessSession2");
+   log.debug("Bean.forward('testPrincipalPropagation') -> "+bean.forward("testPrincipalPropagation"));
+}
+
+public void testMethodAccess() throws Exception
+{
+   log.debug("+++ testMethodAccess");
+   login();
+   StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.StatelessSession");
+   log.debug("Created spec.StatelessSession");
+   log.debug("Bean.echo('Hello') -> "+bean.echo("Hello"));
+
+   // This should be allowed in ejb3
+   bean.noop();
+}
+
+/** Test that the echo method is accessible by an Echo
+ role. Since the excluded() method of the StatelessSession
+ bean has been placed into the excluded set it should not
+ accessible by any user. This uses the security domain of the
+ JaasSecurityDomain service to test its use as an authentication mgr.
+ */
+public void testDomainMethodAccess() throws Exception
+{
+   log.debug("+++ testDomainMethodAccess");
+   login();
+   StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.StatelessSessionInDomain");
+   log.debug("Created spec.StatelessSessionInDomain");
+   log.debug("Bean.echo('testDomainMethodAccess') -> "+bean.echo("testDomainMethodAccess"));
+
+   try
    {
-      log.debug("+++ testMethodAccess2");
-      login();
-      InitialContext jndiContext = new InitialContext();
-      StatelessSession bean = (StatelessSession)jndiContext.lookup("spec.StatelessSession_test");
-      log.debug("Created spec.StatelessSession_test");
-      log.debug("Bean.echo('testMethodAccess2') -> "+bean.echo("testMethodAccess2"));
+      // This should not be allowed
+      bean.excluded();
+      fail("Was able to call StatelessSession.excluded");
    }
-
-   /** Test a user with Echo and EchoLocal roles can access the CalleeBean
-    through its local interface by calling the CallerBean and that a user
-    with only a EchoLocal cannot call the CallerBean.
-    */
-   public void a1testLocalMethodAccess() throws Exception
+   catch(Exception e)
    {
-      log.debug("+++ testLocalMethodAccess");
-      login();
-      InitialContext jndiContext = new InitialContext();
-      CalledSession bean = (CalledSession)jndiContext.lookup("spec.CallerBean");
-      log.debug("Created spec.CallerBean");
-      log.debug("Bean.invokeEcho('testLocalMethodAccess') -> "+bean.invokeEcho("testLocalMethodAccess"));
+      log.debug("StatelessSession.excluded failed as expected");
    }
+}
 
-   /** Test access to a bean with a mix of remote interface permissions and
-    * unchecked permissions with the unchecked permissions declared first.
-    * @throws Exception
-    */ 
-   public void testUncheckedRemote() throws Exception
+/** Test that the permissions assigned to the stateless session bean:
+ with ejb-name=org/jboss/test/security/ejb/StatelessSession_test
+ are read correctly.
+ */
+public void testMethodAccess2() throws Exception
+{
+   log.debug("+++ testMethodAccess2");
+   login();
+   InitialContext jndiContext = new InitialContext();
+   StatelessSession bean = (StatelessSession)jndiContext.lookup("spec.StatelessSession_test");
+   log.debug("Created spec.StatelessSession_test");
+   log.debug("Bean.echo('testMethodAccess2') -> "+bean.echo("testMethodAccess2"));
+}
+
+/** Test a user with Echo and EchoLocal roles can access the CalleeBean
+ through its local interface by calling the CallerBean and that a user
+ with only a EchoLocal cannot call the CallerBean.
+ */
+public void a1testLocalMethodAccess() throws Exception
+{
+   log.debug("+++ testLocalMethodAccess");
+   login();
+   InitialContext jndiContext = new InitialContext();
+   CalledSession bean = (CalledSession)jndiContext.lookup("spec.CallerBean");
+   log.debug("Created spec.CallerBean");
+   log.debug("Bean.invokeEcho('testLocalMethodAccess') -> "+bean.invokeEcho("testLocalMethodAccess"));
+}
+
+/** Test access to a bean with a mix of remote interface permissions and
+ * unchecked permissions with the unchecked permissions declared first.
+ * @throws Exception
+ */ 
+public void testUncheckedRemote() throws Exception
+{
+   log.debug("+++ testUncheckedRemote");
+   login();
+   StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.UncheckedSessionRemoteLast");
+   log.debug("Created spec.UncheckedSessionRemoteLast");
+   log.debug("Bean.echo('testUncheckedRemote') -> "+bean.echo("testUncheckedRemote"));
+   try
    {
-      log.debug("+++ testUncheckedRemote");
-      login();
-      StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.UncheckedSessionRemoteLast");
-      log.debug("Created spec.UncheckedSessionRemoteLast");
-      log.debug("Bean.echo('testUncheckedRemote') -> "+bean.echo("testUncheckedRemote"));
-      try
-      {
-         bean.excluded();
-         fail("Was able to call UncheckedSessionRemoteLast.excluded");
-      }
-      catch(Exception e)
-      {
-         log.debug("UncheckedSessionRemoteLast.excluded failed as expected");         
-      }
-      logout();
+      bean.excluded();
+      fail("Was able to call UncheckedSessionRemoteLast.excluded");
    }
-
-   /** Test access to a bean with a mix of remote interface permissions and
-    * unchecked permissions with the unchecked permissions declared last.
-    * @throws Exception
-    */ 
-   public void testRemoteUnchecked() throws Exception
+   catch(Exception e)
    {
-      log.debug("+++ testRemoteUnchecked");
-      login();
-      StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.UncheckedSessionRemoteFirst");
-      log.debug("Created spec.UncheckedSessionRemoteFirst");
-      log.debug("Bean.echo('testRemoteUnchecked') -> "+bean.echo("testRemoteUnchecked"));
-      try
-      {
-         bean.excluded();
-         fail("Was able to call UncheckedSessionRemoteFirst.excluded");
-      }
-      catch(Exception e)
-      {
-         log.debug("UncheckedSessionRemoteFirst.excluded failed as expected");         
-      }
-      logout();
+      log.debug("UncheckedSessionRemoteLast.excluded failed as expected");         
    }
+   logout();
+}
 
-   /** Test that a user with a role that has not been assigned any
-    method permissions in the ejb-jar descriptor is able to access a
-    method that has been marked as unchecked.
-    */
-   public void testUnchecked() throws Exception
+/** Test access to a bean with a mix of remote interface permissions and
+ * unchecked permissions with the unchecked permissions declared last.
+ * @throws Exception
+ */ 
+public void testRemoteUnchecked() throws Exception
+{
+   log.debug("+++ testRemoteUnchecked");
+   login();
+   StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.UncheckedSessionRemoteFirst");
+   log.debug("Created spec.UncheckedSessionRemoteFirst");
+   log.debug("Bean.echo('testRemoteUnchecked') -> "+bean.echo("testRemoteUnchecked"));
+   try
    {
-      log.debug("+++ testUnchecked");
-      // Login as scott to create the bean
-      login();
-      StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.StatelessSession");
-      log.debug("Created spec.StatelessSession");
-      // Logout and login back in as stark to test access to the unchecked method
-      logout();
-      login("stark", "javaman".toCharArray());
-      bean.unchecked();
-      log.debug("Called Bean.unchecked()");
-      logout();
+      bean.excluded();
+      fail("Was able to call UncheckedSessionRemoteFirst.excluded");
    }
-
-   /** Test that a user with a valid role is able to access a
-    bean for which all methods have been marked as unchecked.
-    */
-   public void testUncheckedWithLogin() throws Exception
+   catch(Exception e)
    {
-      log.debug("+++ testUncheckedWithLogin");
-      // Login as scott to see that a user with roles is allowed access
-      login();
-      StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.UncheckedSession");
-      log.debug("Created spec.StatelessSession");
-      bean.unchecked();
-      log.debug("Called Bean.unchecked()");
-      logout();
+      log.debug("UncheckedSessionRemoteFirst.excluded failed as expected");         
    }
+   logout();
+}
 
-   /** Test that user scott who has the Echo role is not able to
-    access the StatelessSession2.excluded method even though
-    the Echo role has been granted access to all methods of
-    StatelessSession2 to test that the excluded-list takes
-    precendence over the method-permissions.
-    */
-   public void testExcluded() throws Exception
+/** Test that a user with a role that has not been assigned any
+ method permissions in the ejb-jar descriptor is able to access a
+ method that has been marked as unchecked.
+ */
+public void testUnchecked() throws Exception
+{
+   log.debug("+++ testUnchecked");
+   // Login as scott to create the bean
+   login();
+   StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.StatelessSession");
+   log.debug("Created spec.StatelessSession");
+   // Logout and login back in as stark to test access to the unchecked method
+   logout();
+   login("stark", "javaman".toCharArray());
+   bean.unchecked();
+   log.debug("Called Bean.unchecked()");
+   logout();
+}
+
+/** Test that a user with a valid role is able to access a
+ bean for which all methods have been marked as unchecked.
+ */
+public void testUncheckedWithLogin() throws Exception
+{
+   log.debug("+++ testUncheckedWithLogin");
+   // Login as scott to see that a user with roles is allowed access
+   login();
+   StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.UncheckedSession");
+   log.debug("Created spec.StatelessSession");
+   bean.unchecked();
+   log.debug("Called Bean.unchecked()");
+   logout();
+}
+
+/** Test that user scott who has the Echo role is not able to
+ access the StatelessSession2.excluded method even though
+ the Echo role has been granted access to all methods of
+ StatelessSession2 to test that the excluded-list takes
+ precendence over the method-permissions.
+ */
+public void testExcluded() throws Exception
+{
+   log.debug("+++ testExcluded");
+   login();
+   StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.StatelessSession2");
+   log.debug("Created spec.StatelessSession2");
+   try
    {
-      log.debug("+++ testExcluded");
-      login();
-      StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.StatelessSession2");
-      log.debug("Created spec.StatelessSession2");
-      try
-      {
-         bean.excluded();
-         fail("Was able to call Bean.excluded()");
-      }
-      catch(Exception e)
-      {
-         log.debug("Bean.excluded() failed as expected");
-         // This is what we expect
-      }
-      logout();
+      bean.excluded();
+      fail("Was able to call Bean.excluded()");
    }
-   
-   /** This method tests the following call chains:
-    1. RunAsStatelessSession.echo() -> PrivateEntity.echo()
-    2. RunAsStatelessSession.noop() -> RunAsStatelessSession.excluded()
-    3. RunAsStatelessSession.forward() -> StatelessSession.echo()
-    1. Should succeed because the run-as identity of RunAsStatelessSession
-    is valid for accessing PrivateEntity.
-    2. Should succeed because the run-as identity of RunAsStatelessSession
-    is valid for accessing RunAsStatelessSession.excluded().
-    3. Should fail because the run-as identity of RunAsStatelessSession
-    is not Echo.
-    */
-   public void testRunAs() throws Exception
+   catch(Exception e)
    {
-      log.debug("+++ testRunAs");
-      login();
-      StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.RunAsStatelessSession");
-      log.debug("Created spec.RunAsStatelessSession");
-      log.debug("Bean.echo('testRunAs') -> "+bean.echo("testRunAs"));
-      bean.noop();
-      log.debug("Bean.noop(), ok");
-      
-      try
-      {
-         // This should not be allowed
-         bean.forward("Hello");
-         fail("Was able to call RunAsStatelessSession.forward");
-      }
-      catch(Exception e)
-      {
-         log.debug("StatelessSession.forward failed as expected");
-      }
-      
-      logout();
+      log.debug("Bean.excluded() failed as expected");
+      // This is what we expect
    }
+   logout();
+}
 
-   /** This method tests the following call chain:
-    Level1CallerBean.callEcho() -> Level2CallerBean.invokeEcho()
-      -> Level3CalleeBean.echo()
-    The Level1CallerBean uses a run-as of InternalRole and the Level2CallerBean
-    and Level3CalleeBean are only accessible by InternalRole.
-    */   
-   public void testDeepRunAs() throws Exception
+/** This method tests the following call chains:
+ 1. RunAsStatelessSession.echo() -> PrivateEntity.echo()
+ 2. RunAsStatelessSession.noop() -> RunAsStatelessSession.excluded()
+ 3. RunAsStatelessSession.forward() -> StatelessSession.echo()
+ 1. Should succeed because the run-as identity of RunAsStatelessSession
+ is valid for accessing PrivateEntity.
+ 2. Should succeed because the run-as identity of RunAsStatelessSession
+ is valid for accessing RunAsStatelessSession.excluded().
+ 3. Should fail because the run-as identity of RunAsStatelessSession
+ is not Echo.
+ */
+public void testRunAs() throws Exception
+{
+   log.debug("+++ testRunAs");
+   login();
+   StatelessSession bean = (StatelessSession)getInitialContext().lookup("spec.RunAsStatelessSession");
+   log.debug("Created spec.RunAsStatelessSession");
+   log.debug("Bean.echo('testRunAs') -> "+bean.echo("testRunAs"));
+   bean.noop();
+   log.debug("Bean.noop(), ok");
+   
+   try
    {
-      log.debug("+++ testDeepRunAs");
-      login();
-      CalledSession bean = (CalledSession)getInitialContext().lookup("spec.Level1CallerBean");
-      log.debug("Created spec.Level1CallerBean");
-      String principal = bean.callEcho();
-      assertEquals("scott", principal);
-      log.debug("Bean.callEcho() ok");
+      // This should not be allowed
+      bean.forward("Hello");
+      fail("Was able to call RunAsStatelessSession.forward");
    }
-
-   public void testRunAsSFSB() throws Exception
+   catch(Exception e)
    {
-      log.info("+++ testRunAsSFSB");
-      login();
-      log.debug("Found CallerFacadeBean-testRunAsSFSB Home");
-      CalledSession bean = (CalledSession)getInitialContext().lookup("spec.CallerFacadeBean-testRunAsSFSB");
-      log.debug("Created spec.CallerFacadeBean-testRunAsSFSB");
-      bean.invokeEcho("testRunAsSFSB");
-      log.debug("Bean.invokeEcho() ok");
+      log.debug("StatelessSession.forward failed as expected");
    }
+   
+   logout();
+}
 
-   /**
-    * Test the run-as side-effects raised in 
-    * http://jira.jboss.com/jira/browse/JBAS-1852
-    * 
-    * @throws Exception
-    */ 
-   public void testJBAS1852() throws Exception
-   {
-      log.info("+++ testJBAS1852");
-      login();
-      SessionFacade bean = (SessionFacade)getInitialContext().lookup("spec.PublicSessionFacade");
-      log.debug("Created PublicSessionFacade");
-      log.debug("Bean.callEcho('testJBAS1852') -> " + bean.callEcho("testJBAS1852"));
-   }
+/** This method tests the following call chain:
+ Level1CallerBean.callEcho() -> Level2CallerBean.invokeEcho()
+   -> Level3CalleeBean.echo()
+ The Level1CallerBean uses a run-as of InternalRole and the Level2CallerBean
+ and Level3CalleeBean are only accessible by InternalRole.
+ */   
+public void testDeepRunAs() throws Exception
+{
+   log.debug("+++ testDeepRunAs");
+   login();
+   CalledSession bean = (CalledSession)getInitialContext().lookup("spec.Level1CallerBean");
+   log.debug("Created spec.Level1CallerBean");
+   String principal = bean.callEcho();
+   assertEquals("scott", principal);
+   log.debug("Bean.callEcho() ok");
+}
 
-   /** Test that an MDB with a run-as identity is able to access secure EJBs
-    that require the identity.
-    */
-   public void a1testMDBRunAs() throws Exception
-   {
-      log.debug("+++ testMDBRunAs");
-      logout();
-      QueueConnectionFactory queueFactory = (QueueConnectionFactory) getInitialContext().lookup(QUEUE_FACTORY);
-      Queue queA = (Queue) getInitialContext().lookup("queue/A");
-      Queue queB = (Queue) getInitialContext().lookup("queue/B");
-      QueueConnection queueConn = queueFactory.createQueueConnection();
-      QueueSession session = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
-      Message msg = session.createMessage();
-      msg.setStringProperty("arg", "testMDBRunAs");
-      msg.setJMSReplyTo(queB);
-      QueueSender sender = session.createSender(queA);
-      sender.send(msg);
-      sender.close();
-      log.debug("Sent msg to queue/A");
-      queueConn.start();
-      QueueReceiver recv = session.createReceiver(queB);
-      msg = recv.receive(5000);
-      log.debug("Recv msg: "+msg);
-      String info = msg.getStringProperty("reply");
-      recv.close();
-      session.close();
-      queueConn.close();
+public void testRunAsSFSB() throws Exception
+{
+   log.info("+++ testRunAsSFSB");
+   login();
+   log.debug("Found CallerFacadeBean-testRunAsSFSB Home");
+   CalledSession bean = (CalledSession)getInitialContext().lookup("spec.CallerFacadeBean-testRunAsSFSB");
+   log.debug("Created spec.CallerFacadeBean-testRunAsSFSB");
+   bean.invokeEcho("testRunAsSFSB");
+   log.debug("Bean.invokeEcho() ok");
+}
 
-      if( info == null || info.startsWith("Failed") )
-      {
-         fail("Recevied exception reply, info="+info);
-      }
-   }
+/**
+ * Test the run-as side-effects raised in 
+ * http://jira.jboss.com/jira/browse/JBAS-1852
+ * 
+ * @throws Exception
+ */ 
+public void testJBAS1852() throws Exception
+{
+   log.info("+++ testJBAS1852");
+   login();
+   SessionFacade bean = (SessionFacade)getInitialContext().lookup("spec.PublicSessionFacade");
+   log.debug("Created PublicSessionFacade");
+   log.debug("Bean.callEcho('testJBAS1852') -> " + bean.callEcho("testJBAS1852"));
+}
 
-   /** Test that an MDB with a run-as identity is able to access secure EJBs
-    that require the identity. DeepRunAsMDB -> Level1MDBCallerBean.callEcho() ->
-      Level2CallerBean.invokeEcho() -> Level3CalleeBean.echo()
-    The MDB uses a run-as of InternalRole and the Level2CallerBean
-    and Level3CalleeBean are only accessible by InternalRole.
-    */
-   public void a1testMDBDeepRunAs() throws Exception
+/** Test that an MDB with a run-as identity is able to access secure EJBs
+ that require the identity.
+ */
+public void a1testMDBRunAs() throws Exception
+{
+   log.debug("+++ testMDBRunAs");
+   logout();
+   QueueConnectionFactory queueFactory = (QueueConnectionFactory) getInitialContext().lookup(QUEUE_FACTORY);
+   Queue queA = (Queue) getInitialContext().lookup("queue/A");
+   Queue queB = (Queue) getInitialContext().lookup("queue/B");
+   QueueConnection queueConn = queueFactory.createQueueConnection();
+   QueueSession session = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+   Message msg = session.createMessage();
+   msg.setStringProperty("arg", "testMDBRunAs");
+   msg.setJMSReplyTo(queB);
+   QueueSender sender = session.createSender(queA);
+   sender.send(msg);
+   sender.close();
+   log.debug("Sent msg to queue/A");
+   queueConn.start();
+   QueueReceiver recv = session.createReceiver(queB);
+   msg = recv.receive(5000);
+   log.debug("Recv msg: "+msg);
+   String info = msg.getStringProperty("reply");
+   recv.close();
+   session.close();
+   queueConn.close();
+
+   if( info == null || info.startsWith("Failed") )
    {
-      log.debug("+++ testMDBDeepRunAs");
-      logout();
-      QueueConnectionFactory queueFactory = (QueueConnectionFactory) getInitialContext().lookup(QUEUE_FACTORY);
-      Queue queD = (Queue) getInitialContext().lookup("queue/D");
-      Queue queB = (Queue) getInitialContext().lookup("queue/B");
-      QueueConnection queueConn = queueFactory.createQueueConnection();
-      QueueSession session = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
-      Message msg = session.createMessage();
-      msg.setStringProperty("arg", "testMDBDeepRunAs");
-      msg.setJMSReplyTo(queB);
-      QueueSender sender = session.createSender(queD);
-      sender.send(msg);
-      sender.close();
-      log.debug("Sent msg to "+queD);
-      queueConn.start();
-      QueueReceiver recv = session.createReceiver(queB);
-      msg = recv.receive(5000);
-      log.debug("Recv msg: "+msg);
-      String info = msg.getStringProperty("reply");
-      recv.close();
-      session.close();
-      queueConn.close();
-
-      if( info == null || info.startsWith("Failed") )
-      {
-         fail("Recevied exception reply, info="+info);
-      }
+      fail("Recevied exception reply, info="+info);
    }
+}
 
-   /** This method tests that the RunAsWithRolesMDB is assigned multiple roles
-    * within its onMessage so that it can call into the ProjRepository session
-    * bean's methods that required ProjectAdmin, CreateFolder and DeleteFolder
-    * roles.
-    */
-   public void a1testRunAsWithRoles() throws Exception
+/** Test that an MDB with a run-as identity is able to access secure EJBs
+ that require the identity. DeepRunAsMDB -> Level1MDBCallerBean.callEcho() ->
+   Level2CallerBean.invokeEcho() -> Level3CalleeBean.echo()
+ The MDB uses a run-as of InternalRole and the Level2CallerBean
+ and Level3CalleeBean are only accessible by InternalRole.
+ */
+public void a1testMDBDeepRunAs() throws Exception
+{
+   log.debug("+++ testMDBDeepRunAs");
+   logout();
+   QueueConnectionFactory queueFactory = (QueueConnectionFactory) getInitialContext().lookup(QUEUE_FACTORY);
+   Queue queD = (Queue) getInitialContext().lookup("queue/D");
+   Queue queB = (Queue) getInitialContext().lookup("queue/B");
+   QueueConnection queueConn = queueFactory.createQueueConnection();
+   QueueSession session = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+   Message msg = session.createMessage();
+   msg.setStringProperty("arg", "testMDBDeepRunAs");
+   msg.setJMSReplyTo(queB);
+   QueueSender sender = session.createSender(queD);
+   sender.send(msg);
+   sender.close();
+   log.debug("Sent msg to "+queD);
+   queueConn.start();
+   QueueReceiver recv = session.createReceiver(queB);
+   msg = recv.receive(5000);
+   log.debug("Recv msg: "+msg);
+   String info = msg.getStringProperty("reply");
+   recv.close();
+   session.close();
+   queueConn.close();
+
+   if( info == null || info.startsWith("Failed") )
    {
-      log.debug("+++ testRunAsWithRoles");
-      logout();
-      QueueConnectionFactory queueFactory = (QueueConnectionFactory) getInitialContext().lookup(QUEUE_FACTORY);
-      Queue queC = (Queue) getInitialContext().lookup("queue/C");
-      Queue queB = (Queue) getInitialContext().lookup("queue/B");
-      QueueConnection queueConn = queueFactory.createQueueConnection();
-      QueueSession session = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
-      Message msg = session.createMessage();
-      msg.setStringProperty("name", "testRunAsWithRoles");
-      msg.setJMSReplyTo(queB);
-      QueueSender sender = session.createSender(queC);
-      sender.send(msg);
-      sender.close();
-      log.debug("Sent msg to queue/C");
-      queueConn.start();
-      QueueReceiver recv = session.createReceiver(queB);
-      msg = recv.receive(5000);
-      log.debug("Recv msg: "+msg);
-      String info = msg.getStringProperty("reply");
-      recv.close();
-      session.close();
-      queueConn.close();
-
-      if( info == null || info.startsWith("Failed") )
-      {
-         fail("Recevied exception reply, info="+info);
-      }
+      fail("Recevied exception reply, info="+info);
    }
+}
 
-   /** Login as user scott using the conf.name login config or
-    'spec-test' if conf.name is not defined.
-    */
-   private void login() throws Exception
+/** This method tests that the RunAsWithRolesMDB is assigned multiple roles
+ * within its onMessage so that it can call into the ProjRepository session
+ * bean's methods that required ProjectAdmin, CreateFolder and DeleteFolder
+ * roles.
+ */
+public void a1testRunAsWithRoles() throws Exception
+{
+   log.debug("+++ testRunAsWithRoles");
+   logout();
+   QueueConnectionFactory queueFactory = (QueueConnectionFactory) getInitialContext().lookup(QUEUE_FACTORY);
+   Queue queC = (Queue) getInitialContext().lookup("queue/C");
+   Queue queB = (Queue) getInitialContext().lookup("queue/B");
+   QueueConnection queueConn = queueFactory.createQueueConnection();
+   QueueSession session = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+   Message msg = session.createMessage();
+   msg.setStringProperty("name", "testRunAsWithRoles");
+   msg.setJMSReplyTo(queB);
+   QueueSender sender = session.createSender(queC);
+   sender.send(msg);
+   sender.close();
+   log.debug("Sent msg to queue/C");
+   queueConn.start();
+   QueueReceiver recv = session.createReceiver(queB);
+   msg = recv.receive(5000);
+   log.debug("Recv msg: "+msg);
+   String info = msg.getStringProperty("reply");
+   recv.close();
+   session.close();
+   queueConn.close();
+
+   if( info == null || info.startsWith("Failed") )
    {
-      login(username, password);
+      fail("Recevied exception reply, info="+info);
    }
-   private void login(String username, char[] password) throws Exception
+}
+
+/** Login as user scott using the conf.name login config or
+ 'spec-test' if conf.name is not defined.
+ */
+private void login() throws Exception
+{
+   login(username, password);
+}
+private void login(String username, char[] password) throws Exception
+{
+   if( loggedIn )
+      return;
+   
+   String confName = System.getProperty("conf.name", "spec-test");
+   AppCallbackHandler handler = new AppCallbackHandler(username, password);
+   log.debug("Creating LoginContext("+confName+")");
+   lc = new LoginContext(confName, handler);
+   lc.login();
+   log.debug("Created LoginContext, subject="+lc.getSubject());
+   loggedIn = true;
+}
+private void logout() throws Exception
+{
+   if( lc != null )
    {
-      if( loggedIn )
-         return;
-      
-      String confName = System.getProperty("conf.name", "spec-test");
-      AppCallbackHandler handler = new AppCallbackHandler(username, password);
-      log.debug("Creating LoginContext("+confName+")");
-      lc = new LoginContext(confName, handler);
-      lc.login();
-      log.debug("Created LoginContext, subject="+lc.getSubject());
-      loggedIn = true;
+      loggedIn = false;
+      lc.logout();
+      lc = null;
    }
-   private void logout() throws Exception
-   {
-      if( lc != null )
-      {
-         loggedIn = false;
-         lc.logout();
-         lc = null;
-      }
-   }
+}
 
 
-   /**
-    * Setup the test suite.
-    */
-   public static Test suite() throws Exception
-   {
+/**
+ * Setup the test suite.
+ */
+public static Test suite() throws Exception
+{
+   try {
       Configuration.setConfiguration(new XMLLoginConfigImpl());
       return getDeploySetup(EJBSpecUnitTestCase.class, "security.jar");
    }
+   catch (Exception e)
+   {
+      e.printStackTrace();
+      throw e;
+   }
 }
+}

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/standalone/unit/StandardTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/standalone/unit/StandardTestCase.java	2006-08-01 17:12:23 UTC (rev 54984)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/standalone/unit/StandardTestCase.java	2006-08-01 17:38:44 UTC (rev 54985)
@@ -59,8 +59,8 @@
    
    static
    {
-      tests.put("org.jboss.ejb3.test.jca.inflowmdb.unit.InflowUnitTestCase", new StandardTestCaseTest("jmsinflowmdb.jar", "testJMS", null));
-      tests.put("org.jboss.ejb3.test.mdb.unit.MDBUnitTestCase", new StandardTestCaseTest("mdb-test.jar", null, "security-beans.xml, mdbtest-service.xml"));
+      tests.put("org.jboss.ejb3.test.jca.inflowmdb.unit.InflowUnitTestCase", new StandardTestCaseTest("jmsinflowmdb.jar", "testJMS", "standard/jca-inflowmdb-beans.xml"));
+      tests.put("org.jboss.ejb3.test.mdb.unit.MDBUnitTestCase", new StandardTestCaseTest("mdb-test.jar", null, "security-beans.xml,standard/testjms.xml"));
    }
 
    public StandardTestCase(String name)
@@ -97,9 +97,9 @@
    {
       EJB3StandaloneBootstrap.boot(null);
       EJB3StandaloneBootstrap.deployXmlResource("jboss-jms-beans.xml");
-      EJB3StandaloneBootstrap.deployXmlResource("embeddedjms/testjms.xml");
-      EJB3StandaloneBootstrap.deployXmlResource("standard/testjms.xml");
-      EJB3StandaloneBootstrap.deployXmlResource("jca-inflowmdb-beans.xml");
+//      EJB3StandaloneBootstrap.deployXmlResource("embeddedjms/testjms.xml");
+//      EJB3StandaloneBootstrap.deployXmlResource("standard/testjms.xml");
+//      EJB3StandaloneBootstrap.deployXmlResource("jca-inflowmdb-beans.xml");
       
       if (test.xmlResources != null)
       {
@@ -146,7 +146,7 @@
          String testClass = (String)standardTests.next();
          StandardTestCaseTest test = (StandardTestCaseTest)tests.get(testClass);
          
-         System.out.println("!! testClass " + testClass);
+         System.out.println("Testing standard test " + testClass);
          
          startupEmbeddedJboss(test);
          EJB3StandaloneDeployer deployer = new EJB3StandaloneDeployer();




More information about the jboss-cvs-commits mailing list