[Jboss-cvs] JBossAS SVN: r56900 - in trunk/testsuite: . imports imports/sections src/main/org/jboss/test/security/test src/main/org/jboss/test/security/test/opends

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 15 15:33:35 EDT 2006


Author: anil.saldhana at jboss.com
Date: 2006-09-15 15:33:33 -0400 (Fri, 15 Sep 2006)
New Revision: 56900

Added:
   trunk/testsuite/src/main/org/jboss/test/security/test/opends/
   trunk/testsuite/src/main/org/jboss/test/security/test/opends/LdapBasicUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/security/test/opends/OpenDSService.java
   trunk/testsuite/src/main/org/jboss/test/security/test/opends/OpenDSUtil.java
Modified:
   trunk/testsuite/build.xml
   trunk/testsuite/imports/sections/security.xml
   trunk/testsuite/imports/server-config.xml
Log:
SECURITY-5:ldap integration in testsuite

Modified: trunk/testsuite/build.xml
===================================================================
--- trunk/testsuite/build.xml	2006-09-15 19:27:16 UTC (rev 56899)
+++ trunk/testsuite/build.xml	2006-09-15 19:33:33 UTC (rev 56900)
@@ -101,11 +101,13 @@
       <path refid="objectweb.joramtests.classpath"/>
       <path refid="opensaml.opensaml.classpath"/>
       <path refid="oswego.concurrent.classpath"/>
+      <path refid="sleepycat.classpath"/>
       <path refid="sun.jaf.classpath"/>
       <path refid="sun.javamail.classpath"/>
       <path refid="sun.jsf.classpath"/>
       <path refid="sun.servlet.classpath"/>
       <path refid="sun.xacml.classpath"/>
+      <path refid="sun.opends.classpath"/>
       <path refid="trove.classpath"/>
       <path refid="wutka.dtdparser.classpath"/>
       <path refid="codehaus.stax.classpath"/>
@@ -166,6 +168,7 @@
       <path refid="jboss.mbeans.classpath"/>
       <path refid="jboss.mq.classpath"/>
       <path refid="jboss.naming.classpath"/>
+      <path refid="jboss.security.spi.classpath"/>
       <path refid="jboss.security.classpath"/>
       <path refid="jboss.security.spi.classpath"/>
       <path refid="jboss.server.classpath"/>
@@ -398,8 +401,6 @@
          <exclude name="org/jboss/test/recover/derby/**"/>
          <exclude name="org/jboss/test/aop/bean/Annotated*" if="HAVE_JDK_1.5"/>
 	 <exclude name="org/jboss/test/xml/JaxpXPathBaseTestCase*" if="HAVE_JDK_1.4"/>
-         <exclude name="org/jboss/test/security/service/HttpsClient.java" if="IBM_JDK"/>
-	 <exclude name="org/jboss/test/security/test/HttpsUnitTestCase.java" if="IBM_JDK"/>
          <classpath refid="tests.classpath"/>
       </javac>
    </target>
@@ -634,6 +635,9 @@
    <patternset id="jacc.excludes">
 	<exclude name="**/test/jacc/test/*"/>
    </patternset>
+   <patternset id="ldap.includes">  
+      <include name="**/test/security/test/opends/*TestCase.class"/>
+   </patternset>
    <patternset id="jaxr.includes">
       <include name="org/jboss/test/jaxr/scout/**/*TestCase.class"/>
    </patternset>
@@ -671,12 +675,12 @@
       <include name="**/test/security/test/*UnitTestCase.class"/>
       <include name="**/test/security/test/auth/*UnitTestCase.class"/>
       <include name="**/test/security/test/authorization/XACML*UnitTest.class"/>
