cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: Moving the basic JSON parsing utility code to rt/rs/extension/providers
Date Tue, 14 Oct 2014 12:49:34 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes ffbd7bde5 -> 2545331ef


Moving the basic JSON parsing utility code to rt/rs/extension/providers


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

Branch: refs/heads/3.0.x-fixes
Commit: 2545331efbcb82087891ffe4941d1efa01a1b4ac
Parents: ffbd7bd
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Oct 14 13:48:18 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Oct 14 13:49:16 2014 +0100

----------------------------------------------------------------------
 .../provider/json/AbstractJsonMapObject.java    |  61 +++++
 .../json/JsonMapObjectReaderWriter.java         | 219 ++++++++++++++++++
 rt/rs/security/jose/pom.xml                     |   5 +
 .../rs/security/jose/AbstractJoseObject.java    |  61 -----
 .../jose/AbstractJoseObjectReaderWriter.java    | 230 -------------------
 .../cxf/rs/security/jose/JoseHeaders.java       |   3 +-
 .../security/jose/JoseHeadersReaderWriter.java  |   6 +-
 .../jose/jwk/DefaultJwkReaderWriter.java        |   9 +-
 .../cxf/rs/security/jose/jwk/JsonWebKey.java    |   4 +-
 .../cxf/rs/security/jose/jwk/JsonWebKeys.java   |   4 +-
 .../cxf/rs/security/jose/jwt/JwtClaims.java     |   4 +-
 .../security/jose/jwt/JwtTokenReaderWriter.java |  20 +-
 12 files changed, 320 insertions(+), 306 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/2545331e/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/AbstractJsonMapObject.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/AbstractJsonMapObject.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/AbstractJsonMapObject.java
