cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [2/2] cxf git commit: Removing redundant Jwt reader/writer
Date Fri, 03 Jun 2016 12:38:03 GMT
Removing redundant Jwt reader/writer


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

Branch: refs/heads/master
Commit: 49ab24bf02c8d608aef397b19183e678860d4c23
Parents: 374a9cf
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Jun 3 13:37:39 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Jun 3 13:37:39 2016 +0100

----------------------------------------------------------------------
 .../jose/jwe/JweJwtCompactConsumer.java         |  4 +-
 .../security/jose/jws/JwsCompactConsumer.java   |  8 +--
 .../jose/jws/JwsJwtCompactConsumer.java         |  6 +--
 .../jose/jws/JwsJwtCompactProducer.java         |  4 +-
 .../security/jose/jwt/JwtTokenReaderWriter.java | 55 --------------------
 .../cxf/rs/security/jose/jwt/JwtUtils.java      |  9 ++--
 .../jose/jws/JwsCompactReaderWriterTest.java    |  6 +--
 7 files changed, 15 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/49ab24bf/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweJwtCompactConsumer.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweJwtCompactConsumer.java
b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweJwtCompactConsumer.java
index f5610cf..3eaa23d 100644
--- a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweJwtCompactConsumer.java
+++ b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweJwtCompactConsumer.java
@@ -25,7 +25,7 @@ import javax.crypto.SecretKey;
 import org.apache.cxf.rs.security.jose.jwk.JsonWebKey;
 import org.apache.cxf.rs.security.jose.jwt.JwtClaims;
 import org.apache.cxf.rs.security.jose.jwt.JwtToken;