+      <include name="**/test/security/test/mapping/**/*TestCase.class"/>
       <include name="**/test/web/security/authorization/XACML*UnitTestCase.class"/>
       <include name="**/test/jca/test/SecurityContextUnitTestCase.class"/>
       <include name="**/test/jmx/test/Secure*TestCase.class"/>
       <include name="**/test/perf/test/SecurePerfStressTestCase.class"/>
       <include name="**/test/timer/test/SecureTimerUnitTestCase.class"/>
-      <exclude name="**/test/security/test/HttpsUnitTestCase.class" if="IBM_JDK"/>
    </patternset>
    <patternset id="security.excludes">
       <exclude name="**/test/naming/test/Security*"/>
@@ -848,12 +852,7 @@
 
    <target name="jboss-all-config-tests"
       description="The units tests which are run against the jboss all config">
-      <!-- Copy the test-destinations-service.xml to the all config.
-      -->
-      <copy file="${build.resources}/messaging/test-destinations-full-service.xml"
-         todir="${jboss.dist}/server/all/deploy" />
       <server:start name="all"/>
-
       <antcall target="tests-standard-unit"/>
       <antcall target="tests-client-unit"/>
       <antcall target="tests-security-basic-unit"/>
@@ -867,7 +866,6 @@
       <antcall target="tests-aspects"/>
 
       <server:stop name="all"/>
-      <delete file="${jboss.dist}/server/all/deploy/test-destinations-full-service.xml" quiet="true"/>
    </target>
 
    <target name="tests-apache-tomcat-clustering"
@@ -2432,6 +2430,54 @@
      <server:stop name="jaspi"/>
    </target>
 
+<!-- Ldap Tests-->
+   <target name="tests-ldap"
+      description="Tests run against a jboss server with opends configured"> 
+      <create-config baseconf="default" newconf="opends">
+         <patternset>
+            <include name="conf/**"/>
+            <include name="deploy/hsqldb-ds.xml"/>
+            <include name="deploy/jbossweb*.sar/**"/>
+            <include name="deploy/client-deployer-service.xml"/>
+            <include name="deploy/ear-deployer.xml"/>
+            <include name="deploy/ejb-deployer.xml"/>
+            <include name="deploy/jmx-invoker-service.xml"/>
+            <include name="deploy/jmx-console.war/**"/>
+            <include name="deploy/jbossjca-service.xml"/>
+            <include name="deploy/jboss-local-jdbc.rar"/>
+            <include name="deploy/jboss-aop.deployer/**"/>
+            <include name="deploy/jboss-aop-jdk50.deployer/**"/>
+            <include name="deploy/ejb3-interceptors-aop.xml"/>
+            <include name="deploy/ejb3.deployer/**"/>
+            <include name="deploy/properties**"/>
+            <include name="lib/**"/>
+         </patternset>
+      </create-config> 
+
+      <copy file="${build.lib}/opends.sar"
+        todir="${jboss.dist}/server/opends/deploy" />
+      <server:start name="opends"/>
+
+      <mkdir dir="${build.reports}"/>
+      <mkdir dir="${build.testlog}"/>
+
+     <property name="jbosstest.secure" value="true"/> 
+     <property name="java.security.auth.login.config"
+            value="${build.resources}/security/auth.conf"/> 
+     <property name="jboss.security.ldap.ctxfactory"
+            value="com.sun.jndi.ldap.LdapCtxFactory"/> 
+
+     <propertyset id="opends-tests-props">
+        <propertyref prefix="java.security.auth"/>
+	<propertyref prefix="jboss.security"/>
+     </propertyset>
+     <run-junit junit.patternset="ldap.includes"
+        junit.configuration="opends"
+	junit.syspropertyset="opends-tests-props" /> 
+      <server:stop name="opends"/> 
+   </target>
+
+
    <target name="tests-standalone-aop-unit">
       <!--
           <antcall target="tests-treecacheaop-unit" inheritRefs="true"/>

