[jboss-cvs] JBossAS SVN: r106358 - in projects/ejb3/trunk/testsuite: src/test/java/org/jboss/ejb3/test and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 1 06:11:55 EDT 2010


Author: wolfc
Date: 2010-07-01 06:11:55 -0400 (Thu, 01 Jul 2010)
New Revision: 106358

Added:
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/Caller.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/CallerWithIdentity.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/StatelessABean.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/StatelessBBean.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/WhoAmI.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/unit/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/unit/RunAsPrincipalTestCase.java
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1945/
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1945/roles.properties
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1945/users.properties
Modified:
   projects/ejb3/trunk/testsuite/build-test.xml
Log:
EJBTHREE-1945: unit test

Modified: projects/ejb3/trunk/testsuite/build-test.xml
===================================================================
--- projects/ejb3/trunk/testsuite/build-test.xml	2010-07-01 03:50:53 UTC (rev 106357)
+++ projects/ejb3/trunk/testsuite/build-test.xml	2010-07-01 10:11:55 UTC (rev 106358)
@@ -4189,6 +4189,16 @@
 	      <build-simple-jar name="ejbthree1926"/>
 	</target>
     	
+   <target name="ejbthree1945">
+      <mkdir dir="${build.lib}"/>
+      <jar jarfile="${build.lib}/ejbthree1945.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/ejbthree1945/*.class"/>
+         </fileset>
+         <fileset dir="${resources}/test/ejbthree1945"/>
+      </jar>
+   </target>
+
    <target name="ejbthree1995">
       <mkdir dir="${build.lib}"/>
       <jar jarfile="${build.lib}/ejbthree1995.jar">
@@ -4249,6 +4259,7 @@
       ejbthree1504, ejbthree1530, ejbthree1624, ejbthree1647,ejbthree1738,
       ejbthree1852,
       ejbthree1889,
+      ejbthree1945,
       ejbthree1995,
       ejbthree2095,
    	  jaxws, jbas4489, epcpropagation, aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency,
@@ -5081,6 +5092,9 @@
          <param name="test" value="ejbthree1889"/>
       </antcall>
       <antcall target="test" inheritRefs="true">
