[jboss-cvs] JBossAS SVN: r61351 - in branches/Branch_4_2/testsuite: src/main/org/jboss/test/security/ejb and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 15 15:35:49 EDT 2007


Author: anil.saldhana at jboss.com
Date: 2007-03-15 15:35:49 -0400 (Thu, 15 Mar 2007)
New Revision: 61351

Added:
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/security/ejb/SFSBTxSynchronizationBean.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/security/test/ejb/
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/security/test/ejb/SFSBIntegrationTestCase.java
   branches/Branch_4_2/testsuite/src/resources/security/sfsb/
   branches/Branch_4_2/testsuite/src/resources/security/sfsb/ejb-jar.xml
   branches/Branch_4_2/testsuite/src/resources/security/sfsb/jboss.xml
   branches/Branch_4_2/testsuite/src/resources/security/sfsb/login-service.xml
   branches/Branch_4_2/testsuite/src/resources/security/sfsb/sfsb-integration-security-config.xml
Modified:
   branches/Branch_4_2/testsuite/imports/sections/security.xml
Log:
JBAS-3876: SFSB integration test cases

Modified: branches/Branch_4_2/testsuite/imports/sections/security.xml
===================================================================
--- branches/Branch_4_2/testsuite/imports/sections/security.xml	2007-03-15 19:33:53 UTC (rev 61350)
+++ branches/Branch_4_2/testsuite/imports/sections/security.xml	2007-03-15 19:35:49 UTC (rev 61351)
@@ -421,5 +421,20 @@
        </fileset>
      </jar>
 