Modified: trunk/testsuite/imports/sections/security.xml
===================================================================
--- trunk/testsuite/imports/sections/security.xml	2006-09-15 19:27:16 UTC (rev 56899)
+++ trunk/testsuite/imports/sections/security.xml	2006-09-15 19:33:33 UTC (rev 56900)
@@ -340,5 +340,29 @@
        </fileset>
      </jar>
 
+   	<!-- opends-integration.jar -->
+   	      <jar destfile="${build.lib}/opends-integration.jar"> 
+   	         <fileset dir="${build.resources}/security/opends">
+   	           <include name="config/**"/>
+   	           <include name="locks"/>
+   	         </fileset> 
+   	      </jar>
+    	
+     <!-- opends.sar -->
+      <jar destfile="${build.lib}/opends.sar">
+         <metainf dir="${build.resources}/security/opends/META-INF"/>
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/test/security/test/opends/OpenDS*.class"/>
+         </fileset>
+      	<fileset dir="${build.lib}">
+      	   	 <include name="opends-integration.jar"/> 
+        </fileset> 
+         <fileset dir="${sun.opends.lib}">
+            <include name="OpenDS.jar"/>
+         </fileset>
+         <fileset dir="${sleepycat.lib}">
+            <include name="je.jar"/>
+         </fileset>
+      </jar>
    </target>
 </project>

Modified: trunk/testsuite/imports/server-config.xml
===================================================================
--- trunk/testsuite/imports/server-config.xml	2006-09-15 19:27:16 UTC (rev 56899)
+++ trunk/testsuite/imports/server-config.xml	2006-09-15 19:33:33 UTC (rev 56900)
@@ -114,6 +114,9 @@
       <server name="tomcat-sso" host="${node0}">
          <jvmarg value="${jpda.cmdline}" />
       </server>
+      <server name="opends" host="${node0}">
+         <jvmarg value="${jpda.cmdline}" />
+      </server>
       <server name="tomcat-webctx" host="${node0}">
           <jvmarg value="${jpda.cmdline}" />
       </server>

