cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Updating JsonWebKeysProvider to support MBW
Date Thu, 26 Nov 2015 12:46:25 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 22338d4ff -> a5d7bcab3


Updating JsonWebKeysProvider to support MBW


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

Branch: refs/heads/master
Commit: a5d7bcab3b03f6a359b45e3c3cb915098138cd1b
Parents: 22338d4
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Nov 26 12:46:08 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Nov 26 12:46:08 2015 +0000

----------------------------------------------------------------------
 .../jose/jaxrs/JsonWebKeysProvider.java         | 24 +++++++++++++++++++-
 .../cxf/rs/security/jose/jwk/JwkUtils.java      |  8 +++++++
 .../rs/security/oidc/idp/OidcKeysService.java   |  2 +-
 3 files changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a5d7bcab/rt/rs/security/jose-parent/jose-jaxrs/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JsonWebKeysProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose-jaxrs/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JsonWebKeysProvider.java
b/rt/rs/security/jose-parent/jose-jaxrs/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JsonWebKeysProvider.java
index a877925..7a4adc7 100644
--- a/rt/rs/security/jose-parent/jose-jaxrs/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JsonWebKeysProvider.java
+++ b/rt/rs/security/jose-parent/jose-jaxrs/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JsonWebKeysProvider.java
@@ -20,6 +20,7 @@ package org.apache.cxf.rs.security.jose.jaxrs;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 
@@ -27,11 +28,12 @@ import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
 
 import org.apache.cxf.rs.security.jose.jwk.JsonWebKeys;
 import org.apache.cxf.rs.security.jose.jwk.JwkUtils;
 
-public class JsonWebKeysProvider implements MessageBodyReader<JsonWebKeys> {
+public class JsonWebKeysProvider implements MessageBodyReader<JsonWebKeys>, MessageBodyWriter<JsonWebKeys>
{
     
     @Override
     public boolean isReadable(Class<?> cls, Type type, Annotation[] anns, MediaType
mt) {
@@ -44,5 +46,25 @@ public class JsonWebKeysProvider implements MessageBodyReader<JsonWebKeys>
{
         WebApplicationException {
         return JwkUtils.readJwkSet(is);
     }
+
+    @Override
+    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,
+                               MediaType mediaType) {
+        return type == JsonWebKeys.class;
+    }
+
+    @Override
+    public long getSize(JsonWebKeys t, Class<?> type, Type genericType, Annotation[]
annotations,
+                        MediaType mediaType) {
+        return -1;
+    }
+
+    @Override
+    public void writeTo(JsonWebKeys t, Class<?> type, Type genericType, Annotation[]
annotations,
+                        MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
+                        OutputStream entityStream) throws IOException, WebApplicationException
{
+        JwkUtils.jwkSetToJson(t, entityStream);
+        
+    }
     
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/a5d7bcab/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
index 38c299a..e5c93c5 100644
--- a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
+++ b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
@@ -18,8 +18,10 @@
  */
 package org.apache.cxf.rs.security.jose.jwk;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.math.BigInteger;
 import java.net.URI;
 import java.nio.charset.StandardCharsets;
@@ -123,9 +125,15 @@ public final class JwkUtils {
     public static String jwkKeyToJson(JsonWebKey jwkKey) {
         return new JwkReaderWriter().jwkToJson(jwkKey);
     }
+    public static void jwkKeyToJson(JsonWebKey jwkKey, OutputStream os) throws IOException
{
+        IOUtils.copy(new ByteArrayInputStream(StringUtils.toBytesUTF8(jwkKeyToJson(jwkKey))),
os);
+    }
     public static String jwkSetToJson(JsonWebKeys jwkSet) {
         return new JwkReaderWriter().jwkSetToJson(jwkSet);
     }
+    public static void jwkSetToJson(JsonWebKeys jwkSet, OutputStream os) throws IOException
{
+        IOUtils.copy(new ByteArrayInputStream(StringUtils.toBytesUTF8(jwkSetToJson(jwkSet))),
os);
+    }
     public static String encodeJwkKey(JsonWebKey jwkKey) {
         return Base64UrlUtility.encode(jwkKeyToJson(jwkKey));
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/a5d7bcab/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcKeysService.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcKeysService.java
b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcKeysService.java
index f6c214f..e2c140d 100644
--- a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcKeysService.java
+++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcKeysService.java
@@ -36,8 +36,8 @@ public class OidcKeysService {
     @GET
     @Produces("application/json")
     public JsonWebKeys getPublicVerificationKeys() {
-        Properties props = JwsUtils.loadSignatureInProperties(true);
         if (keySet == null) {
+            Properties props = JwsUtils.loadSignatureInProperties(true);
             keySet = JwsUtils.loadPublicVerificationKeys(JAXRSUtils.getCurrentMessage(),
props);
         }
         return keySet;


Mime
View raw message