This is an automated email from the ASF dual-hosted git repository.

tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git

commit 4e4fc82b6158a9350d93a713bec1a3b5e795da5c
Author: Thomas Vandahl <[email protected]>
AuthorDate: Wed Mar 3 22:06:01 2021 +0100

    Add EncryptingSerializer and some documentation
---
 .../utils/serialization/EncryptingSerializer.java  | 168 +++++++++++++++++++++
 .../serialization/SerializationConversionUtil.java |  14 +-
 .../jcs3/JCSRemovalSimpleConcurrentTest.java       |  44 +++---
 .../CompressingSerializerUnitTest.java             |  24 ++-
 ...Test.java => EncryptingSerializerUnitTest.java} |  54 ++-----
 .../utils/serialization/SerializerUnitTest.java    |  99 ++++++++++++
 .../src/test/test-conf/TestElementSerializer.ccf   |  86 +++++++++++
 src/changes/changes.xml                            |   3 +
 src/site/site.xml                                  |   1 +
 xdocs/ElementSerializers.xml                       |  82 ++++++++++
 10 files changed, 487 insertions(+), 88 deletions(-)

diff --git 
a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializer.java
 
b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializer.java
new file mode 100644
index 0000000..f247ecb
--- /dev/null
+++ 
b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializer.java
@@ -0,0 +1,168 @@
+package org.apache.commons.jcs3.utils.serialization;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+
+import org.apache.commons.jcs3.engine.behavior.IElementSerializer;
+import org.apache.commons.jcs3.log.Log;
+import org.apache.commons.jcs3.log.LogManager;
+
+/**
+ * Performs serialization and de-serialization. It encrypts and decrypts the
+ * value.
+ */
+public class EncryptingSerializer extends StandardSerializer
+{
+    /** The logger */
+    private static final Log log = LogManager.getLog( 
EncryptingSerializer.class );
+
+    private static final String DEFAULT_CIPHER = "AES/ECB/PKCS5Padding";
+
+    /** The pre-shared key */
+    private SecretKeySpec secretKey;
+
+    /** The cipher transformation */
+    private String cipherTransformation = DEFAULT_CIPHER;
+
+    /** Wrapped serializer */
+    private final IElementSerializer serializer;
+
+    /**
+     * Default constructor
+     */
+    public EncryptingSerializer()
+    {
+        this(new StandardSerializer());
+    }
+
+    /**
+     * Wrapper constructor
+     *
+     * @param serializer
+     *            the wrapped serializer
+     */
+    public EncryptingSerializer(IElementSerializer serializer)
+    {
+        this.serializer = serializer;
+    }
+
+    /**
+     * Set the pre-shared key for encryption and decryption
+     *
+     * @param psk the key
+     */
+    public void setPreSharedKey(String psk)
+    {
+        try
+        {
+            MessageDigest sha = MessageDigest.getInstance("SHA-1");
+            byte[] key = sha.digest(psk.getBytes(StandardCharsets.UTF_8));
+            secretKey = new SecretKeySpec(key, 0, 16, "AES");
+        }
+        catch (NoSuchAlgorithmException e)
+        {
+            log.error("Cannot set pre-shared key", e);
+        }
+    }
+
+    /**
+     * Set the cipher transformation for encryption and decryption
+     * Default is AES/ECB/PKCS5Padding
+     *
+     * @param transformation the transformation
+     */
+    public void setAesCipherTransformation(String transformation)
+    {
+        this.cipherTransformation = transformation;
+    }
+
+    private byte[] encrypt(byte[] source) throws IOException
+    {
+        try
+        {
+            Cipher cipher = Cipher.getInstance(cipherTransformation);
+            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
+            return cipher.doFinal(source);
+        }
+        catch (Exception e)
+        {
+            throw new IOException("Error while encrypting", e);
+        }
+    }
+
+    private byte[] decrypt(byte[] source) throws IOException
+    {
+        try
+        {
+            Cipher cipher = Cipher.getInstance(cipherTransformation);
+            cipher.init(Cipher.DECRYPT_MODE, secretKey);
+            return cipher.doFinal(source);
+        }
+        catch (Exception e)
+        {
+            throw new IOException("Error while decrypting", e);
+        }
+    }
+
+    /**
+     * Serializes an object using default serialization. Encrypts the byte 
array.
+     * <p>
+     * @param obj object
+     * @return byte[]
+     * @throws IOException on i/o problem
+     */
+    @Override
+    public <T> byte[] serialize( final T obj )
+        throws IOException
+    {
+        final byte[] unencrypted = serializer.serialize(obj);
+        return encrypt(unencrypted);
+    }
+
+    /**
+     * Uses default de-serialization to turn a byte array into an object. 
Decrypts the value
+     * first. All exceptions are converted into IOExceptions.
+     * <p>
+     * @param data data bytes
+     * @param loader class loader to use
+     * @return Object
+     * @throws IOException on i/o problem
+     * @throws ClassNotFoundException if class is not found during 
deserialization
+     */
+    @Override
+    public <T> T deSerialize( final byte[] data, final ClassLoader loader )
+        throws IOException, ClassNotFoundException
+    {
+        if ( data == null )
+        {
+            return null;
+        }
+
+        final byte[] deccrypted = decrypt(data);
+        return serializer.deSerialize(deccrypted, loader);
+    }
+}
diff --git 
a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/serialization/SerializationConversionUtil.java
 