Added: trunk/testsuite/src/main/org/jboss/test/security/test/opends/LdapBasicUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/security/test/opends/LdapBasicUnitTestCase.java	2006-09-15 19:27:16 UTC (rev 56899)
+++ trunk/testsuite/src/main/org/jboss/test/security/test/opends/LdapBasicUnitTestCase.java	2006-09-15 19:33:33 UTC (rev 56900)
@@ -0,0 +1,138 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */ 
+package org.jboss.test.security.test.opends;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.test.JBossTestCase;
+import org.opends.server.tools.LDAPModify;
+
+/**
+ *  Basic tests for the ldap integration
+ *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ *  @version $Revision$
+ *  @since  Sep 13, 2006
+ */
+public class LdapBasicUnitTestCase extends JBossTestCase
+{  
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite();
+      suite.addTest(new LdapBasicUnitTestCase("testLdap")); 
+      suite.addTest(new LdapBasicUnitTestCase("testJNDI"));
+      return suite; 
+   }
+   
+   /**
+    * Inject the ldap initial ctx factory via system property
+    */
+   private String contextFactory = System.getProperty("jboss.security.ldap.ctxfactory",
+         "com.sun.jndi.ldap.LdapCtxFactory");
+   private OpenDSUtil util = new OpenDSUtil();
+   private String serverHost = getServerHost();
+   private String port = "1389";
+   private String adminDN = "cn=Directory Manager";
+   private String adminPW = "password";
+   private String dn = "dc=jboss,dc=org";
+   
+   public LdapBasicUnitTestCase(String name)
+   {
+      super(name); 
+   }
+    
+   /**
+    * Test if a DN exists. If not, add it. Then do a search. Then delete
+    * @throws Exception
+    */
+   public void testLdap() throws Exception
+   {   
+      if(util.existsDN(serverHost, port, dn))
+         util.deleteDN(serverHost, port, adminDN, adminPW, dn, true);
+      assertTrue("ldap add success?" , performLdifAdd());
+      assertTrue("ldap search success?" , util.existsDN(serverHost, port, dn));
+      assertTrue("ldap delete success?",
+            util.deleteDN(serverHost, port, adminDN, adminPW, dn, true));
+      assertFalse("ldap search should fail" , util.existsDN(serverHost, port, dn));
+   } 
+   
+   /**
+    * Test that JNDI operations work
+    * @throws Exception
+    */
+   public void testJNDI() throws Exception
+   {  
+      DirContext dc = null;
+      NamingEnumeration ne = null;
+      try
+      {
+         dc = this.getDirContext();
+         assertNotNull("DirContext exists?", dc);
+         if(util.existsDN(serverHost, port, dn))
+            util.deleteDN(serverHost, port, adminDN, adminPW, dn, true);
+         assertTrue("ldap add success?" , performLdifAdd());
+         SearchControls sc = new SearchControls();
+         sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
+         ne = dc.search(dn, "(objectclass=*)", sc);
+         while (ne.hasMore()) 
+         { 
+            SearchResult sr = (SearchResult) ne.next(); 
+            assertTrue("Search Result exists?", sr != null); 
+        }
+        assertTrue("ldap delete success?",
+               util.deleteDN(serverHost, port, adminDN, adminPW, dn, true));
+        assertFalse("ldap search should fail" , util.existsDN(serverHost, port, dn));
+      }
+      finally
+      {
+         if(ne != null)
+            ne.close();
+         if(dc != null)
+           dc.close(); 
+      } 
+   }
+ 
+   //***************************************************************
+   //   PRIVATE METHODS
+   //***************************************************************
+   private boolean performLdifAdd() throws Exception
+   {
+      String fileurl = this.getResourceURL("security/opends/ldif/example1.ldif");
+      URL url = this.getDeployURL(fileurl);
+      log.debug("ldap add ldif url="+url);
+      File file = new File(url.getPath()); 
+      String[] cmd = new String[] {"-h", getServerHost(), "-p",
+            "1389", "-D", "cn=Directory Manager",
+            "-w", "password",
+            "-a", "-f",file.getPath()};
+      
+      return LDAPModify.mainModify(cmd) == 0;
+   }
+   
+   private DirContext getDirContext() throws Exception
+   {
+      String url = "ldap://" + getServerHost() + ":1389";
+      Hashtable env = new Hashtable();
+      env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);
+      env.put(Context.PROVIDER_URL, url);
+      env.put(Context.SECURITY_AUTHENTICATION, "simple");
+      env.put(Context.SECURITY_PRINCIPAL, this.adminDN);
+      env.put(Context.SECURITY_CREDENTIALS, this.adminPW);
+      return new InitialDirContext(env);   
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/security/test/opends/OpenDSService.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/security/test/opends/OpenDSService.java	2006-09-15 19:27:16 UTC (rev 56899)
+++ trunk/testsuite/src/main/org/jboss/test/security/test/opends/OpenDSService.java	2006-09-15 19:33:33 UTC (rev 56900)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */ 
+package org.jboss.test.security.test.opends;
+
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.jboss.system.ServiceMBeanSupport;
+import org.opends.server.core.DirectoryServer;
+ 
+
+/**
+ *  XMBean Service for OpenDS integration
+ *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ *  @version $Revision$
+ *  @since  Sep 13, 2006
+ */
+public class OpenDSService extends ServiceMBeanSupport
+{
+   public static String objectName = "jboss.test:service=opends";
+   
+   private String newline = (String)
+            AccessController.doPrivileged(new GetSystemPropertyAction("line.separator"));  
+   
+   
+   /**
+    * Print some information about the DS (eg: connections etc)
+    * @return
+    */
+   public String printDiagnostics()
+   {
+     StringBuilder sb = new StringBuilder();
+     sb.append("Maximum concurrent client connections allowed:");
+     sb.append(DirectoryServer.getMaxAllowedConnections());
+     sb.append(newline).append("# of client connections currently established:");
+     sb.append(DirectoryServer.getCurrentConnections());
+     return sb.toString();
+   }
+   
+   /**
+    * Restart the Directory Server
+    */
+   public void restart()
+   {
+     DirectoryServer.restart(getClass().getName(), "DS restart");   
+   }
+   
+   protected void startService() throws Exception
+   {
+      super.startService();
+      
+      //Get the location of the conf directory
+      String confLoc = (String)AccessController.doPrivileged(
+            new GetSystemPropertyAction("jboss.server.config.url"));
+      
+      /**
+       * There seems to be a need to maintain the opends directory
+       * structure. We will create it under the conf dir
+       */
+      ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+      URL ldif = tcl.getResource("opends/config/config.ldif");
+      log.debug("config ldif="+ldif);
+      
+      String[] strArr = new String[] {"--configClass",
+                                    "org.opends.server.config.ConfigFileHandler",
+                                    "--configFile", 
+                                    ldif.getPath()}; 
+      //Start the OpenDS
+      DirectoryServer.main(strArr);
+   }
+
+   protected void stopService() throws Exception
+   { 
+      log.debug("Asking DS to shutdown"); 
+      DirectoryServer.shutDown(getClass().getName(), "Shut down DS");
+   }
+   
+   
+   /**
+    * 
+    * A GetSystemPropetyAction.
+    * 
+    * @author <a href="anil.saldhana at jboss.com">Anil Saldhana</a>
+    * @version $Revision: 1.1 $
+    */
+   public class GetSystemPropertyAction implements PrivilegedAction
+   { 
+      private String property;
+
+      public GetSystemPropertyAction(String prop)
+      {
+         this.property = prop;
+      }
+
+      public Object run()
+      {
+         return System.getProperty(property);
+      }
+   } 
+}
\ No newline at end of file

