You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2011/06/24 09:18:14 UTC

svn commit: r1139172 - in /openejb/trunk/openejb3/examples: ./ datasource-ciphered-password/ datasource-ciphered-password/src/ datasource-ciphered-password/src/main/ datasource-ciphered-password/src/main/java/ datasource-ciphered-password/src/test/ dat...

Author: rmannibucau
Date: Fri Jun 24 07:18:13 2011
New Revision: 1139172

URL: http://svn.apache.org/viewvc?rev=1139172&view=rev
Log:
adding example datasource-ciphered-password

Added:
    openejb/trunk/openejb3/examples/datasource-ciphered-password/
    openejb/trunk/openejb3/examples/datasource-ciphered-password/pom.xml
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/main/
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/main/java/
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/java/
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/java/org/
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/java/org/superbiz/
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/java/org/superbiz/DataSourceCipheredExample.java
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/META-INF/
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/META-INF/beans.xml
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/META-INF/org.apache.openejb.resource.jdbc.PasswordCipher/
    openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/META-INF/org.apache.openejb.resource.jdbc.PasswordCipher/reverse
Modified:
    openejb/trunk/openejb3/examples/dynamic-datasource-routing/src/test/java/org/superbiz/dynamicdatasourcerouting/DynamicDataSourceTest.java
    openejb/trunk/openejb3/examples/pom.xml

Added: openejb/trunk/openejb3/examples/datasource-ciphered-password/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/datasource-ciphered-password/pom.xml?rev=1139172&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/datasource-ciphered-password/pom.xml (added)
+++ openejb/trunk/openejb3/examples/datasource-ciphered-password/pom.xml Fri Jun 24 07:18:13 2011
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.superbiz</groupId>
+  <artifactId>datasource-ciphered-password</artifactId>
+  <packaging>jar</packaging>
+  <version>1.1-SNAPSHOT</version>
+  <name>OpenEJB :: Examples :: Datasource Ciphered Password</name>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <openejb.version>4.0.0-SNAPSHOT</openejb.version>
+  </properties>
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.3.2</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <repositories>
+    <repository>
+      <id>apache-m2-snapshot</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://repository.apache.org/snapshots</url>
+    </repository>
+  </repositories>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>6.0-SNAPSHOT</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <!--
+    The <scope>test</scope> guarantees that non of your runtime
+    code is dependent on any OpenEJB classes.
+    -->
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-core</artifactId>
+      <version>${openejb.version}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <!--
+  This section allows you to configure where to publish libraries for sharing.
+  It is not required and may be deleted.  For more information see:
+  http://maven.apache.org/plugins/maven-deploy-plugin/
+  -->
+  <distributionManagement>
+    <repository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/repo/</url>
+    </repository>
+    <snapshotRepository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/snapshot-repo/</url>
+    </snapshotRepository>
+  </distributionManagement>
+</project>

