[jboss-cvs] JBossAS SVN: r63254 - in trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed May 30 10:39:20 EDT 2007


Author: wolfc
Date: 2007-05-30 10:39:19 -0400 (Wed, 30 May 2007)
New Revision: 63254

Added:
   trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/RunAsSpyBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/SpyAllowedBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/SpyMe.java
Modified:
   trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/WhoAmIMDB.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/unit/AnonymousCallerPrincipalTestCase.java
Log:
EJBTHREE-973: tests using RunAs

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/RunAsSpyBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/RunAsSpyBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/RunAsSpyBean.java	2007-05-30 14:39:19 UTC (rev 63254)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.ejbthree973;
+
+import javax.annotation.security.RunAs;
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import org.jboss.annotation.security.SecurityDomain;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(SpyMe.class)
+ at RunAs("Spy")
+ at SecurityDomain(value="", unauthenticatedPrincipal="anonymous")
+public class RunAsSpyBean implements SpyMe
+{
+   @EJB(beanName="SpyAllowedBean")
+   private SpyMe spyAllowedBean;
+   
+   public String getCallerPrincipal()
+   {
+      return spyAllowedBean.getCallerPrincipal();
+   }
+
+   public void notAllowed()
+   {
+      spyAllowedBean.notAllowed();
+   }
+}


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

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/SpyAllowedBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/SpyAllowedBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/SpyAllowedBean.java	2007-05-30 14:39:19 UTC (rev 63254)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.ejbthree973;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import org.jboss.annotation.security.SecurityDomain;
+
+/**
+ * Only Spy is allowed to call me.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(SpyMe.class)
+ at SecurityDomain(value="", unauthenticatedPrincipal="anonymous")
+ at RolesAllowed("Spy")
+public class SpyAllowedBean implements SpyMe
+{
+   @EJB(beanName="WhoAmIBean")
+   private WhoAmI whoAmIBean;
+   
+   public String getCallerPrincipal()
+   {
+      return whoAmIBean.getCallerPrincipal();
+   }
+
+   @RolesAllowed("nobody")
+   public void notAllowed()
+   {
+      throw new RuntimeException("should not come here");
+   }
+
+}


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

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/SpyMe.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/SpyMe.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/SpyMe.java	2007-05-30 14:39:19 UTC (rev 63254)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.ejbthree973;
+
+/**
+ * Allows for some security checks.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface SpyMe extends WhoAmI
+{
+   void notAllowed();
+}


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

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/WhoAmIMDB.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/WhoAmIMDB.java	2007-05-30 13:52:15 UTC (rev 63253)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/WhoAmIMDB.java	2007-05-30 14:39:19 UTC (rev 63254)
@@ -22,6 +22,7 @@
 package org.jboss.ejb3.test.ejbthree973;
 
 import javax.annotation.Resource;
+import javax.annotation.security.RunAs;
 import javax.ejb.ActivationConfigProperty;
 import javax.ejb.MessageDriven;
 import javax.ejb.MessageDrivenContext;
@@ -48,6 +49,7 @@
       @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
       @ActivationConfigProperty(propertyName="destination", propertyValue="queue/whoAmI")
       })
+ at RunAs("Spy")
 @SecurityDomain(value="", unauthenticatedPrincipal="anonymous")
 public class WhoAmIMDB implements MessageListener
 {
@@ -67,6 +69,7 @@
          }
          catch(IllegalStateException e)
          {
+            e.printStackTrace();
             sendReplyOrThrow(message, e);
          }
       }

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/unit/AnonymousCallerPrincipalTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/unit/AnonymousCallerPrincipalTestCase.java	2007-05-30 13:52:15 UTC (rev 63253)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/unit/AnonymousCallerPrincipalTestCase.java	2007-05-30 14:39:19 UTC (rev 63254)
@@ -21,6 +21,7 @@
  */
 package org.jboss.ejb3.test.ejbthree973.unit;
 
+import javax.ejb.EJBAccessException;
 import javax.jms.DeliveryMode;
 import javax.jms.MessageConsumer;
 import javax.jms.Queue;
@@ -32,6 +33,7 @@
 
 import junit.framework.Test;
 
+import org.jboss.ejb3.test.ejbthree973.SpyMe;
 import org.jboss.ejb3.test.ejbthree973.WhoAmI;
 import org.jboss.security.SecurityAssociation;
 import org.jboss.security.SimplePrincipal;
@@ -68,10 +70,17 @@
    public void testAnybody() throws Exception
    {
       SecurityAssociation.setPrincipal(new SimplePrincipal("anybody"));
-      WhoAmI bean = lookupBean();
-      String actual = bean.getCallerPrincipal();
-      // "anonymous" is defined in the @SecurityDomain on WhoAmIBean
-      assertEquals("anonymous", actual);
+      try
+      {
+         WhoAmI bean = lookupBean();
+         String actual = bean.getCallerPrincipal();
+         // "anonymous" is defined in the @SecurityDomain on WhoAmIBean
+         assertEquals("anonymous", actual);
+      }
+      finally
+      {
+         SecurityAssociation.setPrincipal(null);
+      }
    }
    
    public void testMDB() throws Exception
@@ -104,6 +113,25 @@
       }
    }
    
+   public void testSpy() throws Exception
+   {
+      SpyMe bean = (SpyMe) getInitialContext().lookup("RunAsSpyBean/remote");
+      
+      try
+      {
+         bean.notAllowed();
+         fail("Calling notAllowed anonymously should not be allowed");
+      }
+      catch(EJBAccessException e)
+      {
+         // this is good
+      }
+      
+      String actual = bean.getCallerPrincipal();
+      // "anonymous" is defined in the @SecurityDomain on WhoAmIBean
+      assertEquals("anonymous", actual);
+   }
+   
    public static Test suite() throws Exception
    {
       return getDeploySetup(AnonymousCallerPrincipalTestCase.class, "ejbthree973test-service.xml,ejbthree973.jar");




More information about the jboss-cvs-commits mailing list