new file mode 100644
index 0000000..a518a06
--- /dev/null
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/AbstractJsonMapObject.java
@@ -0,0 +1,61 @@
+/**
+ * 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.jaxrs.provider.json;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public abstract class AbstractJsonMapObject {
+    protected Map<String, Object> values = new LinkedHashMap<String, Object>();
+    
+    protected AbstractJsonMapObject() {
+        
+    }
+    
+    protected AbstractJsonMapObject(Map<String, Object> values) {
+        this.values = values;
+    }
+    
+    protected void setValue(String name, Object value) {
+        values.put(name, value);
+    }
+    
+    protected Object getValue(String name) {
+        return values.get(name);
+    }
+
+    public Map<String, Object> asMap() {
+        return new LinkedHashMap<String, Object>(values);
+    }
+    
+    protected Long getLongDate(String name) {
+        Object object = getValue(name);
+        return object instanceof Long ? (Long)object : Long.valueOf(object.toString());
+    }
+    
+    public int hashCode() { 
+        return values.hashCode();
+    }
+    
+    public boolean equals(Object obj) {
+        return obj instanceof AbstractJsonMapObject && ((AbstractJsonMapObject)obj).values.equals(this.values);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/2545331e/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriter.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriter.java
new file mode 100644
index 0000000..ca30c7d
--- /dev/null
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriter.java
@@ -0,0 +1,219 @@
+/**
+ * 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.jaxrs.provider.json;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+
+
+public class JsonMapObjectReaderWriter {
+    private boolean format;
+    
+    public String toJson(AbstractJsonMapObject jwt) {
+        StringBuilder sb = new StringBuilder();
+        toJsonInternal(sb, jwt.asMap());
+        return sb.toString();
+    }
+
+    protected void toJsonInternal(StringBuilder sb, Map<String, Object> map) {
+        sb.append("{");
+        for (Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator();
it.hasNext();) {
+            Map.Entry<String, Object> entry = it.next();
+            sb.append("\"").append(entry.getKey()).append("\"");
+            sb.append(":");
+            toJsonInternal(sb, entry.getValue(), it.hasNext());
+        }
+        sb.append("}");
+    }
+    
+    protected void toJsonInternal(StringBuilder sb, Object[] array) {
+        toJsonInternal(sb, Arrays.asList(array));
+    }
+    
+    protected void toJsonInternal(StringBuilder sb, Collection<?> coll) {
+        sb.append("[");
+        formatIfNeeded(sb);
+        for (Iterator<?> iter = coll.iterator(); iter.hasNext();) {
+            toJsonInternal(sb, iter.next(), iter.hasNext());
+        }
+        formatIfNeeded(sb);
+        sb.append("]");
+    }
+    
+    @SuppressWarnings("unchecked")
+    protected void toJsonInternal(StringBuilder sb, Object value, boolean hasNext) {
+        if (AbstractJsonMapObject.class.isAssignableFrom(value.getClass())) {
+            sb.append(toJson((AbstractJsonMapObject)value));
+        } else if (value.getClass().isArray()) {
+            toJsonInternal(sb, (Object[])value);
+        } else if (Collection.class.isAssignableFrom(value.getClass())) {
+            toJsonInternal(sb, (Collection<?>)value);
+        } else if (Map.class.isAssignableFrom(value.getClass())) {
+            toJsonInternal(sb, (Map<String, Object>)value);
+        } else {
+            if (value.getClass() == String.class) {
+                sb.append("\"");
+            }
+            sb.append(value);
+            if (value.getClass() == String.class) {
+                sb.append("\"");
+            }
+        }
+        if (hasNext) {
+            sb.append(",");
+            formatIfNeeded(sb);
+        }
+        
+    }
+    
+    protected void formatIfNeeded(StringBuilder sb) {
+        if (format) {
+            sb.append("\r\n ");
+        }
+    }
+        
+    public void fromJson(AbstractJsonMapObject jwt, String json) {
+        String theJson = json.trim();
+        JsonObjectSettable joseObject = new JsonObjectSettable(jwt);
+        readJsonObjectAsSettable(joseObject, theJson.substring(1, theJson.length() - 1));
+    }
+    
+    
+    
+    protected void readJsonObjectAsSettable(Settable values, String json) {
+        for (int i = 0; i < json.length(); i++) {
+            if (isWhiteSpace(json.charAt(i))) {
+                continue;
+            }
+            
+            int closingQuote = json.indexOf('"', i + 1);
+            int from = json.charAt(i) == '"' ? i + 1 : i;
+            String name = json.substring(from, closingQuote);
+            int sepIndex = json.indexOf(':', closingQuote + 1);
+            
+            int j = 1;
+            while (isWhiteSpace(json.charAt(sepIndex + j))) {
+                j++;
+            }
+            if (json.charAt(sepIndex + j) == '{') {
+                int closingIndex = getClosingIndex(json, '{', '}', sepIndex + j);
+                String newJson = json.substring(sepIndex + j + 1, closingIndex);
+                MapSettable nextMap = new MapSettable();
+                readJsonObjectAsSettable(nextMap, newJson);
+                values.put(name, nextMap.map);
+                i = closingIndex + 1;
+            } else if (json.charAt(sepIndex + j) == '[') {
+                int closingIndex = getClosingIndex(json, '[', ']', sepIndex + j);
+                String newJson = json.substring(sepIndex + j + 1, closingIndex);
+                values.put(name, readJwtObjectAsList(name, newJson));
+                i = closingIndex + 1;
+            } else {
+                int commaIndex = getCommaIndex(json, sepIndex + j);
+                Object value = readPrimitiveValue(name, json, sepIndex + j, commaIndex);
+                values.put(name, value);
+                i = commaIndex + 1;
+            }
+            
+        }
+    }
+    protected List<Object> readJwtObjectAsList(String name, String json) {
+        List<Object> values = new LinkedList<Object>();
+        for (int i = 0; i < json.length(); i++) {
+            if (isWhiteSpace(json.charAt(i))) {
+                continue;
+            }
+            if (json.charAt(i) == '{') {
+                int closingIndex = getClosingIndex(json, '{', '}', i);
+                MapSettable nextMap = new MapSettable();
+                readJsonObjectAsSettable(nextMap, json.substring(i + 1, closingIndex));
+                values.add(nextMap.map);
+                i = closingIndex + 1;
+            } else {
+                int commaIndex = getCommaIndex(json, i);
+                Object value = readPrimitiveValue(name, json, i, commaIndex);
+                values.add(value);
+                i = commaIndex + 1;
+            }
+        }
+        
+        return values;
+    }
+    protected Object readPrimitiveValue(String name, String json, int from, int to) {
+        Object value = json.substring(from, to);
+        String valueStr = value.toString().trim(); 
+        if (valueStr.startsWith("\"")) {
+            value = valueStr.substring(1, valueStr.length() - 1);
+        } else if ("true".equals(value) || "false".equals(value)) {
+            value = Boolean.valueOf(valueStr);
+        } 
+        return value;
+    }
+    
+    protected static int getCommaIndex(String json, int from) {
+        int commaIndex = json.indexOf(",", from);
+        if (commaIndex == -1) {
+            commaIndex = json.length();
+        }
+        return commaIndex;
+    }
+    protected int getClosingIndex(String json, char openChar, char closeChar, int from) {
+        int nextOpenIndex = json.indexOf(openChar, from + 1);
+        int closingIndex = json.indexOf(closeChar, from + 1);
+        while (nextOpenIndex != -1 && nextOpenIndex < closingIndex) {
+            nextOpenIndex = json.indexOf(openChar, closingIndex + 1);
+            closingIndex = json.indexOf(closeChar, closingIndex + 1);
+        }
+        return closingIndex;
+    }
+    protected boolean isWhiteSpace(char jsonChar) {
+        return jsonChar == ' ' || jsonChar == '\r' || jsonChar == '\n' || jsonChar == '\t';
+    }
+
+    public void setFormat(boolean format) {
+        this.format = format;
+    }
+
+    private interface Settable {
+        void put(String key, Object value);
+    }
+    private static class MapSettable implements Settable {
+        private Map<String, Object> map = new LinkedHashMap<String, Object>();
+        public void put(String key, Object value) {
+            map.put(key, value);
+        }
+        
+    }
+    private static class JsonObjectSettable implements Settable {
+        private AbstractJsonMapObject jose;
+        public JsonObjectSettable(AbstractJsonMapObject jose) {
+            this.jose = jose;
+        }
+        public void put(String key, Object value) {
+            jose.setValue(key, value);
+        }
+    }
+
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/2545331e/rt/rs/security/jose/pom.xml
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/pom.xml b/rt/rs/security/jose/pom.xml
index 5b17661..77f8513 100644
--- a/rt/rs/security/jose/pom.xml
+++ b/rt/rs/security/jose/pom.xml
@@ -42,6 +42,11 @@
             <version>${project.version}</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-rs-extension-providers</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
             <groupId>org.bouncycastle</groupId>
             <artifactId>bcprov-ext-jdk15on</artifactId>
             <version>${cxf.bcprov.version}</version>

http://git-wip-us.apache.org/repos/asf/cxf/blob/2545331e/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/AbstractJoseObject.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/AbstractJoseObject.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/AbstractJoseObject.java
deleted file mode 100644
index 1db9f1c..0000000
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/AbstractJoseObject.java
+++ /dev/null
@@ -1,61 +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;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public abstract class AbstractJoseObject {
-    protected Map<String, Object> values = new LinkedHashMap<String, Object>();
-    
-    protected AbstractJoseObject() {
-        
-    }
-    
-    protected AbstractJoseObject(Map<String, Object> values) {
-        this.values = values;
-    }
-    
-    protected void setValue(String name, Object value) {
-        values.put(name, value);
-    }
-    
-    protected Object getValue(String name) {
-        return values.get(name);
-    }
-
-    public Map<String, Object> asMap() {
-        return new LinkedHashMap<String, Object>(values);
-    }
-    
-    protected Long getLongDate(String name) {
-        Object object = getValue(name);
-        return object instanceof Long ? (Long)object : Long.valueOf(object.toString());
-    }
-    
-    public int hashCode() { 
-        return values.hashCode();
-    }
-    
-    public boolean equals(Object obj) {
-        return obj instanceof AbstractJoseObject && ((AbstractJoseObject)obj).values.equals(this.values);
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/cxf/blob/2545331e/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/AbstractJoseObjectReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/AbstractJoseObjectReaderWriter.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/AbstractJoseObjectReaderWriter.java
deleted file mode 100644
index d1cbcb7..0000000
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/AbstractJoseObjectReaderWriter.java
+++ /dev/null
@@ -1,230 +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;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.cxf.rs.security.jose.jwt.JwtConstants;
-
-
-
-public class AbstractJoseObjectReaderWriter {
-    private static final Set<String> DATE_PROPERTIES = 
-        new HashSet<String>(Arrays.asList(JwtConstants.CLAIM_EXPIRY, 
-                                          JwtConstants.CLAIM_ISSUED_AT, 
-                                          JwtConstants.CLAIM_NOT_BEFORE));
-    private boolean format;
-    
-    protected String toJson(AbstractJoseObject jwt) {
-        StringBuilder sb = new StringBuilder();
-        toJsonInternal(sb, jwt.asMap());
-        return sb.toString();
-    }
-
-    protected void toJsonInternal(StringBuilder sb, Map<String, Object> map) {
-        sb.append("{");
-        for (Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator();
it.hasNext();) {
-            Map.Entry<String, Object> entry = it.next();
-            sb.append("\"").append(entry.getKey()).append("\"");
-            sb.append(":");
-            toJsonInternal(sb, entry.getValue(), it.hasNext());
-        }
-        sb.append("}");
-    }
-    
-    protected void toJsonInternal(StringBuilder sb, Object[] array) {
-        toJsonInternal(sb, Arrays.asList(array));
-    }
-    
-    protected void toJsonInternal(StringBuilder sb, Collection<?> coll) {
-        sb.append("[");
-        formatIfNeeded(sb);
-        for (Iterator<?> iter = coll.iterator(); iter.hasNext();) {
-            toJsonInternal(sb, iter.next(), iter.hasNext());
-        }
-        formatIfNeeded(sb);
-        sb.append("]");
-    }
-    
-    @SuppressWarnings("unchecked")
-    protected void toJsonInternal(StringBuilder sb, Object value, boolean hasNext) {
-        if (AbstractJoseObject.class.isAssignableFrom(value.getClass())) {
-            sb.append(toJson((AbstractJoseObject)value));
-        } else if (value.getClass().isArray()) {
-            toJsonInternal(sb, (Object[])value);
-        } else if (Collection.class.isAssignableFrom(value.getClass())) {
-            toJsonInternal(sb, (Collection<?>)value);
-        } else if (Map.class.isAssignableFrom(value.getClass())) {
-            toJsonInternal(sb, (Map<String, Object>)value);
-        } else {
-            if (value.getClass() == String.class) {
-                sb.append("\"");
-            }
-            sb.append(value);
-            if (value.getClass() == String.class) {
-                sb.append("\"");
-            }
-        }
-        if (hasNext) {
-            sb.append(",");
-            formatIfNeeded(sb);
-        }
-        
-    }
-    
-    protected void formatIfNeeded(StringBuilder sb) {
-        if (format) {
-            sb.append("\r\n ");
-        }
-    }
-        
-    protected void fromJsonInternal(AbstractJoseObject jwt, String json) {
-        String theJson = json.trim();
-        JoseObjectSettable joseObject = new JoseObjectSettable(jwt);
-        readJwtObjectAsMap(joseObject, theJson.substring(1, theJson.length() - 1));
-    }
-    
-    
-    
-    protected void readJwtObjectAsMap(Settable values, String json) {
-        for (int i = 0; i < json.length(); i++) {
-            if (isWhiteSpace(json.charAt(i))) {
-                continue;
-            }
-            
-            int closingQuote = json.indexOf('"', i + 1);
-            int from = json.charAt(i) == '"' ? i + 1 : i;
-            String name = json.substring(from, closingQuote);
-            int sepIndex = json.indexOf(':', closingQuote + 1);
-            
-            int j = 1;
-            while (isWhiteSpace(json.charAt(sepIndex + j))) {
-                j++;
-            }
-            if (json.charAt(sepIndex + j) == '{') {
-                int closingIndex = getClosingIndex(json, '{', '}', sepIndex + j);
-                String newJson = json.substring(sepIndex + j + 1, closingIndex);
-                MapSettable nextMap = new MapSettable();
-                readJwtObjectAsMap(nextMap, newJson);
-                values.put(name, nextMap.map);
-                i = closingIndex + 1;
-            } else if (json.charAt(sepIndex + j) == '[') {
-                int closingIndex = getClosingIndex(json, '[', ']', sepIndex + j);
-                String newJson = json.substring(sepIndex + j + 1, closingIndex);
-                values.put(name, readJwtObjectAsList(newJson));
-                i = closingIndex + 1;
-            } else {
-                int commaIndex = getCommaIndex(json, sepIndex + j);
-                Object value = readPrimitiveValue(json, sepIndex + j, commaIndex);
-                if (DATE_PROPERTIES.contains(name)) {
-                    value = Long.valueOf(value.toString());
-                }
-                values.put(name, value);
-                i = commaIndex + 1;
-            }
-            
-        }
-    }
-    protected List<Object> readJwtObjectAsList(String json) {
-        List<Object> values = new LinkedList<Object>();
-        for (int i = 0; i < json.length(); i++) {
-            if (isWhiteSpace(json.charAt(i))) {
-                continue;
-            }
-            if (json.charAt(i) == '{') {
-                int closingIndex = getClosingIndex(json, '{', '}', i);
-                MapSettable nextMap = new MapSettable();
-                readJwtObjectAsMap(nextMap, json.substring(i + 1, closingIndex));
-                values.add(nextMap.map);
-                i = closingIndex + 1;
-            } else {
-                int commaIndex = getCommaIndex(json, i);
-                Object value = readPrimitiveValue(json, i, commaIndex);
-                values.add(value);
-                i = commaIndex + 1;
-            }
-        }
-        
-        return values;
-    }
-    protected Object readPrimitiveValue(String json, int from, int to) {
-        Object value = json.substring(from, to);
-        String valueStr = value.toString().trim(); 
-        if (valueStr.startsWith("\"")) {
-            value = valueStr.substring(1, valueStr.length() - 1);
-        } else if ("true".equals(value) || "false".equals(value)) {
-            value = Boolean.valueOf(valueStr);
-        } 
-        return value;
-    }
-    
-    protected static int getCommaIndex(String json, int from) {
-        int commaIndex = json.indexOf(",", from);
-        if (commaIndex == -1) {
-            commaIndex = json.length();
-        }
-        return commaIndex;
-    }
-    protected int getClosingIndex(String json, char openChar, char closeChar, int from) {
-        int nextOpenIndex = json.indexOf(openChar, from + 1);
-        int closingIndex = json.indexOf(closeChar, from + 1);
-        while (nextOpenIndex != -1 && nextOpenIndex < closingIndex) {
-            nextOpenIndex = json.indexOf(openChar, closingIndex + 1);
-            closingIndex = json.indexOf(closeChar, closingIndex + 1);
-        }
-        return closingIndex;
-    }
-    protected boolean isWhiteSpace(char jsonChar) {
-        return jsonChar == ' ' || jsonChar == '\r' || jsonChar == '\n' || jsonChar == '\t';
-    }
-
-    public void setFormat(boolean format) {
-        this.format = format;
-    }
-
-    private interface Settable {
-        void put(String key, Object value);
-    }
-    private static class MapSettable implements Settable {
-        private Map<String, Object> map = new LinkedHashMap<String, Object>();
-        public void put(String key, Object value) {
-            map.put(key, value);
-        }
-        
-    }
-    private static class JoseObjectSettable implements Settable {
-        private AbstractJoseObject jose;
-        public JoseObjectSettable(AbstractJoseObject jose) {
-            this.jose = jose;
-        }
-        public void put(String key, Object value) {
-            jose.setValue(key, value);
-        }
-    }
-
-    
-}

http://git-wip-us.apache.org/repos/asf/cxf/blob/2545331e/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/JoseHeaders.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/JoseHeaders.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/JoseHeaders.java
index 3577669..ea1b984 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/JoseHeaders.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/JoseHeaders.java
@@ -25,9 +25,10 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.jaxrs.provider.json.AbstractJsonMapObject;
 import org.apache.cxf.rs.security.jose.jwk.JsonWebKey;
 
-public class JoseHeaders extends AbstractJoseObject {
+public class JoseHeaders extends AbstractJsonMapObject {
     private Map<String, Integer> headerUpdateCount;
     public JoseHeaders() {
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/2545331e/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/JoseHeadersReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/JoseHeadersReaderWriter.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/JoseHeadersReaderWriter.java
index be20ca3..abcdf8f 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/JoseHeadersReaderWriter.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/JoseHeadersReaderWriter.java
@@ -18,11 +18,13 @@
  */
 package org.apache.cxf.rs.security.jose;
 