Added: openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/java/org/superbiz/DataSourceCipheredExample.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/java/org/superbiz/DataSourceCipheredExample.java?rev=1139172&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/java/org/superbiz/DataSourceCipheredExample.java (added)
+++ openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/java/org/superbiz/DataSourceCipheredExample.java Fri Jun 24 07:18:13 2011
@@ -0,0 +1,97 @@
+package org.superbiz;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Properties;
+import javax.annotation.Resource;
+import javax.ejb.embeddable.EJBContainer;
+import javax.naming.Context;
+import javax.sql.DataSource;
+import org.apache.commons.lang.StringUtils;
+import org.apache.openejb.resource.jdbc.PasswordCipher;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertNotNull;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+public class DataSourceCipheredExample {
+    private static final String USER = DataSourceCipheredExample.class.getSimpleName();
+    private static final String PASSWORD = "YouLLN3v3rFindM3";
+    private static final String DATASOURCE_URL = "jdbc:hsqldb:mem:protected";
+
+    @Resource private DataSource dataSource;
+
+    @BeforeClass public static void addDatabaseUserWithPassword() throws Exception {
+        sql("CREATE USER " + USER + " PASSWORD " + PASSWORD + ";");
+    }
+
+    @Test public void accessDatasource() throws Exception{
+        // define the datasource
+        Properties properties = new Properties();
+        properties.setProperty("ProtectedDatasource", "new://Resource?type=DataSource");
+        properties.setProperty("ProtectedDatasource.JdbcDriver", "org.hsqldb.jdbcDriver");
+        properties.setProperty("ProtectedDatasource.JdbcUrl", DATASOURCE_URL);
+        properties.setProperty("ProtectedDatasource.UserName", USER);
+        properties.setProperty("ProtectedDatasource.Password", "fEroTNXjaL5SOTyRQ92x3DNVS/ksbtgs");
+        properties.setProperty("ProtectedDatasource.PasswordCipher", "Static3DES");
+        properties.setProperty("ProtectedDatasource.JtaManaged", "true");
+
+        // start the context and makes junit test injections
+        Context context = EJBContainer.createEJBContainer(properties).getContext();
+        context.bind("inject", this);
+
+        // test the datasource
+        assertNotNull(dataSource);
+        assertNotNull(dataSource.getConnection());
+
+        // closing the context
+        context.close();
+    }
+
+    @Test public void accessDatasourceWithMyImplementation() throws Exception{
+        // define the datasource
+        Properties properties = new Properties();
+        properties.setProperty("ProtectedDatasource", "new://Resource?type=DataSource");
+        properties.setProperty("ProtectedDatasource.JdbcDriver", "org.hsqldb.jdbcDriver");
+        properties.setProperty("ProtectedDatasource.JdbcUrl", "jdbc:hsqldb:mem:protected");
+        properties.setProperty("ProtectedDatasource.UserName", USER);
+        properties.setProperty("ProtectedDatasource.Password", "3MdniFr3v3NLLuoY");
+        properties.setProperty("ProtectedDatasource.PasswordCipher", "reverse");
+        properties.setProperty("ProtectedDatasource.JtaManaged", "true");
+
+        // start the context and makes junit test injections
+        Context context = EJBContainer.createEJBContainer(properties).getContext();
+        context.bind("inject", this);
+
+        // test the datasource
+        assertNotNull(dataSource);
+        assertNotNull(dataSource.getConnection());
+
+        // closing the context
+        context.close();
+    }
+
+    public static class ReverseEncryption implements PasswordCipher {
+        @Override public char[] encrypt(String plainPassword) {
+            return StringUtils.reverse(plainPassword).toCharArray();
+        }
+
+        @Override public String decrypt(char[] encryptedPassword) {
+            return new String(encrypt(new String(encryptedPassword)));
+        }
+    }
+
+    private static void sql(String query) throws Exception {
+        Class.forName("org.hsqldb.jdbcDriver");
+        Connection conn = DriverManager.getConnection(DATASOURCE_URL, "sa", "");
+        Statement st = conn.createStatement();
+        st.executeUpdate(query);
+        st.close();
+        conn.close();
+    }
+}

Added: openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/META-INF/beans.xml?rev=1139172&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/META-INF/beans.xml (added)
+++ openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/META-INF/beans.xml Fri Jun 24 07:18:13 2011
@@ -0,0 +1 @@
+<beans />

Added: openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/META-INF/org.apache.openejb.resource.jdbc.PasswordCipher/reverse
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/META-INF/org.apache.openejb.resource.jdbc.PasswordCipher/reverse?rev=1139172&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/META-INF/org.apache.openejb.resource.jdbc.PasswordCipher/reverse (added)
+++ openejb/trunk/openejb3/examples/datasource-ciphered-password/src/test/resources/META-INF/org.apache.openejb.resource.jdbc.PasswordCipher/reverse Fri Jun 24 07:18:13 2011
@@ -0,0 +1 @@
+org.superbiz.DataSourceCipheredExample$ReverseEncryption

Modified: openejb/trunk/openejb3/examples/dynamic-datasource-routing/src/test/java/org/superbiz/dynamicdatasourcerouting/DynamicDataSourceTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/dynamic-datasource-routing/src/test/java/org/superbiz/dynamicdatasourcerouting/DynamicDataSourceTest.java?rev=1139172&r1=1139171&r2=1139172&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/dynamic-datasource-routing/src/test/java/org/superbiz/dynamicdatasourcerouting/DynamicDataSourceTest.java (original)
+++ openejb/trunk/openejb3/examples/dynamic-datasource-routing/src/test/java/org/superbiz/dynamicdatasourcerouting/DynamicDataSourceTest.java Fri Jun 24 07:18:13 2011
@@ -81,7 +81,6 @@ public class DynamicDataSourceTest {
             properties.setProperty(dbName, "new://Resource?type=DataSource");
             dbName += ".";
             properties.setProperty(dbName + "JdbcDriver", "org.hsqldb.jdbcDriver");
-            properties.setProperty(dbName + "JdbcDriver", "org.hsqldb.jdbcDriver");
             properties.setProperty(dbName + "JdbcUrl", "jdbc:hsqldb:mem:db" + i);
             properties.setProperty(dbName + "UserName", "sa");
             properties.setProperty(dbName + "Password", "");

Modified: openejb/trunk/openejb3/examples/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/pom.xml?rev=1139172&r1=1139171&r2=1139172&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/pom.xml (original)
+++ openejb/trunk/openejb3/examples/pom.xml Fri Jun 24 07:18:13 2011
@@ -79,6 +79,7 @@
     <module>decorators</module>
     <module>dynamic-datasource-routing</module>
     <module>mbean-auto-registration</module>
+    <module>datasource-ciphered-password</module>
   </modules>
   <profiles>
     <profile>