+     <!-- SFSB Integration Security Tests --> 
+      <jar destfile="${build.lib}/sfsb-security-integration.jar">
+         <metainf dir="${build.resources}/security/sfsb">
+            <include name="ejb-jar.xml"/>
+            <include name="jboss.xml"/>
+            <include name="sfsb*-config.xml"/>
+         </metainf>
+         <fileset dir="${build.resources}/security/sfsb">
+            <include name="login-service.xml"/>
+         </fileset>
+         <fileset dir="${build.classes}"> 
+            <include name="org/jboss/test/security/ejb/SFSB**"/>
+            <include name="org/jboss/test/security/interfaces/Stateful**"/>
+         </fileset>
+      </jar>  
    </target>
 </project>

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/security/ejb/SFSBTxSynchronizationBean.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/security/ejb/SFSBTxSynchronizationBean.java	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/security/ejb/SFSBTxSynchronizationBean.java	2007-03-15 19:35:49 UTC (rev 61351)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.test.security.ejb;
+
+import java.rmi.RemoteException;
+import java.security.Principal;
+import javax.ejb.CreateException; 
+import javax.ejb.EJBException;
+import javax.ejb.SessionBean;
+import javax.ejb.SessionContext;
+import javax.ejb.SessionSynchronization;
+
+import org.apache.log4j.Logger;
+
+/**
+ * SFSB that has the session synchronization methods that invoke
+ * the getCallerPrincipal (Reference: JBAS-4087)
+ *
+ * @author Anil.Saldhana at redhat.com
+ * @version $Revision: 57211 $
+ */
+public class SFSBTxSynchronizationBean implements SessionBean,SessionSynchronization
+{ 
+   private static final long serialVersionUID = 1L;
+   
+   private static Logger log = Logger.getLogger(SFSBTxSynchronizationBean.class);
+   private SessionContext sessionContext;
+   private String state;
+
+   public void ejbCreate(String state) throws CreateException
+   {
+      this.state = state;
+      log.debug("ejbCreate("+state+") called");
+      Principal p = sessionContext.getCallerPrincipal();
+      log.debug("ejbCreate, callerPrincipal="+p);
+   }
+
+   public void ejbActivate()
+   {
+      log.debug("ejbActivate() called");
+   }
+
+   public void ejbPassivate()
+   {
+      log.debug("ejbPassivate() called");
+   }
+
+   public void ejbRemove()
+   {
+      log.debug("ejbRemove() called");
+   }
+
+   public void setSessionContext(SessionContext context)
+   {
+      sessionContext = context;
+   }
+
+   public String echo(String arg)
+   {
+      log.debug("echo, arg="+arg);
+      Principal p = sessionContext.getCallerPrincipal();
+      log.debug("echo, callerPrincipal="+p);
+      return arg;
+   }
+
+   public void afterBegin() throws EJBException, RemoteException
+   {  
+      Principal p = sessionContext.getCallerPrincipal();
+      log.error("afterBegin():callerPrincipal="+p);
+   }
+
+   public void afterCompletion(boolean committed) throws EJBException, RemoteException
+   {  
+      Principal p = sessionContext.getCallerPrincipal();
+      log.error("afterCompletion:callerPrincipal="+p);
+   }
+
+   public void beforeCompletion() throws EJBException, RemoteException
+   {  
+      Principal p = sessionContext.getCallerPrincipal();
+      log.error("beforeCompletion():callerPrincipal="+p);
+   }
+}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/security/test/ejb/SFSBIntegrationTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/security/test/ejb/SFSBIntegrationTestCase.java	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/security/test/ejb/SFSBIntegrationTestCase.java	2007-03-15 19:35:49 UTC (rev 61351)
@@ -0,0 +1,97 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2007, 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.test.security.test.ejb;
+
+import javax.naming.InitialContext;
+import javax.rmi.PortableRemoteObject;
+import javax.security.auth.login.Configuration; 
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.security.auth.login.XMLLoginConfigImpl;
+import org.jboss.test.JBossTestCase; 
+import org.jboss.test.JBossTestSetup;
+import org.jboss.test.security.interfaces.StatefulSession;
+import org.jboss.test.security.interfaces.StatefulSessionHome;  
+
+/**
+ *  Stateful Session Beans Integration Tests
+ *  JBAS-3976: Null security context exception thrown for no login
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Mar 15, 2007 
+ *  @version $Revision$
+ */
+public class SFSBIntegrationTestCase extends JBossTestCase
+{   
+   public SFSBIntegrationTestCase(String name)
+   {
+      super(name); 
+   } 
+  
+   /**
+    * Call a SFSB method that has container transaction and each of
+    * the SessionSynchronization callback methods call the getCallerPrincipal
+    * @throws Exception
+    */
+   public void testCallerPrincipalInSessionSynchronization() throws Exception
+   { 
+      InitialContext jndiContext = new InitialContext();
+      Object obj = jndiContext.lookup("spec.StatefulSession");
+      obj = PortableRemoteObject.narrow(obj, StatefulSessionHome.class);
+      StatefulSessionHome home = (StatefulSessionHome) obj;
+      log.debug("Found StatefulSessionHome");
+      // The create should be allowed to call getCallerPrincipal
+      StatefulSession bean = home.create("testStatefulCreateCaller");
+      // Need to invoke a method to ensure an ejbCreate call
+      bean.echo("testStatefulCreateCaller"); 
+   } 
+   
+   /**
+    * Setup the test suite.
+    */
+   public static Test suite() throws Exception
+   {
+      TestSuite suite = new TestSuite();
+      suite.addTest(new TestSuite(SFSBIntegrationTestCase.class));
+
+      // Create an initializer for the test suite
+      TestSetup wrapper = new JBossTestSetup(suite)
+      {
+         protected void setUp() throws Exception
+         {
+            super.setUp();
+            Configuration.setConfiguration(new XMLLoginConfigImpl());
+            redeploy("sfsb-security-integration.jar");
+            flushAuthCache();
+         }
+         protected void tearDown() throws Exception
+         {
+            undeploy("sfsb-security-integration.jar");
+            super.tearDown();
+         
+         }
+      };
+      return wrapper;
+   } 
+}