+import org.apache.cxf.jaxrs.provider.json.JsonMapObjectReaderWriter;
 
 
 
 
-public class JoseHeadersReaderWriter extends AbstractJoseObjectReaderWriter
+
+public class JoseHeadersReaderWriter extends JsonMapObjectReaderWriter
     implements JoseHeadersReader, JoseHeadersWriter {
     @Override
     public String headersToJson(JoseHeaders headers) {
@@ -32,7 +34,7 @@ public class JoseHeadersReaderWriter extends AbstractJoseObjectReaderWriter
     @Override
     public JoseHeaders fromJsonHeaders(String headersJson) {
         JoseHeaders headers = new JoseHeaders();
-        fromJsonInternal(headers, headersJson);
+        fromJson(headers, headersJson);
         return headers;
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/2545331e/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/DefaultJwkReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/DefaultJwkReaderWriter.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/DefaultJwkReaderWriter.java
index fa4f8ba..5593e0b 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/DefaultJwkReaderWriter.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/DefaultJwkReaderWriter.java
@@ -18,12 +18,13 @@
  */
 package org.apache.cxf.rs.security.jose.jwk;
 
-import org.apache.cxf.rs.security.jose.AbstractJoseObjectReaderWriter;
+import org.apache.cxf.jaxrs.provider.json.JsonMapObjectReaderWriter;
 
 
 
 
-public class DefaultJwkReaderWriter extends AbstractJoseObjectReaderWriter
+
+public class DefaultJwkReaderWriter extends JsonMapObjectReaderWriter
     implements JwkReaderWriter {
     @Override
     public String jwkSetToJson(JsonWebKeys jwks) {
@@ -32,7 +33,7 @@ public class DefaultJwkReaderWriter extends AbstractJoseObjectReaderWriter
     @Override
     public JsonWebKeys jsonToJwkSet(String jwksJson) {
         JsonWebKeys jwks = new JsonWebKeys();
-        fromJsonInternal(jwks, jwksJson);
+        fromJson(jwks, jwksJson);
         return jwks;
     }
     @Override
@@ -42,7 +43,7 @@ public class DefaultJwkReaderWriter extends AbstractJoseObjectReaderWriter
     @Override
     public JsonWebKey jsonToJwk(String jwkJson) {
         JsonWebKey jwk = new JsonWebKey();
-        fromJsonInternal(jwk, jwkJson);
+        fromJson(jwk, jwkJson);
         return jwk;
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/2545331e/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKey.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKey.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKey.java
index ef594e6..aa4ee13 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKey.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKey.java
@@ -22,11 +22,11 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.rs.security.jose.AbstractJoseObject;
+import org.apache.cxf.jaxrs.provider.json.AbstractJsonMapObject;
 import org.apache.cxf.rs.security.jose.JoseConstants;
 
 
-public class JsonWebKey extends AbstractJoseObject {
+public class JsonWebKey extends AbstractJsonMapObject {
     
     public static final String KEY_TYPE = "kty";
     public static final String PUBLIC_KEY_USE = "use";

http://git-wip-us.apache.org/repos/asf/cxf/blob/2545331e/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKeys.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKeys.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKeys.java
index c614622..54130d2 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKeys.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKeys.java
@@ -25,9 +25,9 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.rs.security.jose.AbstractJoseObject;
+import org.apache.cxf.jaxrs.provider.json.AbstractJsonMapObject;
 
-public class JsonWebKeys extends AbstractJoseObject {
+public class JsonWebKeys extends AbstractJsonMapObject {
     public static final String KEYS_PROPERTY = "keys";
     public List<JsonWebKey> getKeys() {
         List<?> list = (List<?>)super.getValue(KEYS_PROPERTY);

http://git-wip-us.apache.org/repos/asf/cxf/blob/2545331e/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtClaims.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtClaims.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtClaims.java
index 8944e07..7f6a1e5 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtClaims.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtClaims.java
@@ -21,12 +21,12 @@ package org.apache.cxf.rs.security.jose.jwt;
 
 import java.util.Map;
 
-import org.apache.cxf.rs.security.jose.AbstractJoseObject;
+import org.apache.cxf.jaxrs.provider.json.AbstractJsonMapObject;
 
 
 
 
-public class JwtClaims extends AbstractJoseObject {
+public class JwtClaims extends AbstractJsonMapObject {
     
     public JwtClaims() {
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/2545331e/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtTokenReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtTokenReaderWriter.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtTokenReaderWriter.java
index d3e7db4..15a5572 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtTokenReaderWriter.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtTokenReaderWriter.java
@@ -18,6 +18,10 @@
  */
 package org.apache.cxf.rs.security.jose.jwt;
 
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
 import org.apache.cxf.rs.security.jose.JoseHeadersReaderWriter;
 
 
@@ -25,7 +29,10 @@ import org.apache.cxf.rs.security.jose.JoseHeadersReaderWriter;
 
 public class JwtTokenReaderWriter extends JoseHeadersReaderWriter
     implements JwtTokenReader, JwtTokenWriter {
-    
+    private static final Set<String> DATE_PROPERTIES = 
+        new HashSet<String>(Arrays.asList(JwtConstants.CLAIM_EXPIRY, 
+                                          JwtConstants.CLAIM_ISSUED_AT, 
+                                          JwtConstants.CLAIM_NOT_BEFORE));
 
     @Override
     public String claimsToJson(JwtClaims claims) {
@@ -41,7 +48,7 @@ public class JwtTokenReaderWriter extends JoseHeadersReaderWriter
     @Override
     public JwtClaims fromJsonClaims(String claimsJson) {
         JwtClaims claims = new JwtClaims();
-        fromJsonInternal(claims, claimsJson);
+        fromJson(claims, claimsJson);
         return claims;
         
     }
@@ -61,4 +68,13 @@ public class JwtTokenReaderWriter extends JoseHeadersReaderWriter
     public JwtHeaders fromJsonHeaders(String jsonHeaders) {
         return new JwtHeaders(super.fromJsonHeaders(jsonHeaders)); 
     }
+    
+    @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;
+    }
 }


Mime
View raw message