You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2014/09/10 13:42:07 UTC
git commit: [CXF-5954] Adding the methods for reading/writing
individual keys back to JwkReaderWriter
Repository: cxf
Updated Branches:
refs/heads/master 8f102efd4 -> f7f3fc826
[CXF-5954] Adding the methods for reading/writing individual keys back to JwkReaderWriter
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/f7f3fc82
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/f7f3fc82
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/f7f3fc82
Branch: refs/heads/master
Commit: f7f3fc8263c098d5c880d35433f96a57ced75dde
Parents: 8f102ef
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Wed Sep 10 12:41:48 2014 +0100
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Wed Sep 10 12:41:48 2014 +0100
----------------------------------------------------------------------
.../oauth2/jwk/DefaultJwkReaderWriter.java | 48 ++++++++++++++++++++
.../oauth2/jwk/DefaultJwkSetReaderWriter.java | 38 ----------------
.../cxf/rs/security/oauth2/jwk/JsonWebKeys.java | 29 ++++++++++--
.../rs/security/oauth2/jwk/JwkReaderWriter.java | 27 +++++++++++
.../security/oauth2/jwk/JwkSetReaderWriter.java | 25 ----------
.../cxf/rs/security/oauth2/jwk/JwkUtils.java | 8 ++--
.../rs/security/oauth2/jwk/JsonWebKeyTest.java | 2 +-
7 files changed, 105 insertions(+), 72 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/f7f3fc82/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/DefaultJwkReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/DefaultJwkReaderWriter.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/DefaultJwkReaderWriter.java
new file mode 100644
index 0000000..ece0c7c
--- /dev/null
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/DefaultJwkReaderWriter.java
@@ -0,0 +1,48 @@
+/**
+ * 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.oauth2.jwk;
+
+import org.apache.cxf.rs.security.oauth2.jwt.AbstractJwtObjectReaderWriter;
+
+
+
+
+public class DefaultJwkReaderWriter extends AbstractJwtObjectReaderWriter
+ implements JwkReaderWriter {
+ @Override
+ public String jwkSetToJson(JsonWebKeys jwks) {
+ return toJson(jwks);
+ }
+ @Override
+ public JsonWebKeys jsonToJwkSet(String jwksJson) {
+ JsonWebKeys jwks = new JsonWebKeys();
+ fromJsonInternal(jwks, jwksJson);
+ return jwks;
+ }
+ @Override
+ public String jwkToJson(JsonWebKey jwk) {
+ return toJson(jwk);
+ }
+ @Override
+ public JsonWebKey jsonToJwk(String jwkJson) {
+ JsonWebKey jwk = new JsonWebKey();
+ fromJsonInternal(jwk, jwkJson);
+ return jwk;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/f7f3fc82/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/DefaultJwkSetReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/DefaultJwkSetReaderWriter.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/DefaultJwkSetReaderWriter.java
deleted file mode 100644
index 15492c2..0000000
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/DefaultJwkSetReaderWriter.java
+++ /dev/null
@@ -1,38 +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.oauth2.jwk;
-
-import org.apache.cxf.rs.security.oauth2.jwt.AbstractJwtObjectReaderWriter;
-
-
-
-
-public class DefaultJwkSetReaderWriter extends AbstractJwtObjectReaderWriter
- implements JwkSetReaderWriter {
- @Override
- public String jwkSetToJson(JsonWebKeys jwks) {
- return toJson(jwks);
- }
- @Override
- public JsonWebKeys jsonToJwkSet(String jwksJson) {
- JsonWebKeys jwks = new JsonWebKeys();
- fromJsonInternal(jwks, jwksJson);
- return jwks;
- }
-}
http://git-wip-us.apache.org/repos/asf/cxf/blob/f7f3fc82/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JsonWebKeys.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JsonWebKeys.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JsonWebKeys.java
index a0dd8db..ff21b45 100644
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JsonWebKeys.java
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JsonWebKeys.java
@@ -83,18 +83,39 @@ public class JsonWebKeys extends AbstractJwtObject {
}
Map<String, List<JsonWebKey>> map = new LinkedHashMap<String, List<JsonWebKey>>();
for (JsonWebKey key : keys) {
- String keyType = (String)key.getProperty(propertyName);
- if (keyType != null) {
- List<JsonWebKey> list = map.get(keyType);
+ String propValue = (String)key.getProperty(propertyName);
+ if (propValue != null) {
+ List<JsonWebKey> list = map.get(propValue);
if (list == null) {
list = new LinkedList<JsonWebKey>();
- map.put(keyType, list);
+ map.put(propValue, list);
}
list.add(key);
}
}
return map;
}
+ public Map<String, List<JsonWebKey>> getKeyOperationMap() {
+ List<JsonWebKey> keys = getKeys();
+ if (keys == null) {
+ return Collections.emptyMap();
+ }
+ Map<String, List<JsonWebKey>> map = new LinkedHashMap<String, List<JsonWebKey>>();
+ for (JsonWebKey key : keys) {
+ List<String> ops = key.getKeyOperation();
+ if (ops != null) {
+ for (String op : ops) {
+ List<JsonWebKey> list = map.get(op);
+ if (list == null) {
+ list = new LinkedList<JsonWebKey>();
+ map.put(op, list);
+ }
+ list.add(key);
+ }
+ }
+ }
+ return map;
+ }
public List<JsonWebKey> getKeys(String keyType) {
return getKeyTypeMap().get(keyType);
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/f7f3fc82/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkReaderWriter.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkReaderWriter.java
new file mode 100644
index 0000000..9397bfd
--- /dev/null
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkReaderWriter.java
@@ -0,0 +1,27 @@
+/**
+ * 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.oauth2.jwk;
+
+
+public interface JwkReaderWriter {
+ String jwkToJson(JsonWebKey jwk);
+ JsonWebKey jsonToJwk(String jwkJson);
+ String jwkSetToJson(JsonWebKeys jwkSet);
+ JsonWebKeys jsonToJwkSet(String jwkSetJson);
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/f7f3fc82/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkSetReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkSetReaderWriter.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkSetReaderWriter.java
deleted file mode 100644
index 05bada0..0000000
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkSetReaderWriter.java
+++ /dev/null
@@ -1,25 +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.oauth2.jwk;
-
-
-public interface JwkSetReaderWriter {
- String jwkSetToJson(JsonWebKeys jwkSet);
- JsonWebKeys jsonToJwkSet(String jwkSetJson);
-}
http://git-wip-us.apache.org/repos/asf/cxf/blob/f7f3fc82/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkUtils.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkUtils.java
index 1bb1efa..7beee80 100644
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkUtils.java
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwk/JwkUtils.java
@@ -36,9 +36,9 @@ public final class JwkUtils {
}
public static JsonWebKeys loadPersistJwkSet(Message m, Properties props) {
- return loadPersistJwkSet(m, props, new DefaultJwkSetReaderWriter());
+ return loadPersistJwkSet(m, props, new DefaultJwkReaderWriter());
}
- public static JsonWebKeys loadPersistJwkSet(Message m, Properties props, JwkSetReaderWriter reader) {
+ public static JsonWebKeys loadPersistJwkSet(Message m, Properties props, JwkReaderWriter reader) {
JsonWebKeys jwkSet = (JsonWebKeys)m.getExchange().get(props.get(CryptoUtils.RSSEC_KEY_STORE_FILE));
if (jwkSet == null) {
jwkSet = loadJwkSet(props, m.getExchange().getBus(), reader);
@@ -47,9 +47,9 @@ public final class JwkUtils {
return jwkSet;
}
public static JsonWebKeys loadJwkSet(Properties props, Bus bus) {
- return loadJwkSet(props, bus, new DefaultJwkSetReaderWriter());
+ return loadJwkSet(props, bus, new DefaultJwkReaderWriter());
}
- public static JsonWebKeys loadJwkSet(Properties props, Bus bus, JwkSetReaderWriter reader) {
+ public static JsonWebKeys loadJwkSet(Properties props, Bus bus, JwkReaderWriter reader) {
String keyStoreLoc = props.getProperty(CryptoUtils.RSSEC_KEY_STORE_FILE);
try {
InputStream is = ResourceUtils.getResourceStream(keyStoreLoc, bus);
http://git-wip-us.apache.org/repos/asf/cxf/blob/f7f3fc82/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwk/JsonWebKeyTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwk/JsonWebKeyTest.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwk/JsonWebKeyTest.java
index a740b05..4085666 100644
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwk/JsonWebKeyTest.java
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwk/JsonWebKeyTest.java
@@ -165,7 +165,7 @@ public class JsonWebKeyTest extends Assert {
public JsonWebKeys readKeySet(String fileName) throws Exception {
InputStream is = JsonWebKeyTest.class.getResourceAsStream(fileName);
String s = IOUtils.readStringFromStream(is);
- JwkSetReaderWriter reader = new DefaultJwkSetReaderWriter();
+ JwkReaderWriter reader = new DefaultJwkReaderWriter();
return reader.jsonToJwkSet(s);
}
}