cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: Setting content type for jws writers
Date Fri, 13 Jun 2014 20:46:51 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 7f60c6cfc -> 86d7c4b90


Setting content type for jws writers


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

Branch: refs/heads/master
Commit: 86d7c4b90bccf66e420ad68340d3ce4322e2544b
Parents: 7f60c6c
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Jun 13 21:46:32 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Jun 13 21:46:32 2014 +0100

----------------------------------------------------------------------
 .../cxf/rs/security/oauth2/jwt/JwtConstants.java    |  1 +
 .../oauth2/jwt/jaxrs/JwsWriterInterceptor.java      | 16 ++++++++++++++--
 .../cxf/rs/security/oauth2/jwt/jwk/JsonWebKey.java  |  1 +
 3 files changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/86d7c4b9/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/JwtConstants.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/JwtConstants.java
b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/JwtConstants.java
index 545cd6e..25ab366 100644
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/JwtConstants.java
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/JwtConstants.java
@@ -29,6 +29,7 @@ public final class JwtConstants {
     public static final String HEADER_X509_URL = "x5u";
     public static final String HEADER_X509_CHAIN = "x5c";
     public static final String HEADER_X509_THUMBPRINT = "x5t";
+    public static final String HEADER_X509_THUMBPRINT_SHA256 = "x5t#S256";
     public static final String HEADER_JSON_WEB_KEY = "jwk";
     public static final String HEADER_JSON_WEB_KEY_SET = "jku";
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/86d7c4b9/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jaxrs/JwsWriterInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jaxrs/JwsWriterInterceptor.java
b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jaxrs/JwsWriterInterceptor.java
index a7beafb..3ec449b 100644
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jaxrs/JwsWriterInterceptor.java
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jaxrs/JwsWriterInterceptor.java
@@ -23,16 +23,19 @@ import java.io.OutputStream;
 
 import javax.annotation.Priority;
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.ext.WriterInterceptor;
 import javax.ws.rs.ext.WriterInterceptorContext;
 
 import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.rs.security.oauth2.jws.JwsCompactProducer;
 import org.apache.cxf.rs.security.oauth2.jwt.Algorithm;
 import org.apache.cxf.rs.security.oauth2.jwt.JwtHeaders;
 
 @Priority(Priorities.JWS_WRITE_PRIORITY)
 public class JwsWriterInterceptor extends AbstractJwsWriterProvider implements WriterInterceptor
{
+    private boolean contentTypeRequired;
     @Override
     public void aroundWriteTo(WriterInterceptorContext ctx) throws IOException, WebApplicationException
{
         OutputStream actualOs = ctx.getOutputStream();
@@ -40,9 +43,18 @@ public class JwsWriterInterceptor extends AbstractJwsWriterProvider implements
W
         ctx.setOutputStream(cos);
         ctx.proceed();
         
-        JwsCompactProducer p = new JwsCompactProducer(new JwtHeaders(Algorithm.SHA256withRSA.getJwtName()),
-                                                      new String(cos.getBytes(), "UTF-8"));
+        JwtHeaders headers = new JwtHeaders(Algorithm.SHA256withRSA.getJwtName());
+        if (contentTypeRequired) {
+            MediaType mt = ctx.getMediaType();
+            if (mt != null) {
+                headers.setContentType(JAXRSUtils.mediaTypeToString(mt));
+            }
+        }
+        JwsCompactProducer p = new JwsCompactProducer(headers, new String(cos.getBytes(),
"UTF-8"));
         writeJws(p, actualOs);
     }
+    public void setContentTypeRequired(boolean contentTypeRequired) {
+        this.contentTypeRequired = contentTypeRequired;
+    }
         
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/86d7c4b9/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jwk/JsonWebKey.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jwk/JsonWebKey.java
b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jwk/JsonWebKey.java
index e26ee0c..d1573c4 100644
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jwk/JsonWebKey.java
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwt/jwk/JsonWebKey.java
@@ -36,6 +36,7 @@ public class JsonWebKey extends AbstractJwtObject {
     public static final String X509_URL = JwtConstants.HEADER_X509_URL;
     public static final String X509_CHAIN = JwtConstants.HEADER_X509_CHAIN;
     public static final String X509_THUMBPRINT = JwtConstants.HEADER_X509_THUMBPRINT;
+    public static final String X509_THUMBPRINT_SHA256 = JwtConstants.HEADER_X509_THUMBPRINT_SHA256;
     
     public static final String KEY_TYPE_OCTET = "oct";
     public static final String KEY_TYPE_RSA = "RSA";


Mime
View raw message