cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1578322 - in /cayenne/main/trunk/cayenne-crypto/src: main/java/org/apache/cayenne/crypto/map/PatternColumnMapper.java test/java/org/apache/cayenne/crypto/map/ test/java/org/apache/cayenne/crypto/map/PatternColumnMapperTest.java
Date Mon, 17 Mar 2014 11:48:57 GMT
Author: aadamchik
Date: Mon Mar 17 11:48:56 2014
New Revision: 1578322

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

PatternColumnMapper

Added:
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/map/PatternColumnMapper.java
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/map/
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/map/PatternColumnMapperTest.java

Added: cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/map/PatternColumnMapper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/map/PatternColumnMapper.java?rev=1578322&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/map/PatternColumnMapper.java
(added)
+++ cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/map/PatternColumnMapper.java
Mon Mar 17 11:48:56 2014
@@ -0,0 +1,45 @@
+/*****************************************************************
+ *   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.map;
+
+import java.util.regex.Pattern;
+
+import org.apache.cayenne.map.DbAttribute;
+
+/**
+ * A {@link ColumnMapper} that decides on whether a column is encrypted by
+ * matching its name against a preset pattern. Only column name is inspected.
+ * Table name is ignored.
+ * 
+ * @since 3.2
+ */
+public class PatternColumnMapper implements ColumnMapper {
+
+    private Pattern columnNamePattern;
+
+    public PatternColumnMapper(String columnNamePattern) {
+        this.columnNamePattern = Pattern.compile(columnNamePattern);
+    }
+
+    @Override
+    public boolean isEncrypted(DbAttribute column) {
+        return columnNamePattern.matcher(column.getName()).find();
+    }
+
+}

Added: cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/map/PatternColumnMapperTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/map/PatternColumnMapperTest.java?rev=1578322&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/map/PatternColumnMapperTest.java
(added)
+++ cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/map/PatternColumnMapperTest.java
Mon Mar 17 11:48:56 2014
@@ -0,0 +1,36 @@
+/*****************************************************************
+ *   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.map;
+
+import org.apache.cayenne.map.DbAttribute;
+
+import junit.framework.TestCase;
+
+public class PatternColumnMapperTest extends TestCase {
+
+    public void testIsEncrypted() {
+        PatternColumnMapper mapper = new PatternColumnMapper("^bla_");
+
+        assertTrue(mapper.isEncrypted(new DbAttribute("bla_")));
+        assertTrue(mapper.isEncrypted(new DbAttribute("bla_x")));
+        assertFalse(mapper.isEncrypted(new DbAttribute("_bla_x")));
+        assertFalse(mapper.isEncrypted(new DbAttribute("nnn")));
+    }
+
+}



Mime
View raw message