cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5311] Wrapping JweOutStream in DeflaterOutputStream if compression is requested
Date Wed, 02 Jul 2014 16:09:17 GMT
Repository: cxf
Updated Branches:
  refs/heads/master f0bb4ac2e -> c0d434e8d


[CXF-5311] Wrapping JweOutStream in DeflaterOutputStream if compression is requested


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

Branch: refs/heads/master
Commit: c0d434e8d6542c1f18d2055f2c55b98ac32fe519
Parents: f0bb4ac
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Jul 2 17:09:00 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Jul 2 17:09:00 2014 +0100

----------------------------------------------------------------------
 .../rs/security/oauth2/jwe/AbstractJweEncryptor.java | 15 ++++++++++++---
 .../cxf/rs/security/oauth2/jwe/JweEncryptor.java     |  2 +-
 .../oauth2/jwt/jaxrs/JweWriterInterceptor.java       |  3 +--
 3 files changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c0d434e8/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/AbstractJweEncryptor.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/AbstractJweEncryptor.java
b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/AbstractJweEncryptor.java
index 6dfa93a..3d5231d 100644
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/AbstractJweEncryptor.java
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/AbstractJweEncryptor.java
@@ -22,11 +22,13 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.security.spec.AlgorithmParameterSpec;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.zip.DeflaterOutputStream;
 
 import javax.crypto.Cipher;
 import javax.crypto.SecretKey;
 
 import org.apache.cxf.rs.security.oauth2.jwt.Algorithm;
+import org.apache.cxf.rs.security.oauth2.jwt.JwtConstants;
 import org.apache.cxf.rs.security.oauth2.jwt.JwtHeadersWriter;
 import org.apache.cxf.rs.security.oauth2.jwt.JwtTokenReaderWriter;
 import org.apache.cxf.rs.security.oauth2.utils.crypto.CryptoUtils;
@@ -122,7 +124,7 @@ public abstract class AbstractJweEncryptor implements JweEncryptor {
     }
     
     @Override
-    public JweOutputStream createJweStream(OutputStream os, String contentType) {
+    public OutputStream createJweStream(OutputStream os, String contentType) {
         JweEncryptorInternalState state = getInternalState(contentType);
         Cipher c = CryptoUtils.initCipher(state.secretKey, state.keyProps, 
                                           Cipher.ENCRYPT_MODE);
@@ -135,7 +137,11 @@ public abstract class AbstractJweEncryptor implements JweEncryptor {
         } catch (IOException ex) {
             throw new SecurityException(ex);
         }
-        return new JweOutputStream(os, c, getAuthTagLen());
+        OutputStream jweStream = new JweOutputStream(os, c, getAuthTagLen());
+        if (state.keyProps.isCompressionSupported()) {
+            jweStream = new DeflaterOutputStream(jweStream);
+        }
+        return jweStream;
     }
     
     private JweEncryptorInternalState getInternalState(String contentType) {
@@ -148,6 +154,7 @@ public abstract class AbstractJweEncryptor implements JweEncryptor {
         byte[] theCek = getContentEncryptionKey();
         String contentEncryptionAlgoJavaName = Algorithm.toJavaName(theHeaders.getContentEncryptionAlgorithm());
         KeyProperties keyProps = new KeyProperties(contentEncryptionAlgoJavaName);
+        keyProps.setCompressionSupported(compressionRequired(theHeaders));
         byte[] additionalEncryptionParam = theHeaders.toCipherAdditionalAuthData(writer);
         keyProps.setAdditionalData(additionalEncryptionParam);
         
@@ -164,7 +171,9 @@ public abstract class AbstractJweEncryptor implements JweEncryptor {
         state.theIv = theIv;
         return state;
     }
-    
+    private boolean compressionRequired(JweHeaders theHeaders) {
+        return JwtConstants.DEFLATE_ZIP_ALGORITHM.equals(theHeaders.getZipAlgorithm());
+    }
     private static class JweEncryptorInternalState {
         JweHeaders theHeaders;
         byte[] jweContentEncryptionKey;

http://git-wip-us.apache.org/repos/asf/cxf/blob/c0d434e8/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/JweEncryptor.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/JweEncryptor.java
b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/JweEncryptor.java
index a7edd08..c304dbf 100644
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/JweEncryptor.java
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/JweEncryptor.java
@@ -23,5 +23,5 @@ import java.io.OutputStream;
 
 public interface JweEncryptor {
     String encrypt(byte[] jweContent, String contentType);
-    JweOutputStream createJweStream(OutputStream os, String contentType);
+    OutputStream createJweStream(OutputStream os, String contentType);
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c0d434e8/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jaxrs/JweWriterInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jaxrs/JweWriterInterceptor.java
b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jaxrs/JweWriterInterceptor.java
index 7d56d28..c8097e3 100644
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jaxrs/JweWriterInterceptor.java
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jaxrs/JweWriterInterceptor.java
@@ -38,7 +38,6 @@ import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.rs.security.oauth2.jwe.JweEncryptor;
 import org.apache.cxf.rs.security.oauth2.jwe.JweHeaders;
-import org.apache.cxf.rs.security.oauth2.jwe.JweOutputStream;
 import org.apache.cxf.rs.security.oauth2.jwe.WrappedKeyJweEncryptor;
 import org.apache.cxf.rs.security.oauth2.jwt.Algorithm;
 import org.apache.cxf.rs.security.oauth2.utils.crypto.CryptoUtils;
@@ -67,7 +66,7 @@ public class JweWriterInterceptor implements WriterInterceptor {
         
         
         if (useJweOutputStream) {
-            JweOutputStream jweStream = theEncryptor.createJweStream(actualOs, ctString);
+            OutputStream jweStream = theEncryptor.createJweStream(actualOs, ctString);
             ctx.setOutputStream(jweStream);
             ctx.proceed();
             jweStream.flush();


Mime
View raw message