[jboss-cvs] JBossAS SVN: r92102 - 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
Fri Aug 7 01:51:30 EDT 2009


Author: ALRubinger
Date: 2009-08-07 01:51:29 -0400 (Fri, 07 Aug 2009)
New Revision: 92102

Added:
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/ProtectedLocalBusiness.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/ProtectedService.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/RunAsRemoteBusiness.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/RunAsService.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/unit/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/unit/SecurityContextInServiceStartTestCase.java
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1738/
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1738/roles.properties
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1738/users.properties
Modified:
   projects/ejb3/trunk/testsuite/build-test.xml
Log:
[EJBTHREE-1738] Added integration test for @RunAs in @Service start()

Modified: projects/ejb3/trunk/testsuite/build-test.xml
===================================================================
--- projects/ejb3/trunk/testsuite/build-test.xml	2009-08-07 04:11:31 UTC (rev 92101)
+++ projects/ejb3/trunk/testsuite/build-test.xml	2009-08-07 05:51:29 UTC (rev 92102)
@@ -4297,6 +4297,19 @@
       </jar>
    </target>	
 
+	<target name="ejbthree1738">
+    <mkdir dir="${build.lib}"/>
+    <jar jarfile="${build.lib}/ejbthree1738.jar">
+      <fileset dir="${build.classes}">
+        <include name="org/jboss/ejb3/test/ejbthree1738/*.class"/>
+      </fileset>
+      <fileset dir="${resources}/test/ejbthree1738">
+        <include name="users.properties"/>
+        <include name="roles.properties"/>
+      </fileset>
+    </jar>
+	</target>
+
 	<target name="ejbthree1786">
 	   <build-simple-jar name="ejbthree1786"/>
 	</target> 
@@ -4357,7 +4370,7 @@
       ejbthree1066, ejbthree1071, ejbthree1075, ejbthree1786, ejbthree1082, ejbthree1090, ejbthree1092, ejbthree1116, ejbthree1119, ejbthree1122, ejbthree1123, ejbthree1127,
       ejbthree1130, 
       ejbthree1146, ejbthree1148, ejbthree1154, ejbthree1157, ejbthree1222, ejbthree1271, ejbthree1339,
-      ejbthree1504, ejbthree1530, ejbthree1624, ejbthree1647,
+      ejbthree1504, ejbthree1530, ejbthree1624, ejbthree1647,ejbthree1738,
       ejbthree1852,
    	  jaxws, jbas4489, epcpropagation, aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency,
       securitydomain, enventry, security5,
@@ -5185,6 +5198,9 @@
          <param name="test" value="ejbthree1647"/>
    	  </antcall>
       <antcall target="test" inheritRefs="true">
