cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6579] Making deflate level configurable
Date Sun, 06 Sep 2015 18:28:18 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes dd208dc7e -> 40a9b123e


[CXF-6579] Making deflate level configurable


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/40a9b123
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/40a9b123
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/40a9b123

Branch: refs/heads/2.7.x-fixes
Commit: 40a9b123e1c1374689d560bc83a81409fdfce6a3
Parents: dd208dc
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Sun Sep 6 19:09:38 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Sun Sep 6 19:27:45 2015 +0100

----------------------------------------------------------------------
 .../rs/security/saml/DeflateEncoderDecoder.java | 28 +++++++++++++++++++-
 .../saml/DeflateEncoderDecoderTest.java         | 21 ++++++++++++++-
 2 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/40a9b123/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/saml/DeflateEncoderDecoder.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/saml/DeflateEncoderDecoder.java
b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/saml/DeflateEncoderDecoder.java
index 05b6b18..76c68ef 100644
--- a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/saml/DeflateEncoderDecoder.java
+++ b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/saml/DeflateEncoderDecoder.java
@@ -24,6 +24,9 @@ import java.io.SequenceInputStream;
 import java.util.zip.DataFormatException;
 import java.util.zip.Deflater;
 import java.util.zip.Inflater;
+import org.apache.cxf.common.util.PropertyUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.PhaseInterceptorChain;
 
 public class DeflateEncoderDecoder {
     public InputStream inflateToken(byte[] deflatedToken) 
@@ -61,7 +64,17 @@ public class DeflateEncoderDecoder {
     }
     
     public byte[] deflateToken(byte[] tokenBytes) {
-        Deflater compresser = new Deflater(Deflater.DEFLATED, true);
+        return deflateToken(tokenBytes, true);
+    }
+    
+    public byte[] deflateToken(byte[] tokenBytes, boolean nowrap) {
+        
+        return deflateToken(tokenBytes, getDeflateLevel(), nowrap);
+    }
+    
+    public byte[] deflateToken(byte[] tokenBytes, int level, boolean nowrap) {
+        
+        Deflater compresser = new Deflater(level, nowrap);
         
         compresser.setInput(tokenBytes);
         compresser.finish();
@@ -74,4 +87,17 @@ public class DeflateEncoderDecoder {
         System.arraycopy(output, 0, result, 0, compressedDataLength);
         return result;
     }
+    
+    private static int getDeflateLevel() {
+        Integer level = null;
+        
+        Message m = PhaseInterceptorChain.getCurrentMessage();
+        if (m != null) {
+            level = PropertyUtils.getInteger(m, "deflate.level");
+        }
+        if (level == null) {
+            level = Deflater.DEFLATED;
+        }
+        return level;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/40a9b123/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/saml/DeflateEncoderDecoderTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/saml/DeflateEncoderDecoderTest.java
b/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/saml/DeflateEncoderDecoderTest.java
index 47de912..15a2512 100644
--- a/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/saml/DeflateEncoderDecoderTest.java
+++ b/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/saml/DeflateEncoderDecoderTest.java
@@ -18,8 +18,11 @@
  */
 package org.apache.cxf.rs.security.saml;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.util.zip.DataFormatException;
+import java.util.zip.Inflater;
+import java.util.zip.InflaterInputStream;
 
 import org.apache.cxf.common.util.Base64Utility;
 import org.apache.cxf.helpers.IOUtils;
@@ -62,5 +65,21 @@ public class DeflateEncoderDecoderTest extends Assert {
         assertNotNull(is);
         assertEquals("valid_grant", IOUtils.readStringFromStream(is));
     }
-    
+    @Test
+    public void testInflateDeflateWithTokenDuplication() throws Exception {
+        String token = "valid_grant valid_grant valid_grant valid_grant valid_grant valid_grant";
+
+        DeflateEncoderDecoder deflateEncoderDecoder = new DeflateEncoderDecoder();
+        byte[] deflatedToken = deflateEncoderDecoder.deflateToken(token.getBytes(), 0, true);
+
+        String cxfInflatedToken = IOUtils
+                .toString(deflateEncoderDecoder.inflateToken(deflatedToken));
+
+        String streamInflatedToken = IOUtils.toString(
+                new InflaterInputStream(new ByteArrayInputStream(deflatedToken),
+                        new Inflater(true)));
+
+        assertEquals(streamInflatedToken, token);
+        assertEquals(cxfInflatedToken, token);
+    }
 }


Mime
View raw message