b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/serialization/SerializationConversionUtil.java
index 018829d..f62a7de 100644
--- 
a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/serialization/SerializationConversionUtil.java
+++ 
b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/serialization/SerializationConversionUtil.java
@@ -120,17 +120,9 @@ public class SerializationConversionUtil
         {
             try
             {
-                try
-                {
-                    deSerializedValue = elementSerializer.deSerialize( 
serialized.getSerializedValue(), null );
-                }
-                catch ( final ClassNotFoundException e )
-                {
-                    log.error( "Problem de-serializing object.", e );
-                    throw e;
-                }
+                deSerializedValue = elementSerializer.deSerialize( 
serialized.getSerializedValue(), null );
             }
-            catch ( final IOException e )
+            catch ( final ClassNotFoundException | IOException e )
             {
                 log.error( "Problem de-serializing object.", e );
                 throw e;
@@ -140,7 +132,7 @@ public class SerializationConversionUtil
         {
             // we could just use the default.
             throw new IOException( "Could not de-serialize object. The 
ElementSerializer is null." );
-       }
+        }
         final ICacheElement<K, V> deSerialized = new CacheElement<>( 
serialized.getCacheName(), serialized.getKey(), deSerializedValue );
         deSerialized.setElementAttributes( serialized.getElementAttributes() );
 
diff --git 
a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/JCSRemovalSimpleConcurrentTest.java
 
b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/JCSRemovalSimpleConcurrentTest.java
index f117473..1f638f4 100644
--- 
a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/JCSRemovalSimpleConcurrentTest.java
+++ 
b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/JCSRemovalSimpleConcurrentTest.java
@@ -1,5 +1,24 @@
 package org.apache.commons.jcs3;
 
+/*
+ * 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.
+ */
+
 import org.apache.commons.jcs3.access.CacheAccess;
 
 /*
@@ -29,13 +48,7 @@ import junit.framework.TestCase;
 public class JCSRemovalSimpleConcurrentTest
     extends TestCase
 {
-    /**
-     * @param testName
-     */
-    public JCSRemovalSimpleConcurrentTest( final String testName )
-    {
-        super( testName );
-    }
+    private CacheAccess<String, String> jcs;
 
     /**
      * Test setup
@@ -47,18 +60,7 @@ public class JCSRemovalSimpleConcurrentTest
         throws Exception
     {
         JCS.setConfigFilename( "/TestRemoval.ccf" );
-        JCS.getInstance( "testCache1" );
-    }
-
-    /**
-     * Main method passes this test to the text test runner.
-     * <p>
-     * @param args
-     */
-    public static void main( final String args[] )
-    {
-        final String[] testCaseName = { 
JCSRemovalSimpleConcurrentTest.class.getName() };
-        junit.textui.TestRunner.main( testCaseName );
+        jcs = JCS.getInstance( "testCache1" );
     }
 
     /**
@@ -70,7 +72,6 @@ public class JCSRemovalSimpleConcurrentTest
         throws Exception
     {
         final int count = 500;
-        final CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" 
);
 
         for ( int i = 0; i <= count; i++ )
         {
@@ -101,7 +102,6 @@ public class JCSRemovalSimpleConcurrentTest
     {
 
         final int count = 500;
-        final CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" 
);
 
         for ( int i = 0; i <= count; i++ )
         {
@@ -131,7 +131,6 @@ public class JCSRemovalSimpleConcurrentTest
     {
 
         final int count = 500;
-        final CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" 
);
 
         for ( int i = 0; i <= count; i++ )
         {
@@ -164,7 +163,6 @@ public class JCSRemovalSimpleConcurrentTest
         throws Exception
     {
         final int count = 500;
-        final CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" 
);
 
         jcs.clear();
 
diff --git 
a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/CompressingSerializerUnitTest.java
 
b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/CompressingSerializerUnitTest.java
index e1927ae..f998762 100644
--- 
a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/CompressingSerializerUnitTest.java
+++ 
b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/CompressingSerializerUnitTest.java
@@ -1,5 +1,7 @@
 package org.apache.commons.jcs3.utils.serialization;
 
+import java.io.IOException;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -21,14 +23,20 @@ package org.apache.commons.jcs3.utils.serialization;
 
 import junit.framework.TestCase;
 
-import java.io.IOException;
-
 /**
  * Tests the compressing serializer.
  */
 public class CompressingSerializerUnitTest
     extends TestCase
 {
+    private CompressingSerializer serializer;
+
+    @Override
+    protected void setUp() throws Exception
+    {
+        this.serializer = new CompressingSerializer();
+    }
+
     /**
      * Verify that we don't get any erorrs for null input.
      * <p>
@@ -38,9 +46,6 @@ public class CompressingSerializerUnitTest
     public void testDeserialize_NullInput()
         throws IOException, ClassNotFoundException
     {
-        // SETUP
-        final CompressingSerializer serializer = new CompressingSerializer();
-
         // DO WORK
         final Object result = serializer.deSerialize( null, null );
 
@@ -58,9 +63,6 @@ public class CompressingSerializerUnitTest
     public void testSimpleBackAndForth()
         throws Exception
     {
-        // SETUP
-        final CompressingSerializer serializer = new CompressingSerializer();
-
         // DO WORK
         final String before = 
"adsfdsafdsafdsafdsafdsafdsafdsagfdsafdsafdsfdsafdsafsa333 31231";
         final String after = (String) serializer.deSerialize( 
serializer.serialize( before ), null );
@@ -77,9 +79,6 @@ public class CompressingSerializerUnitTest
     public void testSerialize_NullInput()
         throws Exception
     {
-        // SETUP
-        final CompressingSerializer serializer = new CompressingSerializer();
-
         final String before = null;
 
         // DO WORK
@@ -98,9 +97,6 @@ public class CompressingSerializerUnitTest
     public void testSerialize_CompareCompressedAndUncompressed()
         throws Exception
     {
-        // SETUP
-        final CompressingSerializer serializer = new CompressingSerializer();
-
         // I hate for loops.
         final String before = "adsfdsafdsafdsafdsafdsafdsafdsagfdsafdsafdssaf 
dsaf sadf dsaf dsaf dsaf "
             + "dsafdsa fdsaf dsaf dsafdsa dsaf dsaf dsaf dsaf dsafdsa76f 
dsa798f dsa6fdsa 087f  "
diff --git 
a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/CompressingSerializerUnitTest.java
 
b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializerUnitTest.java
similarity index 61%
copy from 
commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/CompressingSerializerUnitTest.java
copy to 
commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializerUnitTest.java
index e1927ae..13ef2c8 100644
--- 
a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/CompressingSerializerUnitTest.java
+++ 
b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializerUnitTest.java
@@ -1,5 +1,7 @@
 package org.apache.commons.jcs3.utils.serialization;
 
+import java.io.IOException;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -21,14 +23,22 @@ package org.apache.commons.jcs3.utils.serialization;
 
 import junit.framework.TestCase;
 
-import java.io.IOException;
-
 /**
- * Tests the compressing serializer.
+ * Tests the encrypting serializer.
  */
-public class CompressingSerializerUnitTest
+public class EncryptingSerializerUnitTest
     extends TestCase
 {
+    private EncryptingSerializer serializer;
+
+    @Override
+    protected void setUp() throws Exception
+    {
+        this.serializer = new EncryptingSerializer();
+        this.serializer.setPreSharedKey("my_secret_key");
+        this.serializer.setAesCipherTransformation("AES");
+    }
+
     /**
      * Verify that we don't get any erorrs for null input.
      * <p>
@@ -38,9 +48,6 @@ public class CompressingSerializerUnitTest
     public void testDeserialize_NullInput()
         throws IOException, ClassNotFoundException
     {
-        // SETUP
-        final CompressingSerializer serializer = new CompressingSerializer();
-
         // DO WORK
         final Object result = serializer.deSerialize( null, null );
 
@@ -58,9 +65,6 @@ public class CompressingSerializerUnitTest
     public void testSimpleBackAndForth()
         throws Exception
     {
-        // SETUP
-        final CompressingSerializer serializer = new CompressingSerializer();
-
         // DO WORK
         final String before = 
"adsfdsafdsafdsafdsafdsafdsafdsagfdsafdsafdsfdsafdsafsa333 31231";
         final String after = (String) serializer.deSerialize( 
serializer.serialize( before ), null );
@@ -77,9 +81,6 @@ public class CompressingSerializerUnitTest
     public void testSerialize_NullInput()
         throws Exception
     {
-        // SETUP
-        final CompressingSerializer serializer = new CompressingSerializer();
-
         final String before = null;
 
         // DO WORK
@@ -89,31 +90,4 @@ public class CompressingSerializerUnitTest
         // VERIFY
         assertNull( "Should have nothing. after =" + after, after );
     }
-
-    /**
-     * Verify that the compressed is smaller.
-     * <p>
-     * @throws Exception on error
-     */
-    public void testSerialize_CompareCompressedAndUncompressed()
-        throws Exception
-    {
-        // SETUP
-        final CompressingSerializer serializer = new CompressingSerializer();
-
-        // I hate for loops.
-        final String before = "adsfdsafdsafdsafdsafdsafdsafdsagfdsafdsafdssaf 
dsaf sadf dsaf dsaf dsaf "
-            + "dsafdsa fdsaf dsaf dsafdsa dsaf dsaf dsaf dsaf dsafdsa76f 
dsa798f dsa6fdsa 087f  "
-            + "gh 987dsahb dsahbuhbfnui nufdsa hbv87 f8vhdsgbnfv 
h8fdg8dfjvn8fdwgj fdsgjb9fdsjbv"
-            + "jvhjv hg98f-dsaghj j9fdsb gfsb 9fdshjbgb987fdsbfdwgh ujbhjbhb 
hbfdsgh fdshb "
-            + "Ofdsgyfesgyfdsafdsafsa333 31231";
-
-        // DO WORK
-        final byte[] compressed = serializer.serialize( before );
-        final byte[] nonCompressed = new StandardSerializer().serialize( 
before );
-
-        // VERIFY
-        assertTrue( "Compressed should be smaller. compressed size = " + 
compressed.length + "nonCompressed size = "
-            + nonCompressed.length, compressed.length < nonCompressed.length );
-    }
 }
diff --git 
a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/SerializerUnitTest.java
 
b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/SerializerUnitTest.java
new file mode 100644
index 0000000..065b972
--- /dev/null
+++ 
b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/utils/serialization/SerializerUnitTest.java
@@ -0,0 +1,99 @@
+package org.apache.commons.jcs3.utils.serialization;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.jcs3.JCS;
+import org.apache.commons.jcs3.access.CacheAccess;
+
+/*
+ * 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.
+ */
+
+import junit.framework.TestCase;
+
+/**
+ * Verify that serializer functionality works.
+ */
+public class SerializerUnitTest
+    extends TestCase
+{
+    /**
+     * Test setup
+     * <p>
+     * @throws Exception
+     */
+    @Override
+    public void setUp()
+        throws Exception
+    {
+        JCS.setConfigFilename( "/TestElementSerializer.ccf" );
+    }
+
+    /**
+     * Verify that object reading and writing works
+     * <p>
+     * @throws Exception
+     */
+    public void testReadWrite()
+        throws Exception
+    {
+        final int count = 500; // 100 fit in memory
+        final CacheAccess<String, String> jcs1 = JCS.getInstance( 
"blockRegion1" );
+
+        for ( int i = 0; i < count; i++ )
+        {
+            jcs1.put( "key:" + i, "data" + i );
+        }
+
+        for ( int i = count-1; i >= 0; i-- )
+        {
+            final String res = jcs1.get( "key:" + i );
+            assertNotNull( "[key:" + i + "] should not be null, " + 
jcs1.getStats(), res );
+        }
+
+        final CacheAccess<String, String> jcs2 = JCS.getInstance( 
"blockRegion2" );
+
+        for ( int i = 0; i < count; i++ )
+        {
+            jcs2.put( "key:" + i, "data" + i );
+        }
+
+        for ( int i = count-1; i >= 0; i-- )
+        {
+            final String res = jcs2.get( "key:" + i );
+            assertNotNull( "[key:" + i + "] should not be null, " + 
jcs2.getStats(), res );
+        }
+    }
+}
diff --git a/commons-jcs-core/src/test/test-conf/TestElementSerializer.ccf 
b/commons-jcs-core/src/test/test-conf/TestElementSerializer.ccf
new file mode 100644
index 0000000..55a5ec0
--- /dev/null
+++ b/commons-jcs-core/src/test/test-conf/TestElementSerializer.ccf
@@ -0,0 +1,86 @@
+# 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.
+# Cache configuration for the 'TestDiskCache' test. The memory cache has a
+# a maximum of 100 objects, so objects should get pushed into the disk cache
+
+jcs.default=blockDiskCache
+jcs.default.cacheattributes=org.apache.commons.jcs3.engine.CompositeCacheAttributes
+jcs.default.cacheattributes.MaxObjects=100
+jcs.default.cacheattributes.MemoryCacheName=org.apache.commons.jcs3.engine.memory.lru.LRUMemoryCache
+
+# SYSTEM GROUP ID CACHE
+jcs.system.groupIdCache=blockDiskCache
+jcs.system.groupIdCache.cacheattributes=org.apache.commons.jcs3.engine.CompositeCacheAttributes
+jcs.system.groupIdCache.cacheattributes.MaxObjects=10000
+jcs.system.groupIdCache.cacheattributes.MemoryCacheName=org.apache.commons.jcs3.engine.memory.lru.LRUMemoryCache
+
+
+# #### CACHE REGIONS FOR TEST
+
+jcs.region.blockRegion1=blockDiskCache
+jcs.region.blockRegion1.cacheattributes=org.apache.commons.jcs3.engine.CompositeCacheAttributes
+jcs.region.blockRegion1.cacheattributes.MaxObjects=100
+jcs.region.blockRegion1.cacheattributes.MemoryCacheName=org.apache.commons.jcs3.engine.memory.lru.LRUMemoryCache
+
+jcs.region.blockRegion2=blockDiskCache2
+jcs.region.blockRegion2.cacheattributes=org.apache.commons.jcs3.engine.CompositeCacheAttributes
+jcs.region.blockRegion2.cacheattributes.MaxObjects=100
+jcs.region.blockRegion2.cacheattributes.MemoryCacheName=org.apache.commons.jcs3.engine.memory.lru.LRUMemoryCache
+
+# #### AUXILIARY CACHES
+
+# Block Disk Cache
+jcs.auxiliary.blockDiskCache=org.apache.commons.jcs3.auxiliary.disk.block.BlockDiskCacheFactory
+jcs.auxiliary.blockDiskCache.attributes=org.apache.commons.jcs3.auxiliary.disk.block.BlockDiskCacheAttributes
+jcs.auxiliary.blockDiskCache.attributes.DiskPath=target/test-sandbox/block-disk-cache
+jcs.auxiliary.blockDiskCache.serializer=org.apache.commons.jcs3.utils.serialization.CompressingSerializer
+
+
+# Block Disk Cache
+jcs.auxiliary.blockDiskCache2=org.apache.commons.jcs3.auxiliary.disk.block.BlockDiskCacheFactory
+jcs.auxiliary.blockDiskCache2.attributes=org.apache.commons.jcs3.auxiliary.disk.block.BlockDiskCacheAttributes
+jcs.auxiliary.blockDiskCache2.attributes.DiskPath=target/test-sandbox/block-disk-cache2
+jcs.auxiliary.blockDiskCache2.serializer=org.apache.commons.jcs3.utils.serialization.EncryptingSerializer
+jcs.auxiliary.blockDiskCache2.serializer.attributes.preSharedKey=my_secret
+
+# #############################################################
+# ################# THREAD POOL CONFIGURATION ###################
+# Default thread pool config
+thread_pool.default.boundarySize=2000
+thread_pool.default.maximumPoolSize=150
+thread_pool.default.minimumPoolSize=4
+thread_pool.default.keepAliveTime=350000
+# RUN ABORT WAIT BLOCK DISCARDOLDEST
+thread_pool.default.whenBlockedPolicy=RUN
+thread_pool.default.startUpSize=4
+
+# Default Cache Event Queue thread pool config, used by auxiliaries
+thread_pool.cache_event_queue.useBoundary=false
+# thread_pool.cache_event_queue.boundarySize=2000
+# thread_pool.cache_event_queue.maximumPoolSize=10
+thread_pool.cache_event_queue.minimumPoolSize=5
+thread_pool.cache_event_queue.keepAliveTime=3500
+# thread_pool.cache_event_queue.whenBlockedPolicy=RUN
+thread_pool.cache_event_queue.startUpSize=5
+
+# Remote cache client thread pool config
+thread_pool.remote_cache_client.boundarySize=75
+thread_pool.remote_cache_client.maximumPoolSize=150
+thread_pool.remote_cache_client.minimumPoolSize=4
+thread_pool.remote_cache_client.keepAliveTime=350000
+thread_pool.remote_cache_client.whenBlockedPolicy=RUN
+thread_pool.remote_cache_client.startUpSize=4
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index dd491e1..0702479 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -20,6 +20,9 @@
        </properties>
        <body>
         <release version="3.1" date="20YY-MM-DD">
+            <action dev="tv" type="add">
+               Add EncryptingSerializer and some documentation
+            </action>
             <action dev="tv" type="update">
                Replace several Runnable classes with Lambdas
                Deprecate original classes
diff --git a/src/site/site.xml b/src/site/site.xml
index 8e0a738..d50c1e7 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -57,6 +57,7 @@
       </item>
       <item name="Auxiliary" href="/JCSPlugins.html" collapse="true">
         <item name="Cache Event Logging" href="/CacheEventLogging.html"/>
+        <item name="Element Serializers" href="/ElementSerializers.html"/>
         <item name="Indexed Disk Cache" href="/IndexedDiskAuxCache.html"/>
         <item name="Indexed Disk Properties" 
href="/IndexedDiskCacheProperties.html"/>
         <item name="Block Disk Cache" href="/BlockDiskCache.html"/>
diff --git a/xdocs/ElementSerializers.xml b/xdocs/ElementSerializers.xml
new file mode 100644
index 0000000..e99914c
--- /dev/null
+++ b/xdocs/ElementSerializers.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0"?>
+       <!--
+               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.
+       -->
+<document>
+       <properties>
+               <title>Element Serializers</title>
+               <author email="[email protected]">Thomas Vandahl</author>
+       </properties>
+       <body>
+               <section name="Serializing and De-serializing Cache Objects">
+                       <p> When using auxiliary caches, cache elements need to 
be serialized 
+                into a byte stream in order to be stored on disk or 
transported 
+                through a network. For reading from these caches, bytes must 
be 
+                de-serialized into objects. By default, JCS uses the standard 
JDK
+                methods for serializing and de-serializing objects. However, 
all 
+                of the auxiliaries also support setting a custom serializer to 
+                have finer control of the behavior.</p>
+                
+                       <p> This document describes the built-in serializers 
and their 
+                configuration.</p>
+               </section>
+        <section name="Compressing Serializer">
+            <p> The <code>CompressingSerializer</code> gzips the bytes
+                after serializing the cache object the default way. For 
reading, 
+                the bytes will be de-compressed first and then de-serialized 
into 
+                a Java object. The class can also be used as a wrapper around 
an
+                arbitrary class implementing 
<code>IElementSerializer</code>.</p>
+                
+            <p> The configuration for a typical application looks like 
this:</p>
+            <source>
+                <![CDATA[
+# Block Disk Cache
+jcs.auxiliary.blockDiskCache=org.apache.commons.jcs3.auxiliary.disk.block.BlockDiskCacheFactory
+jcs.auxiliary.blockDiskCache.attributes=org.apache.commons.jcs3.auxiliary.disk.block.BlockDiskCacheAttributes
+jcs.auxiliary.blockDiskCache.attributes.DiskPath=target/test-sandbox/block-disk-cache
+jcs.auxiliary.blockDiskCache.serializer=org.apache.commons.jcs3.utils.serialization.CompressingSerializer
+                ]]>
+            </source>
+        </section>
+        <section name="Encrypting Serializer">
+            <p> The <code>EncryptingSerializer</code> uses AES to encrypt the 
bytes
+                after serializing the cache object the default way. For 
reading, 
+                the bytes will be decrypted first and then de-serialized into 
+                a Java object. The class can also be used as a wrapper around 
an
+                arbitrary class implementing 
<code>IElementSerializer</code>.</p>
+
+            <p> The implementation uses a symmetrical pre-shared key for 
encrypting
+                and decrypting the data.</p>
+                
+            <p> The configuration for a typical application looks like 
this:</p>
+            <source>
+                <![CDATA[
+# Block Disk Cache
+jcs.auxiliary.blockDiskCache2=org.apache.commons.jcs3.auxiliary.disk.block.BlockDiskCacheFactory
+jcs.auxiliary.blockDiskCache2.attributes=org.apache.commons.jcs3.auxiliary.disk.block.BlockDiskCacheAttributes
+jcs.auxiliary.blockDiskCache2.attributes.DiskPath=target/test-sandbox/block-disk-cache2
+jcs.auxiliary.blockDiskCache2.serializer=org.apache.commons.jcs3.utils.serialization.EncryptingSerializer
+jcs.auxiliary.blockDiskCache2.serializer.attributes.preSharedKey=my_secret
+                ]]>
+            </source>
+            
+            <p> The AES cipher transformation to be used can be configured 
like this:</p>
+            <source>
+                <![CDATA[
+jcs.auxiliary.blockDiskCache.serializer.attributes.aesCipherTransformation=AES/ECB/PKCS5Padding
+                ]]>
+            </source>
+        </section>
+       </body>
+</document>
\ No newline at end of file

Reply via email to