[jboss-cvs] JBossAS SVN: r83571 - in branches/JBPAPP_4_2_0_GA_CP/testsuite: src/main/org/jboss/test/security/test and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jan 28 12:41:02 EST 2009


Author: mmoyses
Date: 2009-01-28 12:41:02 -0500 (Wed, 28 Jan 2009)
New Revision: 83571

Added:
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/security/test/DatasourcePasswordEncryptionUnitTestCase.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/security/datasource-password/
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/security/datasource-password/encryptedpassword-ds.xml
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/security/datasource-password/login-config.xml
Modified:
   branches/JBPAPP_4_2_0_GA_CP/testsuite/imports/sections/security.xml
Log:
JBPAPP-1659: fix for passwords that have leading zeros

Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/imports/sections/security.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/imports/sections/security.xml	2009-01-28 17:19:35 UTC (rev 83570)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/imports/sections/security.xml	2009-01-28 17:41:02 UTC (rev 83571)
@@ -479,5 +479,13 @@
             <include name="org/jboss/test/security/interfaces/Stateful**"/>
          </fileset>
       </jar>  
+
+      <!-- datasource password encryption -->
+      <jar destfile="${build.lib}/encrypted-password.jar">
+         <fileset dir="${build.resources}/security/datasource-password">
+            <include name="login-config.xml"/>
+            <include name="encryptedpassword-ds.xml"/>
+         </fileset>
+      </jar>
    </target>
 </project>

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/security/test/DatasourcePasswordEncryptionUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/security/test/DatasourcePasswordEncryptionUnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/security/test/DatasourcePasswordEncryptionUnitTestCase.java	2009-01-28 17:41:02 UTC (rev 83571)
@@ -0,0 +1,188 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.test;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+
+/**
+ * 
+ * Tests password encryption for datasource
+ * 
+ * @author <a href="mmoyses at redhat.com">Marcus Moyses</a>
+ * @version $Revision: 1.1 $
+ */
+public class DatasourcePasswordEncryptionUnitTestCase extends JBossTestCase
+{
+
+   public DatasourcePasswordEncryptionUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite() throws Exception
+   {
+      // Clear any default login behavior
+      System.setProperty("jbosstest.secure", "false");
+      Test t1 = getDeploySetup(DatasourcePasswordEncryptionUnitTestCase.class, "encrypted-password.jar");
+      return t1;
+   }
+
+   //   public void testPasswordEncryption() throws Throwable
+   //   {
+   //      log.info("+++ testPasswordEncryption");
+   //      InitialContext ctx = super.getInitialContext();
+   //      Connection conn = null;
+   //      Statement stmt = null;
+   //      try
+   //      {
+   //         log.info("Lookup EncryptedSecureIdentityDS");
+   //         DataSource ds = (DataSource) ctx.lookup("EncryptedSecureIdentityDS");
+   //         conn = ds.getConnection();
+   //         log.info("Connected to EncryptedSecurityIdentityDS");
+   //         stmt = conn.createStatement();
+   //         log.info("Creating temp table TEST");
+   //         stmt.execute("CREATE TEMP TABLE TEST (NUM INTEGER, PRIMARY KEY (NUM))");
+   //         stmt.close();
+   //         log.info("Temp table created");
+   //         stmt = conn.createStatement();
+   //         stmt.execute("SHUTDOWN");
+   //         stmt.close();
+   //      }
+   //      catch (SQLException ignore)
+   //      {
+   //         log.debug("Failed to create table", ignore);
+   //         fail("Failed to create table");
+   //      }
+   //      finally
+   //      {
+   //         if (stmt != null)
+   //         {
+   //            try
+   //            {
+   //               stmt.close();
+   //            }
+   //            catch (SQLException ignore)
+   //            {
+   //            }
+   //         }
+   //         if (conn != null)
+   //            conn.close();
+   //      }
+   //   }
+
+   public void testNonDefaultPasswordEncryption() throws Throwable
+   {
+      log.info("+++ testNonDefaultPasswordEncryption");
+      InitialContext ctx = super.getInitialContext();
+      DataSource ds = null;
+      DataSource ds2 = null;
+      Connection conn = null;
+      Connection conn2 = null;
+      Statement stmt = null;
+      try
+      {
+         log.info("Lookup DefaultPasswordDS");
+         ds = (DataSource) ctx.lookup("DefaultPasswordDS");
+         conn = ds.getConnection();
+         log.info("Connected to DefaultPasswordDS");
+         stmt = conn.createStatement();
+         log.info("Changing password");
+         stmt.execute("SET PASSWORD dynamcusr");
+         stmt.close();
+         log.info("Password changed");
+      }
+      catch (SQLException ignore)
+      {
+         log.debug("Failed to update password", ignore);
+         fail("Failed to update password");
+      }
+      finally
+      {
+         if (stmt != null)
+         {
+            try
+            {
+               stmt.close();
+            }
+            catch (SQLException ignore)
+            {
+            }
+         }
+      }
+      try
+      {
+         log.info("Trying to connect again");
+         conn2 = ds.getConnection();
+         fail("Shouldn't be able to connected again");
+      }
+      catch (SQLException ignore)
+      {
+         log.info("Access was correctly denied");
+      }
+      finally
+      {
+         if (conn2 != null)
+            conn2.close();
+      }
+      try
+      {
+         log.info("Lookup NonDefaultPasswordDS");
+         ds2 = (DataSource) ctx.lookup("NonDefaultPasswordDS");
+         conn2 = ds2.getConnection();
+         log.info("Connected to NonDefaultPasswordDS");
+         stmt = conn2.createStatement();
+         stmt.execute("SHUTDOWN");
+         stmt.close();
+      }
+      catch (SQLException ignore)
+      {
+         log.debug("Access was incorrectly denied", ignore);
+         fail("Access was incorrectly denied");
+      }
+      finally
+      {
+         if (stmt != null)
+         {
+            try
+            {
+               stmt.close();
+            }
+            catch (SQLException ignore)
+            {
+            }
+         }
+         if (conn != null)
+            conn.close();
+         if (conn2 != null)
+            conn2.close();
+      }
+   }
+}

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/security/datasource-password/encryptedpassword-ds.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/security/datasource-password/encryptedpassword-ds.xml	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/security/datasource-password/encryptedpassword-ds.xml	2009-01-28 17:41:02 UTC (rev 83571)
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- The Hypersonic embedded database JCA connection factory config
+ to test password encryption -->
+
+<datasources>
+   <local-tx-datasource>
+      <jndi-name>EncryptedSecureIdentityDS</jndi-name>
+      <use-java-context>false</use-java-context>
+      <connection-url>jdbc:hsqldb:mem:EncryptedSIDB</connection-url>
+      <driver-class>org.hsqldb.jdbcDriver</driver-class>
+      <security-domain>EncryptedSecureIdentityDSRealm</security-domain>
+      <metadata>
+         <type-mapping>Hypersonic SQL</type-mapping>
+      </metadata>
+   </local-tx-datasource>
+   
+   <local-tx-datasource>
+      <jndi-name>DefaultPasswordDS</jndi-name>
+      <user-name>sa</user-name>
+      <password></password>
+      <use-java-context>false</use-java-context>
+      <connection-url>jdbc:hsqldb:mem:PasswordTestDB</connection-url>
+      <driver-class>org.hsqldb.jdbcDriver</driver-class>
+      <security-domain>DefaultPasswordDSRealm</security-domain>
+      <metadata>
+         <type-mapping>Hypersonic SQL</type-mapping>
+      </metadata>
+   </local-tx-datasource>
+   
+   <local-tx-datasource>
+      <jndi-name>NonDefaultPasswordDS</jndi-name>
+      <use-java-context>false</use-java-context>
+      <connection-url>jdbc:hsqldb:mem:PasswordTestDB</connection-url>
+      <driver-class>org.hsqldb.jdbcDriver</driver-class>
+      <security-domain>NonDefaultPasswordDSRealm</security-domain>
+      <metadata>
+         <type-mapping>Hypersonic SQL</type-mapping>
+      </metadata>
+   </local-tx-datasource>
+
+   <mbean code="org.jboss.security.auth.login.DynamicLoginConfig"
+         name="jboss.security.tests:service=SecuritySpecLoginConfig">
+      <attribute name="AuthConfig">login-config.xml</attribute>
+      <depends optional-attribute-name="LoginConfigService">
+         jboss.security:service=XMLLoginConfig
+      </depends>
+      <depends optional-attribute-name="SecurityManagerService">
+         jboss.security:service=JaasSecurityManager
+      </depends>
+   </mbean>
+</datasources>

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/security/datasource-password/login-config.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/security/datasource-password/login-config.xml	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/security/datasource-password/login-config.xml	2009-01-28 17:41:02 UTC (rev 83571)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- A login-config.xml example that uses the extended schema and jbossxb
+to marshall non-trival module-options.
+-->
+<policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xmlns="http://www.jboss.org/j2ee/schema/jaas"
+   targetNamespace="http://www.jboss.org/j2ee/schema/jaas"
+   >
+
+   <application-policy name="EncryptedSecureIdentityDSRealm">
+      <authentication>
+         <login-module code="org.jboss.resource.security.SecureIdentityLoginModule"
+            flag="required">
+            <module-option name="username">sa</module-option>
+            <module-option name="password">-207a6df87216de44</module-option>
+            <module-option name="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=EncryptedSecureIdentityDS</module-option>
+         </login-module>
+      </authentication>
+   </application-policy>
+   
+   <application-policy name="DefaultPasswordDSRealm">
+       <authentication>
+          <login-module code="org.jboss.resource.security.ConfiguredIdentityLoginModule"
+             flag = "required">
+             <module-option name="principal">sa</module-option>
+             <module-option name="userName">sa</module-option>
+             <module-option name="password"></module-option>
+             <module-option name="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=DefaultPasswordDS</module-option>
+          </login-module>
+       </authentication>
+    </application-policy>
+
+   <application-policy name="NonDefaultPasswordDSRealm">
+      <authentication>
+         <login-module code="org.jboss.resource.security.SecureIdentityLoginModule"
+            flag="required">
+            <module-option name="username">sa</module-option>
+            <module-option name="password">4284319a798f171f0b0525519389a9</module-option>
+            <module-option name="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=NonDefaultPasswordDS</module-option>
+         </login-module>
+      </authentication>
+   </application-policy>
+</policy>




More information about the jboss-cvs-commits mailing list