+         <param name="test" value="ejbthree1738"/>
+      </antcall>
+      <antcall target="test" inheritRefs="true">
          <param name="test" value="ejbthree1852"/>
       </antcall>
       <antcall target="test" inheritRefs="true">

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/ProtectedLocalBusiness.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/ProtectedLocalBusiness.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/ProtectedLocalBusiness.java	2009-08-07 05:51:29 UTC (rev 92102)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejbthree1738;
+
+/**
+ * ProtectedLocalBusiness
+ * 
+ * Local business interface of operations that will 
+ * be protected by a security domain
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface ProtectedLocalBusiness
+{
+
+   //------------------------------------------------------------------------||
+   // Constants -------------------------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * The value to return in {@link ProtectedLocalBusiness#getValue()}
+    */
+   String VALUE = "Protected Value";
+
+   /**
+    * Security Domain under which we're protected
+    */
+   String SECURITY_DOMAIN = "other";
+
+   /**
+    * The role which is allowed to run these methods
+    */
+   String ROLE_ALLOWED = "authorized";
+
+   //------------------------------------------------------------------------||
+   // Contracts -------------------------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * Returns the contracted value {@link ProtectedLocalBusiness#VALUE}
+    */
+   String getValue();
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/ProtectedService.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/ProtectedService.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/ProtectedService.java	2009-08-07 05:51:29 UTC (rev 92102)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejbthree1738;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.Local;
+
+import org.jboss.ejb3.annotation.SecurityDomain;
+import org.jboss.ejb3.annotation.Service;
+
+/**
+ * ProtectedService
+ * 
+ * A Service Bean which runs protected under a security domain
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Service
+ at SecurityDomain(ProtectedLocalBusiness.SECURITY_DOMAIN)
+ at RolesAllowed(ProtectedLocalBusiness.ROLE_ALLOWED)
+ at Local(ProtectedLocalBusiness.class)
+public class ProtectedService implements ProtectedLocalBusiness
+{
+   //------------------------------------------------------------------------||
+   // Required Implementations ----------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.test.ejbthree1738.unit.ProtectedLocalBusiness#getValue()
+    */
+   public String getValue()
+   {
+      return ProtectedLocalBusiness.VALUE;
+   }
+
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/RunAsRemoteBusiness.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/RunAsRemoteBusiness.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/RunAsRemoteBusiness.java	2009-08-07 05:51:29 UTC (rev 92102)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejbthree1738;
+
+/**
+ * RunAsLocalBusiness
+ * 
+ * Local business interface of operations that will 
+ * be run as another identity
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface RunAsRemoteBusiness
+{
+   //------------------------------------------------------------------------||
+   // Constants -------------------------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * JNDI Name to which this Service will be bound
+    */
+   String JNDI_NAME = "RunAs/remote";
+
+   //------------------------------------------------------------------------||
+   // Contracts -------------------------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * Delegates to a protected service {@link ProtectedLocalBusiness#getValue()}
+    * as cached from a lookup to the protected service during start()
+    */
+   String getProtectedValueObtainedFromStart();
+
+   /**
+    * Obtains the String value directly from the service
+    * 
+    * @return
+    */
+   String getValueFromProtectedService();
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/RunAsService.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/RunAsService.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/RunAsService.java	2009-08-07 05:51:29 UTC (rev 92102)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejbthree1738;
+
+import javax.annotation.security.PermitAll;
+import javax.annotation.security.RunAs;
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+
+import org.jboss.ejb3.annotation.RemoteBinding;
+import org.jboss.ejb3.annotation.SecurityDomain;
+import org.jboss.ejb3.annotation.Service;
+import org.jboss.logging.Logger;
+
+/**
+ * RunAsService
+ * 
+ * A Service Bean which executes under an authorized
+ * identity.  
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Service
+ at SecurityDomain(ProtectedLocalBusiness.SECURITY_DOMAIN)
+ at PermitAll
+ at RunAs(ProtectedLocalBusiness.ROLE_ALLOWED)
+ at Remote(RunAsRemoteBusiness.class)
+ at RemoteBinding(jndiBinding = RunAsRemoteBusiness.JNDI_NAME)
+public class RunAsService implements RunAsRemoteBusiness
+{
+
+   //------------------------------------------------------------------------||
+   // Class Members ---------------------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(RunAsService.class);
+
+   //------------------------------------------------------------------------||
+   // Instance Members ------------------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * Cached value obtained during bean start() from
+    * the protected service
+    */
+   private String value;
+
+   /**
+    * Protected service from which we'll get a value
+    */
+   @EJB
+   private ProtectedLocalBusiness protectedService;
+
+   //------------------------------------------------------------------------||
+   // Required Implementations ----------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.test.ejbthree1738.unit.RunAsLocalBusiness#getProtectedValue()
+    */
+   public String getProtectedValueObtainedFromStart()
+   {
+      return value;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.ejb3.test.ejbthree1738.RunAsRemoteBusiness#getValueFromProtectedService()
+    */
+   public String getValueFromProtectedService()
+   {
+      return protectedService.getValue();
+   }
+
+   //------------------------------------------------------------------------||
+   // Lifecycle -------------------------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * Callback by the container, invoked on start.  Here we try to get
+    * a value from the protected service to see if the security context 
+    * is set up properly.
+    */
+   public void start() throws Exception
+   {
+      log.info("Start");
+      log.info("Attempting to get value from protected service");
+      try
+      {
+         value = protectedService.getValue();
+      }
+      catch (final Exception e)
+      {
+         log.error("Could not get value from protected service in lifecycle start(): " + e.getMessage());
+         return;
+      }
+      log.info("Got value from protected service: " + value);
+   }
+
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/unit/SecurityContextInServiceStartTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/unit/SecurityContextInServiceStartTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/unit/SecurityContextInServiceStartTestCase.java	2009-08-07 05:51:29 UTC (rev 92102)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejbthree1738.unit;
+
+import javax.naming.Context;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.ejbthree1738.ProtectedLocalBusiness;
+import org.jboss.ejb3.test.ejbthree1738.RunAsRemoteBusiness;
+import org.jboss.logging.Logger;
+import org.jboss.security.client.SecurityClient;
+import org.jboss.security.client.SecurityClientFactory;
+import org.jboss.test.JBossTestCase;
+import org.junit.Assert;
+
+/**
+ * SecurityContextInServiceStartTestCase
+ * 
+ * Test Cases to ensure that we may invoke within a 
+ * security context in @Service bean lifecycle start()
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class SecurityContextInServiceStartTestCase extends JBossTestCase
+{
+   //------------------------------------------------------------------------||
+   // Class Members ---------------------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(SecurityContextInServiceStartTestCase.class);
+
+   //------------------------------------------------------------------------||
+   // Instance Members ------------------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * The EJB used to test security context in start() lifecycle
+    */
+   private RunAsRemoteBusiness bean;
+
+   //------------------------------------------------------------------------||
+   // Constructor -----------------------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * Constructor
+    */
+   public SecurityContextInServiceStartTestCase()
+   {
+      super(SecurityContextInServiceStartTestCase.class.getName());
+   }
+
+   //------------------------------------------------------------------------||
+   // Suite -----------------------------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * Defines the Suite
+    */
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(SecurityContextInServiceStartTestCase.class, "ejbthree1738.jar");
+   }
+
+   //------------------------------------------------------------------------||
+   // Tests -----------------------------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * Ensures that we may invoke within the context of a security 
+    * domain as a defined role while in the start() lifecycle 
+    * of a @Service bean
+    */
+
+   public void testSecurityContextInServiceStart() throws Throwable
+   {
+      // Log
+      log.info("testSecurityContextInServiceStart");
+
+      // Log in as some user (with "unauthorized" role)
+      SecurityClient client = SecurityClientFactory.getSecurityClient();
+      client.setSimple("someuser", "password");
+      client.login();
+
+      // Get the bean
+      final RunAsRemoteBusiness bean = this.getBean();
+
+      // Get the value from a protected service lookup; the @RunAs should change the role used to "authorized"
+      final String valueFromBusinessInvocation = bean.getValueFromProtectedService();
+      // Ensure the value is correct
+      Assert
+            .assertEquals("The obtained value was incorrect", ProtectedLocalBusiness.VALUE, valueFromBusinessInvocation);
+
+      // Get the value which should be set upon instance start()
+      final String valueFromStart = bean.getProtectedValueObtainedFromStart();
+
+      // Ensure the value's set
+      Assert.assertNotNull("The value from the protected bean was not set", valueFromStart);
+      // Ensure the value is correct
+      Assert.assertEquals("The obtained value was incorrect", ProtectedLocalBusiness.VALUE, valueFromStart);
+   }
+
+   //------------------------------------------------------------------------||
+   // Internal Helper Methods -----------------------------------------------||
+   //------------------------------------------------------------------------||
+
+   /**
+    * Obtains the EJB via which we'll access the endpoint
+    */
+   private RunAsRemoteBusiness getBean() throws Throwable
+   {
+      // If we haven't yet getten the bean
+      if (bean == null)
+      {
+         // Look it up and set
+         final Context context = this.getInitialContext();
+         bean = (RunAsRemoteBusiness) context.lookup(RunAsRemoteBusiness.JNDI_NAME);
+      }
+
+      // Return
+      return bean;
+   }
+}


Property changes on: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1738/unit/SecurityContextInServiceStartTestCase.java
___________________________________________________________________
Name: svn:executable
   + *

Added: projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1738/roles.properties
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1738/roles.properties	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1738/roles.properties	2009-08-07 05:51:29 UTC (rev 92102)
@@ -0,0 +1,2 @@
+authorizeduser=authorized
+someuser=unauthorized


Property changes on: projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1738/roles.properties
___________________________________________________________________
Name: svn:executable
   + *

Added: projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1738/users.properties
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1738/users.properties	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1738/users.properties	2009-08-07 05:51:29 UTC (rev 92102)
@@ -0,0 +1,2 @@
+authorizeduser=password
+someuser=password


Property changes on: projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1738/users.properties
___________________________________________________________________
Name: svn:executable
   + *




More information about the jboss-cvs-commits mailing list