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 2015/12/03 17:35:20 UTC

cxf git commit: Explicit support for serializing a single audience as String given that Google fails to recognize an array despite the spec text

Repository: cxf
Updated Branches:
  refs/heads/master 8ad8ea6ed -> 02995d073


Explicit support for serializing a single audience as String given that Google fails to recognize an array despite the spec text


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

Branch: refs/heads/master
Commit: 02995d07354ff3408047146195d6269f38322a30
Parents: 8ad8ea6
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Thu Dec 3 16:34:52 2015 +0000
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Thu Dec 3 16:34:52 2015 +0000

----------------------------------------------------------------------
 .../java/demo/jaxrs/server/BigQueryServer.java  |  2 +-
 .../cxf/rs/security/jose/jwt/JwtClaims.java     | 31 ++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/02995d07/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryServer.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryServer.java b/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryServer.java
index 6c047ca..33b8d46 100644
--- a/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryServer.java
+++ b/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryServer.java
@@ -76,7 +76,7 @@ public final class BigQueryServer {
         JwsHeaders headers = new JwsHeaders(JoseType.JWT, SignatureAlgorithm.RS256);
         JwtClaims claims = new JwtClaims();
         claims.setIssuer(issuer);
-        claims.setAudiences(Collections.singletonList("https://www.googleapis.com/oauth2/v3/token"));
+        claims.setAudience("https://www.googleapis.com/oauth2/v3/token");
         
         long issuedAt = OAuthUtils.getIssuedAt();
         claims.setIssuedAt(issuedAt);

http://git-wip-us.apache.org/repos/asf/cxf/blob/02995d07/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtClaims.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtClaims.java b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtClaims.java
index a3c77b9..b924a55 100644
--- a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtClaims.java
+++ b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwt/JwtClaims.java
@@ -23,6 +23,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxrs.json.basic.JsonMapObject;
 
@@ -54,10 +55,40 @@ public class JwtClaims extends JsonMapObject {
         return (String)getClaim(JwtConstants.CLAIM_SUBJECT);
     }
     
+    /**
+     * Set a single audience value which will be serialized as a String
+     * @param audience the audience
+     */
+    public void setAudience(String audience) {
+        setClaim(JwtConstants.CLAIM_AUDIENCE, audience);
+    }
+    
+    /**
+     * Get a single audience value. If the audience claim value is an array then the
+     * first value will be returned.
+     * @return the audience
+     */
+    public String getAudience() {
+        List<String> audiences = getAudiences();
+        if (!StringUtils.isEmpty(audiences)) {
+            return audiences.get(0);
+        } else {
+            return null;
+        }
+    }
+    
+    /**
+     * Set an array of audiences
+     * @param audiences the audiences array
+     */
     public void setAudiences(List<String> audiences) {
         setClaim(JwtConstants.CLAIM_AUDIENCE, audiences);
     }
     
+    /**
+     * Get an array of audiences
+     * @return the audiences array
+     */
     public List<String> getAudiences() {
         Object audiences = getClaim(JwtConstants.CLAIM_AUDIENCE);
         if (audiences instanceof List<?>) {