+         <param name="test" value="ejbthree1945"/>
+      </antcall>
+      <antcall target="test" inheritRefs="true">
          <param name="test" value="ejbthree1995"/>
       </antcall>
      <antcall target="test" inheritRefs="true">

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/Caller.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/Caller.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/Caller.java	2010-07-01 10:11:55 UTC (rev 106358)
@@ -0,0 +1,47 @@
+/*
+ * 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.test.ejbthree1945;
+
+import org.jboss.ejb3.annotation.SecurityDomain;
+
+import javax.annotation.security.RunAs;
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Stateless
+ at Remote(WhoAmI.class)
+ at RunAs("Admin")
+ at SecurityDomain("other")
+public class Caller implements WhoAmI
+{
+   @EJB(beanName = "StatelessBBean")
+   private WhoAmI beanB;
+   
+   public String getCallerPrincipal()
+   {
+      return beanB.getCallerPrincipal();
+   }
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/CallerWithIdentity.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/CallerWithIdentity.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/CallerWithIdentity.java	2010-07-01 10:11:55 UTC (rev 106358)
@@ -0,0 +1,49 @@
+/*
+ * 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.test.ejbthree1945;
+
+import org.jboss.ejb3.annotation.RunAsPrincipal;
+import org.jboss.ejb3.annotation.SecurityDomain;
+
+import javax.annotation.security.RunAs;
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Stateless
+ at Remote(WhoAmI.class)
+ at RunAs("Admin")
+ at RunAsPrincipal("jackinabox")
+ at SecurityDomain("other")
+public class CallerWithIdentity implements WhoAmI
+{
+   @EJB(beanName = "StatelessBBean")
+   private WhoAmI beanB;
+   
+   public String getCallerPrincipal()
+   {
+      return beanB.getCallerPrincipal();
+   }
+}
\ No newline at end of file

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/StatelessABean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/StatelessABean.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/StatelessABean.java	2010-07-01 10:11:55 UTC (rev 106358)
@@ -0,0 +1,47 @@
+/*
+ * 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.test.ejbthree1945;
+
+import org.jboss.ejb3.annotation.SecurityDomain;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Stateless
+ at Local(WhoAmI.class)
+ at RolesAllowed("Admin")
+ at SecurityDomain("other")
+public class StatelessABean implements WhoAmI
+{
+   @EJB(beanName = "StatelessCBean")
+   private WhoAmI beanC;
+
+   public String getCallerPrincipal()
+   {
+      return beanC.getCallerPrincipal();
+   }
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/StatelessBBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/StatelessBBean.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/StatelessBBean.java	2010-07-01 10:11:55 UTC (rev 106358)
@@ -0,0 +1,48 @@
+/*
+ * 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.test.ejbthree1945;
+
+import org.jboss.ejb3.annotation.SecurityDomain;
+
+import javax.annotation.Resource;
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.Local;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Stateless
+ at Local(WhoAmI.class)
+ at RolesAllowed("Admin")
+ at SecurityDomain("other")
+public class StatelessBBean implements WhoAmI
+{
+   @Resource
+   private SessionContext ctx;
+
+   public String getCallerPrincipal()
+   {
+      return ctx.getCallerPrincipal().getName();
+   }
+}
\ No newline at end of file

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/WhoAmI.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/WhoAmI.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/WhoAmI.java	2010-07-01 10:11:55 UTC (rev 106358)
@@ -0,0 +1,30 @@
+/*
+ * 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.test.ejbthree1945;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public interface WhoAmI
+{
+   String getCallerPrincipal();
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/unit/RunAsPrincipalTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/unit/RunAsPrincipalTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1945/unit/RunAsPrincipalTestCase.java	2010-07-01 10:11:55 UTC (rev 106358)
@@ -0,0 +1,99 @@
+/*
+ * 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.test.ejbthree1945.unit;
+
+import junit.framework.Test;
+import org.jboss.ejb3.test.common.EJB3TestCase;
+import org.jboss.ejb3.test.ejbthree1945.WhoAmI;
+import org.jboss.security.client.SecurityClient;
+import org.jboss.security.client.SecurityClientFactory;
+
+import javax.ejb.EJBAccessException;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class RunAsPrincipalTestCase extends EJB3TestCase
+{
+   public RunAsPrincipalTestCase(String name)
+   {
+      super(name);
+   }
+
+   private WhoAmI lookupBean() throws Exception
+   {
+      return (WhoAmI) getInitialContext().lookup("Caller/remote");
+   }
+
+   public void testJackInABox() throws Exception
+   {
+      SecurityClient client = SecurityClientFactory.getSecurityClient();
+      client.setSimple("thomas", "valid");
+      client.login();
+      try
+      {
+         WhoAmI bean = lookup("CallerWithIdentity/remote", WhoAmI.class);
+         String actual = bean.getCallerPrincipal();
+         assertEquals("jackinabox", actual);
+      }
+      finally
+      {
+         client.logout();
+      }
+   }
+
+   public void testRunAsPrincipal() throws Exception
+   {
+      WhoAmI bean = lookupBean();
+      try
+      {
+         bean.getCallerPrincipal();
+         fail("Expected EJBAccessException");
+      }
+      catch(EJBAccessException e)
+      {
+         // good
+      }
+   }
+
+   public void testThomas() throws Exception
+   {
+      SecurityClient client = SecurityClientFactory.getSecurityClient();
+      client.setSimple("thomas", "valid");
+      client.login();
+      try
+      {
+         WhoAmI bean = lookupBean();
+         String actual = bean.getCallerPrincipal();
+         assertEquals("anonymous", actual);
+      }
+      finally
+      {
+         client.logout();
+      }
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(RunAsPrincipalTestCase.class, "ejbthree1945.jar");
+   }
+}

Copied: projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1945/roles.properties (from rev 106230, projects/ejb3/trunk/testsuite/src/test/resources/test/security/roles.properties)
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1945/roles.properties	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1945/roles.properties	2010-07-01 10:11:55 UTC (rev 106358)
@@ -0,0 +1,2 @@
+thomas=User
+#thomas.CallerPrincipal=thomas

Copied: projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1945/users.properties (from rev 106230, projects/ejb3/trunk/testsuite/src/test/resources/test/security/users.properties)
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1945/users.properties	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1945/users.properties	2010-07-01 10:11:55 UTC (rev 106358)
@@ -0,0 +1 @@
+thomas=valid
\ No newline at end of file



More information about the jboss-cvs-commits mailing list