Added: trunk/testsuite/src/main/org/jboss/test/security/test/opends/OpenDSUtil.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/security/test/opends/OpenDSUtil.java	2006-09-15 19:27:16 UTC (rev 56899)
+++ trunk/testsuite/src/main/org/jboss/test/security/test/opends/OpenDSUtil.java	2006-09-15 19:33:33 UTC (rev 56900)
@@ -0,0 +1,155 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */ 
+package org.jboss.test.security.test.opends;
+
+import java.io.File;
+import java.net.URL;
+import java.util.StringTokenizer;
+
+import org.jboss.logging.Logger;
+import org.opends.server.tools.LDAPCompare;
+import org.opends.server.tools.LDAPDelete;
+import org.opends.server.tools.LDAPModify;
+import org.opends.server.tools.LDAPSearch;
+
+/**
+ *  Utility class that deals with the integrated ldap (OpenDS)
+ *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ *  @version $Revision$
+ *  @since  Sep 15, 2006
+ */
+public class OpenDSUtil
+{
+   private static final Logger log = Logger.getLogger(OpenDSUtil.class);
+   
+   public OpenDSUtil()
+   {  
+   }
+   
+   /**
+    * Add a LDIF file into the Directory Server
+    * @param serverHost Server Host (Use getServerHost() of JBossTestxxx)
+    * @param port Port for the DS
+    * @param admin admin dn ("cn=Directory Manager")
+    * @param adminpwd (password)
+    * @param ldifURL (use getDeployURL of JBossTestxxx)
+    * @return whether the add was success
+    */
+   public boolean addLDIF(String serverHost, String port, String admin,
+         String adminpwd, URL ldifURL)
+   {
+      File ldifFile = new File(ldifURL.getPath());
+      if(!ldifFile.exists())
+         throw new IllegalArgumentException("LDIF file:"+ ldifURL + " does not exist");
+      String[] cmd = new String[] {"-h", serverHost, "-p",
+            port, "-D", admin,
+            "-w", adminpwd, "-a", "-f",ldifFile.getPath()};
+      log.debug("addLDIF:" + print(cmd));
+      return LDAPModify.mainModify(cmd) == 0;
+   }
+   
+   /**
+    * Delete a DN in the Directory Server
+   * @param serverHost Server Host (Use getServerHost() of JBossTestxxx)
+    * @param port Port for the DS
+    * @param admin admin dn ("cn=Directory Manager")
+    * @param adminpwd (password)
+    * @param dnToDelete DN to delete (Eg: dc=jboss,dc=org)
+    * @param recursive should children also go?
+    * @return whether the delete op was success
+    */
+   public boolean deleteDN(String serverHost, String port, String admin,
+         String adminpwd, String dnToDelete, boolean recursive)
+   { 
+      String rec = recursive ? "-x" : " ";
+      
+      String[] cmd = new String[] {"-h", serverHost, "-p",
+            port, "-D", admin,
+            "-w", adminpwd, rec,dnToDelete};
+      log.debug("deleteDN:" + print(cmd)); 
+      return LDAPDelete.mainDelete(cmd) == 0;
+   }
+   
+   /**
+    * Check whether a DN exists. Typically before you do a ldap delete
+    * @param serverHost
+    * @param port
+    * @param dn
+    * @return whether the DN exists?
+    */
+   public boolean existsDN(String serverHost, String port, String dn)
+   {   
+      String[] cmd = new String[] {"-h", serverHost, "-p",
+            port, "-b", dn ,"-s", "sub", "objectclass=*"};
+      log.debug("existsDN:" + print(cmd)); 
+      return LDAPSearch.mainSearch(cmd) == 0;
+   }
+   
+   /**
+    * Issue a ldapCompare in the standard ldapCompare cmd line syntax
+    * (Eg: "-h localhost -p 1389 -D "cn=..." -w password -a -f ldif.txt)
+    * @param cmdline
+    * @return whether ldapCompare was success
+    */
+   public boolean ldapCompare(String cmdline)
+   {
+      String[] strArr = getStringArr(cmdline);
+      log.debug("ldapCompare:"+print(strArr));
+      return LDAPCompare.mainCompare(strArr) == 0;
+   }
+   
+   /**
+    * Issue a ldapdelete in the standard ldapdelete cmd line syntax
+    * (Eg: "-h localhost -p 1389 -D "cn=..." -w password -a -f ldif.txt)
+    * @param cmdline
+    * @return whether ldapmodify was success
+    */
+   public boolean ldapDelete(String cmdline)
+   {
+      String[] strArr = getStringArr(cmdline);
+      log.debug("ldapDelete:"+print(strArr));
+      return LDAPDelete.mainDelete(strArr) == 0;
+   }
+   
+   /**
+    * Issue a ldapmodify in the standard ldapmodify cmd line syntax
+    * (Eg: "-h localhost -p 1389 -D "cn=..." -w password -a -f ldif.txt)
+    * @param cmdline
+    * @return whether ldapmodify was success
+    */
+   public boolean ldapModify(String cmdline)
+   {
+      String[] strArr = getStringArr(cmdline);
+      log.debug("ldapModify:"+print(strArr));
+      return LDAPModify.mainModify(strArr) == 0;
+   }
+  
+   //***************************************************************
+   //   PRIVATE METHODS
+   //***************************************************************
+   private String[] getStringArr(String str)
+   {
+      StringTokenizer st = new StringTokenizer(str);
+      int num = st.countTokens();
+      String[] strarr = new String[num];
+      int i = 0;
+      while(st.hasMoreTokens())
+      {
+         strarr[i++] = st.nextToken();
+      }
+      return strarr;
+   } 
+   
+   private String print(String[] arr)
+   {
+      StringBuilder sb = new StringBuilder();
+      int len = arr != null ? arr.length : 0;
+      for(int i=0; i < len; i++)
+         sb.append(arr[i]);
+      return sb.toString();
+   }
+}




More information about the jboss-cvs-commits mailing list