You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2014/03/17 12:48:06 UTC

svn commit: r1578318 - in /cayenne/main/trunk: ./ cayenne-crypto/ cayenne-crypto/src/ cayenne-crypto/src/test/ cayenne-crypto/src/test/java/ cayenne-crypto/src/test/java/org/ cayenne-crypto/src/test/java/org/apache/ cayenne-crypto/src/test/java/org/apa...

Author: aadamchik
Date: Mon Mar 17 11:48:05 2014
New Revision: 1578318

URL: http://svn.apache.org/r1578318
Log:
CAY-1916 cayenne-crypto module that enables data encryption for certain model attributes

basic module, a simple integration test

Added:
    cayenne/main/trunk/cayenne-crypto/
    cayenne/main/trunk/cayenne-crypto/pom.xml
    cayenne/main/trunk/cayenne-crypto/src/
    cayenne/main/trunk/cayenne-crypto/src/test/
    cayenne/main/trunk/cayenne-crypto/src/test/java/
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Crypto_InRuntime_Test.java
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/Table1.java
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table1.java
    cayenne/main/trunk/cayenne-crypto/src/test/resources/
    cayenne/main/trunk/cayenne-crypto/src/test/resources/cayenne-crypto.xml
    cayenne/main/trunk/cayenne-crypto/src/test/resources/datamap.map.xml
Modified:
    cayenne/main/trunk/pom.xml