-import org.apache.cxf.rs.security.jose.jwt.JwtTokenReaderWriter;
+import org.apache.cxf.rs.security.jose.jwt.JwtUtils;
 
 
 public class JweJwtCompactConsumer  {
@@ -51,7 +51,7 @@ public class JweJwtCompactConsumer  {
     }
     public JwtToken decryptWith(JweDecryptionProvider jwe) {
         byte[] bytes = jwe.decrypt(jweConsumer.getJweDecryptionInput());
-        JwtClaims claims = new JwtTokenReaderWriter().fromJsonClaims(toString(bytes));
+        JwtClaims claims = JwtUtils.jsonToClaims(toString(bytes));
         return new JwtToken(headers, claims);
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/49ab24bf/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactConsumer.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactConsumer.java
b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactConsumer.java
index 8ec1194..485e022 100644
--- a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactConsumer.java
+++ b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactConsumer.java
@@ -40,15 +40,9 @@ public class JwsCompactConsumer {
     private String decodedJwsPayload;
     private JwsHeaders jwsHeaders;
     public JwsCompactConsumer(String encodedJws) {
-        this(encodedJws, null, null);
+        this(encodedJws, null);
     }
     public JwsCompactConsumer(String encodedJws, String detachedPayload) {
-        this(encodedJws, detachedPayload, null);
-    }
-    protected JwsCompactConsumer(String encodedJws, String detachedPayload, JsonMapObjectReaderWriter
r) {
-        if (r != null) {
-            this.reader = r;
-        }
         String[] parts = JoseUtils.getCompactParts(encodedJws);
         if (parts.length != 3) {
             if (parts.length == 2 && encodedJws.endsWith(".")) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/49ab24bf/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJwtCompactConsumer.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJwtCompactConsumer.java
b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJwtCompactConsumer.java
index e2bcfa8..0b97874 100644
--- a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJwtCompactConsumer.java
+++ b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJwtCompactConsumer.java
@@ -20,12 +20,11 @@ package org.apache.cxf.rs.security.jose.jws;
 
 import org.apache.cxf.rs.security.jose.jwt.JwtClaims;
 import org.apache.cxf.rs.security.jose.jwt.JwtToken;
-import org.apache.cxf.rs.security.jose.jwt.JwtTokenReaderWriter;
 
 public class JwsJwtCompactConsumer extends JwsCompactConsumer {
     private JwtToken token;
     public JwsJwtCompactConsumer(String encodedJws) {
-        super(encodedJws, null, new JwtTokenReaderWriter());
+        super(encodedJws, null);
     }
     public JwtClaims getJwtClaims() {
         return getJwtToken().getClaims();
@@ -33,8 +32,7 @@ public class JwsJwtCompactConsumer extends JwsCompactConsumer {
     public JwtToken getJwtToken() {
         if (token == null) {
             JwsHeaders theHeaders = super.getJwsHeaders();
-            JwtClaims theClaims = 
-                ((JwtTokenReaderWriter)getReader()).fromJsonClaims(getDecodedJwsPayload());
+            JwtClaims theClaims = new JwtClaims(getReader().fromJson(getDecodedJwsPayload()));
             token = new JwtToken(theHeaders, theClaims);
         }
         return token;

http://git-wip-us.apache.org/repos/asf/cxf/blob/49ab24bf/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJwtCompactProducer.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJwtCompactProducer.java
b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJwtCompactProducer.java
index 8b73b02..7c18240 100644
--- a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJwtCompactProducer.java
+++ b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsJwtCompactProducer.java
@@ -18,9 +18,9 @@
  */
 package org.apache.cxf.rs.security.jose.jws;
 
+import org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter;
 import org.apache.cxf.rs.security.jose.jwt.JwtClaims;
 import org.apache.cxf.rs.security.jose.jwt.JwtToken;
-import org.apache.cxf.rs.security.jose.jwt.JwtTokenReaderWriter;
 import org.apache.cxf.rs.security.jose.jwt.JwtUtils;
 
 
@@ -35,7 +35,7 @@ public class JwsJwtCompactProducer extends JwsCompactProducer {
     public JwsJwtCompactProducer(JwsHeaders headers, JwtClaims claims) {
         this(new JwtToken(headers, claims), null);
     }
-    protected JwsJwtCompactProducer(JwtToken token, JwtTokenReaderWriter w) {
+    protected JwsJwtCompactProducer(JwtToken token, JsonMapObjectReaderWriter w) {
         super(new JwsHeaders(token.getJwsHeaders()), w, 
               JwtUtils.claimsToJson(token.getClaims(), w));
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/49ab24bf/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtTokenReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtTokenReaderWriter.java
b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtTokenReaderWriter.java
deleted file mode 100644
index fba861e..0000000
--- a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtTokenReaderWriter.java
+++ /dev/null
@@ -1,55 +0,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.
- */
-package org.apache.cxf.rs.security.jose.jwt;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter;
-
-
-
-
-public class JwtTokenReaderWriter extends JsonMapObjectReaderWriter {
-    private static final Set<String> DATE_PROPERTIES = 
-        new HashSet<String>(Arrays.asList(JwtConstants.CLAIM_EXPIRY, 
-                                          JwtConstants.CLAIM_ISSUED_AT, 
-                                          JwtConstants.CLAIM_NOT_BEFORE));
-
-    public String claimsToJson(JwtClaims claims) {
-        return toJson(claims);
-    }
-
-    public JwtClaims fromJsonClaims(String claimsJson) {
-        JwtClaims claims = new JwtClaims();
-        fromJson(claims, claimsJson);
-        return claims;
-        
-    }
-    
-    @Override
-    protected Object readPrimitiveValue(String name, String json, int from, int to) {
-        Object value = super.readPrimitiveValue(name, json, from, to);
-        if (DATE_PROPERTIES.contains(name)) {
-            value = Long.valueOf(value.toString());
-        }
-        return value;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cxf/blob/49ab24bf/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtUtils.java
b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtUtils.java
index f07a071..cf5e1c2 100644
--- a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtUtils.java
+++ b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtUtils.java
@@ -20,6 +20,7 @@ package org.apache.cxf.rs.security.jose.jwt;
 
 import java.util.Date;
 
+import org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 
@@ -30,14 +31,14 @@ public final class JwtUtils {
     public static String claimsToJson(JwtClaims claims) {
         return claimsToJson(claims, null);
     }
-    public static String claimsToJson(JwtClaims claims, JwtTokenReaderWriter writer) {
+    public static String claimsToJson(JwtClaims claims, JsonMapObjectReaderWriter writer)
{
         if (writer == null) {
-            writer = new JwtTokenReaderWriter();
+            writer = new JsonMapObjectReaderWriter();
         }
-        return writer.claimsToJson(claims);
+        return writer.toJson(claims);
     }
     public static JwtClaims jsonToClaims(String json) {
-        return new JwtTokenReaderWriter().fromJsonClaims(json);
+        return new JwtClaims(new JsonMapObjectReaderWriter().fromJson(json));
     }
     
     public static void validateJwtExpiry(JwtClaims claims, int clockOffset, boolean claimRequired)
{

http://git-wip-us.apache.org/repos/asf/cxf/blob/49ab24bf/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/JwsCompactReaderWriterTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/JwsCompactReaderWriterTest.java
b/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/JwsCompactReaderWriterTest.java
index 19f9f68..35bf6d0 100644
--- a/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/JwsCompactReaderWriterTest.java
+++ b/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jws/JwsCompactReaderWriterTest.java
@@ -29,6 +29,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter;
 import org.apache.cxf.rs.security.jose.common.JoseConstants;
 import org.apache.cxf.rs.security.jose.common.JoseType;
 import org.apache.cxf.rs.security.jose.jwa.SignatureAlgorithm;
@@ -37,7 +38,6 @@ import org.apache.cxf.rs.security.jose.jwk.KeyOperation;
 import org.apache.cxf.rs.security.jose.jwk.KeyType;
 import org.apache.cxf.rs.security.jose.jwt.JwtClaims;
 import org.apache.cxf.rs.security.jose.jwt.JwtToken;
-import org.apache.cxf.rs.security.jose.jwt.JwtTokenReaderWriter;
 import org.apache.cxf.rt.security.crypto.CryptoUtils;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 
@@ -311,8 +311,8 @@ public class JwsCompactReaderWriterTest extends Assert {
     }
 
     
-    private JwtTokenReaderWriter getWriter() {
-        JwtTokenReaderWriter jsonWriter = new JwtTokenReaderWriter();
+    private JsonMapObjectReaderWriter getWriter() {
+        JsonMapObjectReaderWriter jsonWriter = new JsonMapObjectReaderWriter();
         jsonWriter.setFormat(true);
         return jsonWriter;
     }


Mime
View raw message