Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 3459edc0e -> 5dc39daa0
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/5dc39daa Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/5dc39daa Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/5dc39daa Branch: refs/heads/3.0.x-fixes Commit: 5dc39daa045f4ddd1fdbc064235d69a62b08e398 Parents: 3459edc Author: Sergey Beryozkin <[email protected]> Authored: Thu Dec 3 16:34:52 2015 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Thu Dec 3 16:39:23 2015 +0000 ---------------------------------------------------------------------- .../cxf/rs/security/jose/jwt/JwtClaims.java | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/5dc39daa/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<?>) {