Added: branches/Branch_4_2/testsuite/src/resources/security/sfsb/ejb-jar.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/security/sfsb/ejb-jar.xml	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/resources/security/sfsb/ejb-jar.xml	2007-03-15 19:35:49 UTC (rev 61351)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE ejb-jar PUBLIC
+      "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
+      "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+   <display-name>SFSB Integration TESTS</display-name>
+   <enterprise-beans>
+      <session>
+         <description>A secured stateful session bean</description>
+         <ejb-name>StatefulSession</ejb-name>
+         <home>org.jboss.test.security.interfaces.StatefulSessionHome</home>
+         <remote>org.jboss.test.security.interfaces.StatefulSession</remote>
+         <ejb-class>org.jboss.test.security.ejb.SFSBTxSynchronizationBean</ejb-class>
+         <session-type>Stateful</session-type>
+         <transaction-type>Container</transaction-type>
+      </session>
+   </enterprise-beans>
+
+   <assembly-descriptor>
+      <security-role>
+         <description>The role required to invoke the echo method</description>
+         <role-name>Echo</role-name>
+      </security-role>  
+        <method-permission>
+        <unchecked/>
+        <method>
+           <ejb-name>StatefulSession</ejb-name>
+           <method-name>*</method-name>
+        </method>
+     </method-permission>
+      <container-transaction>
+         <method>
+            <ejb-name>StatefulSession</ejb-name>
+            <method-name>*</method-name>
+         </method>
+         <trans-attribute>Required</trans-attribute>
+      </container-transaction>
+   </assembly-descriptor>
+
+</ejb-jar>

Added: branches/Branch_4_2/testsuite/src/resources/security/sfsb/jboss.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/security/sfsb/jboss.xml	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/resources/security/sfsb/jboss.xml	2007-03-15 19:35:49 UTC (rev 61351)
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE jboss PUBLIC
+   "-//JBoss//DTD JBOSS 4.0//EN"
+   "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
+
+<!-- The jboss.xml descriptor for the security-spec.jar ejb unit.
+This descriptor redefines the JNDI names of the beans in the ejb-jar.xml
+descriptor so that there is no conflict with the security.jar deployment.
+-->
+<jboss>
+   <security-domain>
+      java:/jaas/sfsb-security-test
+   </security-domain>
+   <unauthenticated-principal>nobody</unauthenticated-principal>
+
+   <enterprise-beans>
+      <session>
+         <ejb-name>StatefulSession</ejb-name>
+         <jndi-name>spec.StatefulSession</jndi-name>
+      </session>
+   </enterprise-beans>
+</jboss>

Added: branches/Branch_4_2/testsuite/src/resources/security/sfsb/login-service.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/security/sfsb/login-service.xml	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/resources/security/sfsb/login-service.xml	2007-03-15 19:35:49 UTC (rev 61351)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+   <!-- The custom JAAS login configuration service that installs 
+       a Configuration capable of dynamically updating the
+       config settings
+   -->
+   <mbean code="org.jboss.security.auth.login.DynamicLoginConfig"
+         name="jboss.security.test.sfsb:service=DynamicLoginConfig">
+      <attribute name="AuthConfig">META-INF/sfsb-integration-security-config.xml</attribute>
+      <depends optional-attribute-name="LoginConfigService">
+         jboss.security:service=XMLLoginConfig
+      </depends>
+      <depends optional-attribute-name="SecurityManagerService">
+         jboss.security:service=JaasSecurityManager
+      </depends>
+   </mbean>
+
+</server>

Added: branches/Branch_4_2/testsuite/src/resources/security/sfsb/sfsb-integration-security-config.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/security/sfsb/sfsb-integration-security-config.xml	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/resources/security/sfsb/sfsb-integration-security-config.xml	2007-03-15 19:35:49 UTC (rev 61351)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xmlns="urn:jbosstest:caller-info"
+   targetNamespace="urn:jbosstest:caller-info" >
+
+   <application-policy name="sfsb-security-test">
+      <authentication>
+         <login-module code="org.jboss.security.auth.spi.XMLLoginModule" flag="required">
+            <module-option name="userInfo">
+               <lm:users xmlns:lm="http://www.jboss.org/j2ee/schemas/XMLLoginModule">
+                  <lm:user name="jduke" password="theduke">
+                     <lm:role name="Echo"/>
+                  </lm:user>
+               </lm:users>
+            </module-option>
+             <module-option name="unauthenticatedIdentity">guest</module-option>
+         </login-module>
+      </authentication>
+   </application-policy>
+</policy>




More information about the jboss-cvs-commits mailing list