Added: cayenne/main/trunk/cayenne-crypto/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/pom.xml?rev=1578318&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/pom.xml (added)
+++ cayenne/main/trunk/cayenne-crypto/pom.xml Mon Mar 17 11:48:05 2014
@@ -0,0 +1,88 @@
+<?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/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<artifactId>cayenne-parent</artifactId>
+		<groupId>org.apache.cayenne</groupId>
+		<version>3.2.M2-SNAPSHOT</version>
+	</parent>
+	<artifactId>cayenne-crypto</artifactId>
+	<name>Cayenne Cryptography Eextensions</name>
+	<packaging>jar</packaging>
+	<dependencies>
+
+		<!-- Compile dependencies -->
+		<dependency>
+			<groupId>org.apache.cayenne</groupId>
+			<artifactId>cayenne-server</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+
+		<!-- Test dependencies -->
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.cayenne.build-tools</groupId>
+			<artifactId>cayenne-test-utilities</artifactId>
+			<version>${project.version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.mockito</groupId>
+			<artifactId>mockito-all</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>hsqldb</groupId>
+			<artifactId>hsqldb</artifactId>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<artifactId>maven-remote-resources-plugin</artifactId>
+				<executions>
+					<execution>
+						<goals>
+							<goal>process</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.cayenne.plugins</groupId>
+				<artifactId>maven-cayenne-plugin</artifactId>
+				<version>${project.version}</version>
+				<configuration>
+					<map>${project.basedir}/src/test/resources/datamap.map.xml</map>
+					<destDir>${project.basedir}/src/test/java</destDir>
+					<defaultPackage>org.apache.cayenne.crypto.db</defaultPackage>
+					<superPkg>org.apache.cayenne.crypto.db.auto</superPkg>
+				</configuration>
+				<executions>
+					<execution>
+						<id>default-cli</id>
+						<goals>
+							<goal>cgen</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+</project>

Added: cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Crypto_InRuntime_Test.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Crypto_InRuntime_Test.java?rev=1578318&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Crypto_InRuntime_Test.java (added)
+++ cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Crypto_InRuntime_Test.java Mon Mar 17 11:48:05 2014
@@ -0,0 +1,96 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+package org.apache.cayenne.crypto;
+
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.configuration.Rot13PasswordEncoder;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.crypto.db.Table1;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+
+public class Crypto_InRuntime_Test extends TestCase {
+
+    private ServerRuntime runtime;
+
+    private TableHelper table1;
+
+    private Rot13PasswordEncoder rot13Cipher;
+
+    @Override
+    protected void setUp() throws Exception {
+
+        this.runtime = new ServerRuntime("cayenne-crypto.xml");
+        this.rot13Cipher = new Rot13PasswordEncoder();
+
+        DBHelper dbHelper = new DBHelper(runtime.getDataSource(null));
+
+        this.table1 = new TableHelper(dbHelper, "TABLE1").setColumns("ID", "PLAIN_STRING", "CRYPTO_STRING");
+        table1.deleteAll();
+    }
+
+    public void testInsert() throws SQLException {
+
+        ObjectContext context = runtime.newContext();
+
+        Table1 t1 = context.newObject(Table1.class);
+        t1.setPlainString("plain_1");
+        t1.setCryptoString("crypto_1");
+
+        context.commitChanges();
+
+        Object[] data = table1.select();
+        assertEquals("plain_1", data[1]);
+        assertEquals(rot13Cipher.rotate("crypto_1"), data[2]);
+    }
+
+    public void testInsert_Multiple() throws SQLException {
+
+        ObjectContext context = runtime.newContext();
+
+        Table1 t1 = context.newObject(Table1.class);
+        t1.setPlainString("a");
+        t1.setCryptoString("crypto_1");
+
+        Table1 t2 = context.newObject(Table1.class);
+        t2.setPlainString("b");
+        t2.setCryptoString("crypto_2");
+
+        context.commitChanges();
+
+        List<Object[]> data = table1.selectAll();
+        assertEquals(2, data.size());
+
+        Map<Object, Object> cipherByPlain = new HashMap<Object, Object>();
+        for (Object[] r : data) {
+            cipherByPlain.put(r[1], r[2]);
+        }
+
+        assertEquals(rot13Cipher.rotate("crypto_1"), cipherByPlain.get("a"));
+        assertEquals(rot13Cipher.rotate("crypto_2"), cipherByPlain.get("b"));
+    }
+
+}

Added: cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/Table1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/Table1.java?rev=1578318&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/Table1.java (added)
+++ cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/Table1.java Mon Mar 17 11:48:05 2014
@@ -0,0 +1,9 @@
+package org.apache.cayenne.crypto.db;
+
+import org.apache.cayenne.crypto.db.auto._Table1;
+
+public class Table1 extends _Table1 {
+
+    private static final long serialVersionUID = 1L; 
+
+}

Added: cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table1.java?rev=1578318&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table1.java (added)
+++ cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table1.java Mon Mar 17 11:48:05 2014
@@ -0,0 +1,40 @@
+package org.apache.cayenne.crypto.db.auto;
+
+import org.apache.cayenne.CayenneDataObject;
+import org.apache.cayenne.exp.Property;
+
+/**
+ * Class _Table1 was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public abstract class _Table1 extends CayenneDataObject {
+
+    private static final long serialVersionUID = 1L; 
+
+    @Deprecated
+    public static final String CRYPTO_STRING_PROPERTY = "cryptoString";
+    @Deprecated
+    public static final String PLAIN_STRING_PROPERTY = "plainString";
+
+    public static final String ID_PK_COLUMN = "ID";
+
+    public static final Property<String> CRYPTO_STRING = new Property<String>("cryptoString");
+    public static final Property<String> PLAIN_STRING = new Property<String>("plainString");
+
+    public void setCryptoString(String cryptoString) {
+        writeProperty("cryptoString", cryptoString);
+    }
+    public String getCryptoString() {
+        return (String)readProperty("cryptoString");
+    }
+
+    public void setPlainString(String plainString) {
+        writeProperty("plainString", plainString);
+    }
+    public String getPlainString() {
+        return (String)readProperty("plainString");
+    }
+
+}

Added: cayenne/main/trunk/cayenne-crypto/src/test/resources/cayenne-crypto.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/resources/cayenne-crypto.xml?rev=1578318&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/resources/cayenne-crypto.xml (added)
+++ cayenne/main/trunk/cayenne-crypto/src/test/resources/cayenne-crypto.xml Mon Mar 17 11:48:05 2014
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<domain project-version="7">
+	<map name="datamap"/>
+
+	<node name="datanode"
+		 factory="org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory"
+		 schema-update-strategy="org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"
+		>
+		<map-ref name="datamap"/>
+		<data-source>
+			<driver value="org.hsqldb.jdbcDriver"/>
+			<url value="jdbc:hsqldb:mem:crypto"/>
+			<connectionPool min="1" max="1"/>
+			<login userName="sa"/>
+		</data-source>
+	</node>
+</domain>

Added: cayenne/main/trunk/cayenne-crypto/src/test/resources/datamap.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/resources/datamap.map.xml?rev=1578318&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/resources/datamap.map.xml (added)
+++ cayenne/main/trunk/cayenne-crypto/src/test/resources/datamap.map.xml Mon Mar 17 11:48:05 2014
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/7/modelMap"
+	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	 xsi:schemaLocation="http://cayenne.apache.org/schema/7/modelMap http://cayenne.apache.org/schema/7/modelMap.xsd"
+	 project-version="7">
+	<property name="defaultPackage" value="org.apache.cayenne.crypto.db"/>
+	<db-entity name="TABLE1">
+		<db-attribute name="CRYPTO_STRING" type="CLOB"/>
+		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="PLAIN_STRING" type="VARCHAR" length="200"/>
+	</db-entity>
+	<obj-entity name="Table1" className="org.apache.cayenne.crypto.db.Table1" dbEntityName="TABLE1">
+		<obj-attribute name="cryptoString" type="java.lang.String" db-attribute-path="CRYPTO_STRING"/>
+		<obj-attribute name="plainString" type="java.lang.String" db-attribute-path="PLAIN_STRING"/>
+	</obj-entity>
+</data-map>

Modified: cayenne/main/trunk/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/pom.xml?rev=1578318&r1=1578317&r2=1578318&view=diff
==============================================================================
--- cayenne/main/trunk/pom.xml (original)
+++ cayenne/main/trunk/pom.xml Mon Mar 17 11:48:05 2014
@@ -49,6 +49,7 @@
 		<module>cayenne-tools</module>
 		<module>cayenne-project</module>
 		<module>cayenne-lifecycle</module>
+		<module>cayenne-crypto</module>
 		<module>itests</module>
 		<module>modeler</module>
 		<module>plugins</module>