Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/ClaimJwtException.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/ClaimJwtException.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/ClaimJwtException.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +/** + * ClaimJwtException is a subclass of the {@link JwtException} that is thrown after a validation of an JTW claim failed. + * + * @since 0.5 + */ +public abstract class ClaimJwtException extends JwtException { + + public static final String INCORRECT_EXPECTED_CLAIM_MESSAGE_TEMPLATE = "Expected %s claim to be: %s, but was: %s."; + public static final String MISSING_EXPECTED_CLAIM_MESSAGE_TEMPLATE = "Expected %s claim to be: %s, but was not present in the JWT claims."; + + private final Header header; + + private final Claims claims; + + protected ClaimJwtException(Header header, Claims claims, String message) { + super(message); + this.header = header; + this.claims = claims; + } + + protected ClaimJwtException(Header header, Claims claims, String message, Throwable cause) { + super(message, cause); + this.header = header; + this.claims = claims; + } + + public Claims getClaims() { + return claims; + } + + public Header getHeader() { + return header; + } +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Claims.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Claims.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Claims.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +import java.util.Date; +import java.util.Map; + +/** + * A JWT Claims set. + * + *
This is ultimately a JSON map and any values can be added to it, but JWT standard names are provided as + * type-safe getters and setters for convenience.
+ * + *Because this interface extends {@code Map<String, Object>}, if you would like to add your own properties, + * you simply use map methods, for example:
+ * + *+ * claims.{@link Map#put(Object, Object) put}("someKey", "someValue"); + *+ * + *
It is easiest to create a {@code Claims} instance by calling one of the + * {@link Jwts#claims() JWTs.claims()} factory methods.
+ * + * @since 0.1 + */ +public interface Claims extends Map"iss"
*/
+ public static final String ISSUER = "iss";
+
+ /** JWT {@code Subject} claims parameter name: "sub"
*/
+ public static final String SUBJECT = "sub";
+
+ /** JWT {@code Audience} claims parameter name: "aud"
*/
+ public static final String AUDIENCE = "aud";
+
+ /** JWT {@code Expiration} claims parameter name: "exp"
*/
+ public static final String EXPIRATION = "exp";
+
+ /** JWT {@code Not Before} claims parameter name: "nbf"
*/
+ public static final String NOT_BEFORE = "nbf";
+
+ /** JWT {@code Issued At} claims parameter name: "iat"
*/
+ public static final String ISSUED_AT = "iat";
+
+ /** JWT {@code JWT ID} claims parameter name: "jti"
*/
+ public static final String ID = "jti";
+
+ /**
+ * Returns the JWT
+ * iss
(issuer) value or {@code null} if not present.
+ *
+ * @return the JWT {@code iss} value or {@code null} if not present.
+ */
+ String getIssuer();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override //only for better/targeted JavaDoc
+ Claims setIssuer(String iss);
+
+ /**
+ * Returns the JWT
+ * sub
(subject) value or {@code null} if not present.
+ *
+ * @return the JWT {@code sub} value or {@code null} if not present.
+ */
+ String getSubject();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override //only for better/targeted JavaDoc
+ Claims setSubject(String sub);
+
+ /**
+ * Returns the JWT
+ * aud
(audience) value or {@code null} if not present.
+ *
+ * @return the JWT {@code aud} value or {@code null} if not present.
+ */
+ String getAudience();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override //only for better/targeted JavaDoc
+ Claims setAudience(String aud);
+
+ /**
+ * Returns the JWT
+ * exp
(expiration) timestamp or {@code null} if not present.
+ *
+ * A JWT obtained after this timestamp should not be used.
+ * + * @return the JWT {@code exp} value or {@code null} if not present. + */ + Date getExpiration(); + + /** + * {@inheritDoc} + */ + @Override //only for better/targeted JavaDoc + Claims setExpiration(Date exp); + + /** + * Returns the JWT + *nbf
(not before) timestamp or {@code null} if not present.
+ *
+ * A JWT obtained before this timestamp should not be used.
+ * + * @return the JWT {@code nbf} value or {@code null} if not present. + */ + Date getNotBefore(); + + /** + * {@inheritDoc} + */ + @Override //only for better/targeted JavaDoc + Claims setNotBefore(Date nbf); + + /** + * Returns the JWT + *iat
(issued at) timestamp or {@code null} if not present.
+ *
+ * If present, this value is the timestamp when the JWT was created.
+ * + * @return the JWT {@code nbf} value or {@code null} if not present. + */ + Date getIssuedAt(); + + /** + * {@inheritDoc} + */ + @Override //only for better/targeted JavaDoc + Claims setIssuedAt(Date iat); + + /** + * Returns the JWTs + *jti
(JWT ID) value or {@code null} if not present.
+ *
+ * This value is a CaSe-SenSiTiVe unique identifier for the JWT. If available, this value is expected to be + * assigned in a manner that ensures that there is a negligible probability that the same value will be + * accidentally + * assigned to a different data object. The ID can be used to prevent the JWT from being replayed.
+ * + * @return the JWT {@code jti} value or {@code null} if not present. + */ + String getId(); + + /** + * {@inheritDoc} + */ + @Override //only for better/targeted JavaDoc + Claims setId(String jti); + +iss
(issuer) value. A {@code null} value will remove the property from the JSON map.
+ *
+ * @param iss the JWT {@code iss} value or {@code null} to remove the property from the JSON map.
+ * @return the {@code Claims} instance for method chaining.
+ */
+ T setIssuer(String iss);
+
+ /**
+ * Sets the JWT
+ * sub
(subject) value. A {@code null} value will remove the property from the JSON map.
+ *
+ * @param sub the JWT {@code sub} value or {@code null} to remove the property from the JSON map.
+ * @return the {@code Claims} instance for method chaining.
+ */
+ T setSubject(String sub);
+
+ /**
+ * Sets the JWT
+ * aud
(audience) value. A {@code null} value will remove the property from the JSON map.
+ *
+ * @param aud the JWT {@code aud} value or {@code null} to remove the property from the JSON map.
+ * @return the {@code Claims} instance for method chaining.
+ */
+ T setAudience(String aud);
+
+ /**
+ * Sets the JWT
+ * exp
(expiration) timestamp. A {@code null} value will remove the property from the JSON map.
+ *
+ * A JWT obtained after this timestamp should not be used.
+ * + * @param exp the JWT {@code exp} value or {@code null} to remove the property from the JSON map. + * @return the {@code Claims} instance for method chaining. + */ + T setExpiration(Date exp); + + /** + * Sets the JWT + *nbf
(not before) timestamp. A {@code null} value will remove the property from the JSON map.
+ *
+ * A JWT obtained before this timestamp should not be used.
+ * + * @param nbf the JWT {@code nbf} value or {@code null} to remove the property from the JSON map. + * @return the {@code Claims} instance for method chaining. + */ + T setNotBefore(Date nbf); + + /** + * Sets the JWT + *iat
(issued at) timestamp. A {@code null} value will remove the property from the JSON map.
+ *
+ * The value is the timestamp when the JWT was created.
+ * + * @param iat the JWT {@code iat} value or {@code null} to remove the property from the JSON map. + * @return the {@code Claims} instance for method chaining. + */ + T setIssuedAt(Date iat); + + /** + * Sets the JWT + *jti
(JWT ID) value. A {@code null} value will remove the property from the JSON map.
+ *
+ * This value is a CaSe-SenSiTiVe unique identifier for the JWT. If specified, this value MUST be assigned in a + * manner that ensures that there is a negligible probability that the same value will be accidentally + * assigned to a different data object. The ID can be used to prevent the JWT from being replayed.
+ * + * @param jti the JWT {@code jti} value or {@code null} to remove the property from the JSON map. + * @return the {@code Claims} instance for method chaining. + */ + T setId(String jti); +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Clock.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Clock.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Clock.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,18 @@ +package io.jsonwebtoken; + +import java.util.Date; + +/** + * A clock represents a time source that can be used when creating and verifying JWTs. + * + * @since 0.7.0 + */ +public interface Clock { + + /** + * Returns the clock's current timestamp at the instant the method is invoked. + * + * @return the clock's current timestamp at the instant the method is invoked. + */ + Date now(); +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/CompressionCodec.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/CompressionCodec.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/CompressionCodec.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2015 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +/** + * Compresses and decompresses byte arrays according to a compression algorithm. + * + * @see io.jsonwebtoken.impl.compression.DeflateCompressionCodec + * @see io.jsonwebtoken.impl.compression.GzipCompressionCodec + * @since 0.6.0 + */ +public interface CompressionCodec { + + /** + * The algorithm name to use as the JWT's {@code calg} header value. + * + * @return the algorithm name to use as the JWT's {@code calg} header value. + */ + String getAlgorithmName(); + + /** + * Compresses the specified byte array according to the compression {@link #getAlgorithmName() algorithm}. + * + * @param payload bytes to compress + * @return compressed bytes + * @throws CompressionException if the specified byte array cannot be compressed according to the compression + * {@link #getAlgorithmName() algorithm}. + */ + byte[] compress(byte[] payload) throws CompressionException; + + /** + * Decompresses the specified compressed byte array according to the compression + * {@link #getAlgorithmName() algorithm}. The specified byte array must already be in compressed form + * according to the {@link #getAlgorithmName() algorithm}. + * + * @param compressed compressed bytes + * @return decompressed bytes + * @throws CompressionException if the specified byte array cannot be decompressed according to the compression + * {@link #getAlgorithmName() algorithm}. + */ + byte[] decompress(byte[] compressed) throws CompressionException; +} \ No newline at end of file Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/CompressionCodecResolver.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/CompressionCodecResolver.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/CompressionCodecResolver.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2015 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +/** + * Looks for a JWT {@code calg} header, and if found, returns the corresponding {@link CompressionCodec} the parser + * can use to decompress the JWT body. + * + *JJWT's default {@link JwtParser} implementation supports both the + * {@link io.jsonwebtoken.impl.compression.DeflateCompressionCodec DEFLATE} + * and {@link io.jsonwebtoken.impl.compression.GzipCompressionCodec GZIP} algorithms by default - you do not need to + * specify a {@code CompressionCodecResolver} in these cases.
+ * + *However, if you want to use a compression algorithm other than {@code DEF} or {@code GZIP}, you must implement + * your own {@link CompressionCodecResolver} and specify that when + * {@link io.jsonwebtoken.JwtBuilder#compressWith(CompressionCodec) building} and + * {@link io.jsonwebtoken.JwtParser#setCompressionCodecResolver(CompressionCodecResolver) parsing} JWTs.
+ * + * @since 0.6.0 + */ +public interface CompressionCodecResolver { + + /** + * Looks for a JWT {@code calg} header, and if found, returns the corresponding {@link CompressionCodec} the parser + * can use to decompress the JWT body. + * + * @param header of the JWT + * @return CompressionCodec matching the {@code calg} header, or null if there is no {@code calg} header. + * @throws CompressionException if a {@code calg} header value is found and not supported. + */ + CompressionCodec resolveCompressionCodec(Header header) throws CompressionException; + +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/CompressionCodecs.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/CompressionCodecs.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/CompressionCodecs.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,34 @@ +package io.jsonwebtoken; + +import io.jsonwebtoken.impl.compression.DeflateCompressionCodec; +import io.jsonwebtoken.impl.compression.GzipCompressionCodec; + +/** + * Provides default implementations of the {@link CompressionCodec} interface. + * + * @see #DEFLATE + * @see #GZIP + * @since 0.7.0 + */ +public final class CompressionCodecs { + + private static final CompressionCodecs INSTANCE = new CompressionCodecs(); + + private CompressionCodecs() {} //prevent external instantiation + + /** + * Codec implementing the JWA standard + * deflate compression algorithm + */ + public static final CompressionCodec DEFLATE = new DeflateCompressionCodec(); + + /** + * Codec implementing the gzip compression algorithm. + *This is not a standard JWA compression algorithm. Be sure to use this only when you are confident + * that all parties accessing the token support the gzip algorithm.
+ *If you're concerned about compatibility, the {@link #DEFLATE DEFLATE} code is JWA standards-compliant.
+ */ + public static final CompressionCodec GZIP = new GzipCompressionCodec(); + +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/CompressionException.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/CompressionException.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/CompressionException.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2015 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +/** + * Exception indicating that either compressing or decompressing an JWT body failed. + * + * @since 0.6.0 + */ +public class CompressionException extends JwtException { + + public CompressionException(String message) { + super(message); + } + + public CompressionException(String message, Throwable cause) { + super(message, cause); + } + +} \ No newline at end of file Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/ExpiredJwtException.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/ExpiredJwtException.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/ExpiredJwtException.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +/** + * Exception indicating that a JWT was accepted after it expired and must be rejected. + * + * @since 0.3 + */ +public class ExpiredJwtException extends ClaimJwtException { + + public ExpiredJwtException(Header header, Claims claims, String message) { + super(header, claims, message); + } + + /** + * @param header jwt header + * @param claims jwt claims (body) + * @param message exception message + * @param cause cause + * @since 0.5 + */ + public ExpiredJwtException(Header header, Claims claims, String message, Throwable cause) { + super(header, claims, message, cause); + } +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Header.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Header.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Header.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +import java.util.Map; + +/** + * A JWT JOSE header. + * + *This is ultimately a JSON map and any values can be added to it, but JWT JOSE standard names are provided as + * type-safe getters and setters for convenience.
+ * + *Because this interface extends {@code Map<String, Object>}, if you would like to add your own properties, + * you simply use map methods, for example:
+ * + *+ * header.{@link Map#put(Object, Object) put}("headerParamName", "headerParamValue"); + *+ * + *
It is easiest to create a {@code Header} instance by calling one of the + * {@link Jwts#header() JWTs.header()} factory methods.
+ * + * @since 0.1 + */ +public interface Header"JWT"
*/
+ public static final String JWT_TYPE = "JWT";
+
+ /** JWT {@code Type} header parameter name: "typ"
*/
+ public static final String TYPE = "typ";
+
+ /** JWT {@code Content Type} header parameter name: "cty"
*/
+ public static final String CONTENT_TYPE = "cty";
+
+ /** JWT {@code Compression Algorithm} header parameter name: "zip"
*/
+ public static final String COMPRESSION_ALGORITHM = "zip";
+
+ /** JJWT legacy/deprecated compression algorithm header parameter name: "calg"
+ * @deprecated use {@link #COMPRESSION_ALGORITHM} instead. */
+ @Deprecated
+ public static final String DEPRECATED_COMPRESSION_ALGORITHM = "calg";
+
+ /**
+ * Returns the
+ * typ
(type) header value or {@code null} if not present.
+ *
+ * @return the {@code typ} header value or {@code null} if not present.
+ */
+ String getType();
+
+ /**
+ * Sets the JWT
+ * typ
(Type) header value. A {@code null} value will remove the property from the JSON map.
+ *
+ * @param typ the JWT JOSE {@code typ} header value or {@code null} to remove the property from the JSON map.
+ * @return the {@code Header} instance for method chaining.
+ */
+ T setType(String typ);
+
+ /**
+ * Returns the
+ * cty
(Content Type) header value or {@code null} if not present.
+ *
+ * In the normal case where nested signing or encryption operations are not employed (i.e. a compact + * serialization JWT), the use of this header parameter is NOT RECOMMENDED. In the case that nested + * signing or encryption is employed, this Header Parameter MUST be present; in this case, the value MUST be + * {@code JWT}, to indicate that a Nested JWT is carried in this JWT. While media type names are not + * case-sensitive, it is RECOMMENDED that {@code JWT} always be spelled using uppercase characters for + * compatibility with legacy implementations. See + * JWT Appendix A.2 for + * an example of a Nested JWT.
+ * + * @return the {@code typ} header parameter value or {@code null} if not present. + */ + String getContentType(); + + /** + * Sets the JWT + *cty
(Content Type) header parameter value. A {@code null} value will remove the property from
+ * the JSON map.
+ *
+ * In the normal case where nested signing or encryption operations are not employed (i.e. a compact + * serialization JWT), the use of this header parameter is NOT RECOMMENDED. In the case that nested + * signing or encryption is employed, this Header Parameter MUST be present; in this case, the value MUST be + * {@code JWT}, to indicate that a Nested JWT is carried in this JWT. While media type names are not + * case-sensitive, it is RECOMMENDED that {@code JWT} always be spelled using uppercase characters for + * compatibility with legacy implementations. See + * JWT Appendix A.2 for + * an example of a Nested JWT.
+ * + * @param cty the JWT JOSE {@code cty} header value or {@code null} to remove the property from the JSON map. + */ + T setContentType(String cty); + + /** + * Returns the JWTcalg
(Compression Algorithm) header value or {@code null} if not present.
+ *
+ * @return the {@code calg} header parameter value or {@code null} if not present.
+ * @since 0.6.0
+ */
+ String getCompressionAlgorithm();
+
+ /**
+ * Sets the JWT calg
(Compression Algorithm) header parameter value. A {@code null} value will remove
+ * the property from the JSON map.
+ * + *
The compression algorithm is NOT part of the JWT specification + * and must be used carefully since, is not expected that other libraries (including previous versions of this one) + * be able to deserialize a compressed JTW body correctly.
+ * + * @param calg the JWT compression algorithm {@code calg} value or {@code null} to remove the property from the JSON map. + * @since 0.6.0 + */ + T setCompressionAlgorithm(String calg); + +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/IncorrectClaimException.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/IncorrectClaimException.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/IncorrectClaimException.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +/** + * Exception thrown when discovering that a required claim does not equal the required value, indicating the JWT is + * invalid and may not be used. + * + * @since 0.6 + */ +public class IncorrectClaimException extends InvalidClaimException { + public IncorrectClaimException(Header header, Claims claims, String message) { + super(header, claims, message); + } + + public IncorrectClaimException(Header header, Claims claims, String message, Throwable cause) { + super(header, claims, message, cause); + } +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/InvalidClaimException.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/InvalidClaimException.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/InvalidClaimException.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2015 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +/** + * Exception indicating a parsed claim is invalid in some way. Subclasses reflect the specific + * reason the claim is invalid. + * + * @see IncorrectClaimException + * @see MissingClaimException + * + * @since 0.6 + */ +public class InvalidClaimException extends ClaimJwtException { + private String claimName; + private Object claimValue; + + protected InvalidClaimException(Header header, Claims claims, String message) { + super(header, claims, message); + } + + protected InvalidClaimException(Header header, Claims claims, String message, Throwable cause) { + super(header, claims, message, cause); + } + + public String getClaimName() { + return claimName; + } + + public void setClaimName(String claimName) { + this.claimName = claimName; + } + + public Object getClaimValue() { + return claimValue; + } + + public void setClaimValue(Object claimValue) { + this.claimValue = claimValue; + } +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Jws.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Jws.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Jws.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +/** + * An expanded (not compact/serialized) Signed JSON Web Token. + * + * @param the type of the JWS body contents, either a String or a {@link Claims} instance. + * + * @since 0.1 + */ +public interface Jws extends Jwt"alg"
*/
+ public static final String ALGORITHM = "alg";
+
+ /** JWS {@code JWT Set URL} header parameter name: "jku"
*/
+ public static final String JWK_SET_URL = "jku";
+
+ /** JWS {@code JSON Web Key} header parameter name: "jwk"
*/
+ public static final String JSON_WEB_KEY = "jwk";
+
+ /** JWS {@code Key ID} header parameter name: "kid"
*/
+ public static final String KEY_ID = "kid";
+
+ /** JWS {@code X.509 URL} header parameter name: "x5u"
*/
+ public static final String X509_URL = "x5u";
+
+ /** JWS {@code X.509 Certificate Chain} header parameter name: "x5c"
*/
+ public static final String X509_CERT_CHAIN = "x5c";
+
+ /** JWS {@code X.509 Certificate SHA-1 Thumbprint} header parameter name: "x5t"
*/
+ public static final String X509_CERT_SHA1_THUMBPRINT = "x5t";
+
+ /** JWS {@code X.509 Certificate SHA-256 Thumbprint} header parameter name: "x5t#S256"
*/
+ public static final String X509_CERT_SHA256_THUMBPRINT = "x5t#S256";
+
+ /** JWS {@code Critical} header parameter name: "crit"
*/
+ public static final String CRITICAL = "crit";
+
+ /**
+ * Returns the JWS
+ * alg
(algorithm) header value or {@code null} if not present.
+ *
+ * The algorithm header parameter identifies the cryptographic algorithm used to secure the JWS. Consider + * using {@link io.jsonwebtoken.SignatureAlgorithm#forName(String) SignatureAlgorithm.forName} to convert this + * string value to a type-safe enum instance.
+ * + * @return the JWS {@code alg} header value or {@code null} if not present. This will always be + * {@code non-null} on validly constructed JWS instances, but could be {@code null} during construction. + */ + String getAlgorithm(); + + /** + * Sets the JWT + *alg
(Algorithm) header value. A {@code null} value will remove the property from the JSON map.
+ *
+ * The algorithm header parameter identifies the cryptographic algorithm used to secure the JWS. Consider + * using a type-safe {@link io.jsonwebtoken.SignatureAlgorithm SignatureAlgorithm} instance and using its + * {@link io.jsonwebtoken.SignatureAlgorithm#getValue() value} as the argument to this method.
+ * + * @param alg the JWS {@code alg} header value or {@code null} to remove the property from the JSON map. + * @return the {@code Header} instance for method chaining. + */ + T setAlgorithm(String alg); + + /** + * Returns the JWS + *kid
(Key ID) header value or {@code null} if not present.
+ *
+ * The keyId header parameter is a hint indicating which key was used to secure the JWS. This parameter allows + * originators to explicitly signal a change of key to recipients. The structure of the keyId value is + * unspecified.
+ * + *When used with a JWK, the keyId value is used to match a JWK {@code keyId} parameter value.
+ * + * @return the JWS {@code kid} header value or {@code null} if not present. + */ + String getKeyId(); + + /** + * Sets the JWT + *kid
(Key ID) header value. A {@code null} value will remove the property from the JSON map.
+ *
+ * The keyId header parameter is a hint indicating which key was used to secure the JWS. This parameter allows + * originators to explicitly signal a change of key to recipients. The structure of the keyId value is + * unspecified.
+ * + *When used with a JWK, the keyId value is used to match a JWK {@code keyId} parameter value.
+ * + * @param kid the JWS {@code kid} header value or {@code null} to remove the property from the JSON map. + * @return the {@code Header} instance for method chaining. + */ + T setKeyId(String kid); +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Jwt.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Jwt.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/Jwt.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +/** + * An expanded (not compact/serialized) JSON Web Token. + * + * @param the type of the JWT body contents, either a String or a {@link Claims} instance. + * + * @since 0.1 + */ +public interface JwtThe payload and claims properties are mutually exclusive - only one of the two may be used.
+ * + * @param payload the plaintext (non-JSON) string that will be the body of the JWT. + * @return the builder for method chaining. + */ + JwtBuilder setPayload(String payload); + + /** + * Sets the JWT payload to be a JSON Claims instance. If you do not want the JWT body to be JSON and instead want + * it to be a plaintext string, use the {@link #setPayload(String)} method instead. + * + *The payload and claims properties are mutually exclusive - only one of the two may be used.
+ * + * @param claims the JWT claims to be set as the JWT body. + * @return the builder for method chaining. + */ + JwtBuilder setClaims(Claims claims); + + /** + * Sets the JWT payload to be a JSON Claims instance populated by the specified name/value pairs. If you do not + * want the JWT body to be JSON and instead want it to be a plaintext string, use the {@link #setPayload(String)} + * method instead. + * + *The payload* and claims* properties are mutually exclusive - only one of the two may be used.
+ * + * @param claims the JWT claims to be set as the JWT body. + * @return the builder for method chaining. + */ + JwtBuilder setClaims(MapThe payload and claims properties are mutually exclusive - only one of the two may be used.
+ * + * @param claims the JWT claims to be added to the JWT body. + * @return the builder for method chaining. + * @since 0.8 + */ + JwtBuilder addClaims(Mapiss
(issuer) value. A {@code null} value will remove the property from the Claims.
+ *
+ * This is a convenience method. It will first ensure a Claims instance exists as the JWT body and then set + * the Claims {@link Claims#setIssuer(String) issuer} field with the specified value. This allows you to write + * code like this:
+ * + *+ * String jwt = Jwts.builder().setIssuer("Joe").compact(); + *+ * + *
instead of this:
+ *+ * Claims claims = Jwts.claims().setIssuer("Joe"); + * String jwt = Jwts.builder().setClaims(claims).compact(); + *+ *
if desired.
+ * + * @param iss the JWT {@code iss} value or {@code null} to remove the property from the Claims map. + * @return the builder instance for method chaining. + * @since 0.2 + */ + @Override //only for better/targeted JavaDoc + JwtBuilder setIssuer(String iss); + + /** + * Sets the JWT Claims + *sub
(subject) value. A {@code null} value will remove the property from the Claims.
+ *
+ * This is a convenience method. It will first ensure a Claims instance exists as the JWT body and then set + * the Claims {@link Claims#setSubject(String) subject} field with the specified value. This allows you to write + * code like this:
+ * + *+ * String jwt = Jwts.builder().setSubject("Me").compact(); + *+ * + *
instead of this:
+ *+ * Claims claims = Jwts.claims().setSubject("Me"); + * String jwt = Jwts.builder().setClaims(claims).compact(); + *+ *
if desired.
+ * + * @param sub the JWT {@code sub} value or {@code null} to remove the property from the Claims map. + * @return the builder instance for method chaining. + * @since 0.2 + */ + @Override //only for better/targeted JavaDoc + JwtBuilder setSubject(String sub); + + /** + * Sets the JWT Claims + *aud
(audience) value. A {@code null} value will remove the property from the Claims.
+ *
+ * This is a convenience method. It will first ensure a Claims instance exists as the JWT body and then set + * the Claims {@link Claims#setAudience(String) audience} field with the specified value. This allows you to write + * code like this:
+ * + *+ * String jwt = Jwts.builder().setAudience("You").compact(); + *+ * + *
instead of this:
+ *+ * Claims claims = Jwts.claims().setSubject("You"); + * String jwt = Jwts.builder().setClaims(claims).compact(); + *+ *
if desired.
+ * + * @param aud the JWT {@code aud} value or {@code null} to remove the property from the Claims map. + * @return the builder instance for method chaining. + * @since 0.2 + */ + @Override //only for better/targeted JavaDoc + JwtBuilder setAudience(String aud); + + /** + * Sets the JWT Claims + *exp
(expiration) value. A {@code null} value will remove the property from the Claims.
+ *
+ * A JWT obtained after this timestamp should not be used.
+ * + *This is a convenience method. It will first ensure a Claims instance exists as the JWT body and then set + * the Claims {@link Claims#setExpiration(java.util.Date) expiration} field with the specified value. This allows + * you to write code like this:
+ * + *+ * String jwt = Jwts.builder().setExpiration(new Date(System.currentTimeMillis() + 3600000)).compact(); + *+ * + *
instead of this:
+ *+ * Claims claims = Jwts.claims().setExpiration(new Date(System.currentTimeMillis() + 3600000)); + * String jwt = Jwts.builder().setClaims(claims).compact(); + *+ *
if desired.
+ * + * @param exp the JWT {@code exp} value or {@code null} to remove the property from the Claims map. + * @return the builder instance for method chaining. + * @since 0.2 + */ + @Override //only for better/targeted JavaDoc + JwtBuilder setExpiration(Date exp); + + /** + * Sets the JWT Claims + *nbf
(not before) value. A {@code null} value will remove the property from the Claims.
+ *
+ * A JWT obtained before this timestamp should not be used.
+ * + *This is a convenience method. It will first ensure a Claims instance exists as the JWT body and then set + * the Claims {@link Claims#setNotBefore(java.util.Date) notBefore} field with the specified value. This allows + * you to write code like this:
+ * + *+ * String jwt = Jwts.builder().setNotBefore(new Date()).compact(); + *+ * + *
instead of this:
+ *+ * Claims claims = Jwts.claims().setNotBefore(new Date()); + * String jwt = Jwts.builder().setClaims(claims).compact(); + *+ *
if desired.
+ * + * @param nbf the JWT {@code nbf} value or {@code null} to remove the property from the Claims map. + * @return the builder instance for method chaining. + * @since 0.2 + */ + @Override //only for better/targeted JavaDoc + JwtBuilder setNotBefore(Date nbf); + + /** + * Sets the JWT Claims + *iat
(issued at) value. A {@code null} value will remove the property from the Claims.
+ *
+ * The value is the timestamp when the JWT was created.
+ * + *This is a convenience method. It will first ensure a Claims instance exists as the JWT body and then set + * the Claims {@link Claims#setIssuedAt(java.util.Date) issuedAt} field with the specified value. This allows + * you to write code like this:
+ * + *+ * String jwt = Jwts.builder().setIssuedAt(new Date()).compact(); + *+ * + *
instead of this:
+ *+ * Claims claims = Jwts.claims().setIssuedAt(new Date()); + * String jwt = Jwts.builder().setClaims(claims).compact(); + *+ *
if desired.
+ * + * @param iat the JWT {@code iat} value or {@code null} to remove the property from the Claims map. + * @return the builder instance for method chaining. + * @since 0.2 + */ + @Override //only for better/targeted JavaDoc + JwtBuilder setIssuedAt(Date iat); + + /** + * Sets the JWT Claims + *jti
(JWT ID) value. A {@code null} value will remove the property from the Claims.
+ *
+ * The value is a CaSe-SenSiTiVe unique identifier for the JWT. If specified, this value MUST be assigned in a + * manner that ensures that there is a negligible probability that the same value will be accidentally + * assigned to a different data object. The ID can be used to prevent the JWT from being replayed.
+ * + *This is a convenience method. It will first ensure a Claims instance exists as the JWT body and then set + * the Claims {@link Claims#setId(String) id} field with the specified value. This allows + * you to write code like this:
+ * + *+ * String jwt = Jwts.builder().setId(UUID.randomUUID().toString()).compact(); + *+ * + *
instead of this:
+ *+ * Claims claims = Jwts.claims().setIssuedAt(UUID.randomUUID().toString()); + * String jwt = Jwts.builder().setClaims(claims).compact(); + *+ *
if desired.
+ * + * @param jti the JWT {@code jti} (id) value or {@code null} to remove the property from the Claims map. + * @return the builder instance for method chaining. + * @since 0.2 + */ + @Override //only for better/targeted JavaDoc + JwtBuilder setId(String jti); + + /** + * Sets a custom JWT Claims parameter value. A {@code null} value will remove the property from the Claims. + * + *This is a convenience method. It will first ensure a Claims instance exists as the JWT body and then set the + * named property on the Claims instance using the Claims {@link Claims#put(Object, Object) put} method. This allows + * you to write code like this:
+ * + *+ * String jwt = Jwts.builder().claim("aName", "aValue").compact(); + *+ * + *
instead of this:
+ *+ * Claims claims = Jwts.claims().put("aName", "aValue"); + * String jwt = Jwts.builder().setClaims(claims).compact(); + *+ *
if desired.
+ * + * @param name the JWT Claims property name + * @param value the value to set for the specified Claims property name + * @return the builder instance for method chaining. + * @since 0.2 + */ + JwtBuilder claim(String name, Object value); + + /** + * Signs the constructed JWT using the specified algorithm with the specified key, producing a JWS. + * + * @param alg the JWS algorithm to use to digitally sign the JWT, thereby producing a JWS. + * @param secretKey the algorithm-specific signing key to use to digitally sign the JWT. + * @return the builder for method chaining. + */ + JwtBuilder signWith(SignatureAlgorithm alg, byte[] secretKey); + + /** + * Signs the constructed JWT using the specified algorithm with the specified key, producing a JWS. + * + *This is a convenience method: the string argument is first BASE64-decoded to a byte array and this resulting + * byte array is used to invoke {@link #signWith(SignatureAlgorithm, byte[])}.
+ * + * @param alg the JWS algorithm to use to digitally sign the JWT, thereby producing a JWS. + * @param base64EncodedSecretKey the BASE64-encoded algorithm-specific signing key to use to digitally sign the + * JWT. + * @return the builder for method chaining. + */ + JwtBuilder signWith(SignatureAlgorithm alg, String base64EncodedSecretKey); + + /** + * Signs the constructed JWT using the specified algorithm with the specified key, producing a JWS. + * + * @param alg the JWS algorithm to use to digitally sign the JWT, thereby producing a JWS. + * @param key the algorithm-specific signing key to use to digitally sign the JWT. + * @return the builder for method chaining. + */ + JwtBuilder signWith(SignatureAlgorithm alg, Key key); + + /** + * Compresses the JWT body using the specified {@link CompressionCodec}. + * + *If your compact JWTs are large, and you want to reduce their total size during network transmission, this + * can be useful. For example, when embedding JWTs in URLs, some browsers may not support URLs longer than a + * certain length. Using compression can help ensure the compact JWT fits within that length. However, NOTE:
+ * + *The JWT family of specifications defines compression only for JWE (Json Web Encryption) + * tokens. Even so, JJWT will also support compression for JWS tokens as well if you choose to use it. + * However, be aware that if you use compression when creating a JWS token, other libraries may not be able to + * parse that JWS token. When using compression for JWS tokens, be sure that that all parties accessing the + * JWS token support compression for JWS.
+ * + *Compression when creating JWE tokens however should be universally accepted for any + * library that supports JWE.
+ * + * @see io.jsonwebtoken.CompressionCodecs + * + * @param codec implementation of the {@link CompressionCodec} to be used. + * @return the builder for method chaining. + * @since 0.6.0 + */ + JwtBuilder compressWith(CompressionCodec codec); + + /** + * Actually builds the JWT and serializes it to a compact, URL-safe string according to the + * JWT Compact Serialization + * rules. + * + * @return A compact URL-safe JWT string. + */ + String compact(); +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/JwtException.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/JwtException.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/JwtException.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +/** + * Base class for JWT-related runtime exceptions. + * + * @since 0.1 + */ +public class JwtException extends RuntimeException { + + public JwtException(String message) { + super(message); + } + + public JwtException(String message, Throwable cause) { + super(message, cause); + } +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/JwtHandler.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/JwtHandler.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/JwtHandler.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +/** + * A JwtHandler is invoked by a {@link io.jsonwebtoken.JwtParser JwtParser} after parsing a JWT to indicate the exact + * type of JWT or JWS parsed. + * + * @paramThis method will only be invoked if the cryptographic signature can be successfully verified.
+ * + * @param jws the parsed plaintext JWS + * @return any object to be used after inspecting the JWS, or {@code null} if no return value is necessary. + */ + T onPlaintextJws(JwsThis method will only be invoked if the cryptographic signature can be successfully verified.
+ * + * @param jws the parsed claims JWS + * @return any object to be used after inspecting the JWS, or {@code null} if no return value is necessary. + */ + T onClaimsJws(JwsAll of the methods in this implementation throw exceptions: overridden methods represent + * scenarios expected by calling code in known situations. It would be unexpected to receive a JWS or JWT that did + * not match parsing expectations, so all non-overridden methods throw exceptions to indicate that the JWT + * input was unexpected.
+ * + * @param+ *
Note that this key MUST be a valid key for the signature algorithm found in the JWT header + * (as the {@code alg} header parameter).
+ *+ *
This method overwrites any previously set key.
+ * + * @param key the algorithm-specific signature verification key used to validate any discovered JWS digital + * signature. + * @return the parser for method chaining. + */ + JwtParser setSigningKey(byte[] key); + + /** + * Sets the signing key used to verify any discovered JWS digital signature. If the specified JWT string is not + * a JWS (no signature), this key is not used. + *+ *
Note that this key MUST be a valid key for the signature algorithm found in the JWT header + * (as the {@code alg} header parameter).
+ *+ *
This method overwrites any previously set key.
+ *+ *
This is a convenience method: the string argument is first BASE64-decoded to a byte array and this resulting + * byte array is used to invoke {@link #setSigningKey(byte[])}.
+ * + * @param base64EncodedKeyBytes the BASE64-encoded algorithm-specific signature verification key to use to validate + * any discovered JWS digital signature. + * @return the parser for method chaining. + */ + JwtParser setSigningKey(String base64EncodedKeyBytes); + + /** + * Sets the signing key used to verify any discovered JWS digital signature. If the specified JWT string is not + * a JWS (no signature), this key is not used. + *+ *
Note that this key MUST be a valid key for the signature algorithm found in the JWT header + * (as the {@code alg} header parameter).
+ *+ *
This method overwrites any previously set key.
+ * + * @param key the algorithm-specific signature verification key to use to validate any discovered JWS digital + * signature. + * @return the parser for method chaining. + */ + JwtParser setSigningKey(Key key); + + /** + * Sets the {@link SigningKeyResolver} used to acquire thesigning key
that should be used to verify
+ * a JWS's signature. If the parsed String is not a JWS (no signature), this resolver is not used.
+ * + *
Specifying a {@code SigningKeyResolver} is necessary when the signing key is not already known before parsing + * the JWT and the JWT header or payload (plaintext body or Claims) must be inspected first to determine how to + * look up the signing key. Once returned by the resolver, the JwtParser will then verify the JWS signature with the + * returned key. For example:
+ *+ *
+ * Jws<Claims> jws = Jwts.parser().setSigningKeyResolver(new SigningKeyResolverAdapter() { + * @Override + * public byte[] resolveSigningKeyBytes(JwsHeader header, Claims claims) { + * //inspect the header or claims, lookup and return the signing key + * return getSigningKey(header, claims); //implement me + * }}) + * .parseClaimsJws(compact); + *+ *
+ *
A {@code SigningKeyResolver} is invoked once during parsing before the signature is verified.
+ *+ *
This method should only be used if a signing key is not provided by the other {@code setSigningKey*} builder + * methods.
+ * + * @param signingKeyResolver the signing key resolver used to retrieve the signing key. + * @return the parser for method chaining. + * @since 0.4 + */ + JwtParser setSigningKeyResolver(SigningKeyResolver signingKeyResolver); + + /** + * Sets the {@link CompressionCodecResolver} used to acquire the {@link CompressionCodec} that should be used to + * decompress the JWT body. If the parsed JWT is not compressed, this resolver is not used. + *NOTE: Compression is not defined by the JWT Specification, and it is not expected that other libraries + * (including JJWT versions < 0.6.0) are able to consume a compressed JWT body correctly. This method is only + * useful if the compact JWT was compressed with JJWT >= 0.6.0 or another library that you know implements + * the same behavior.
+ *JJWT's default {@link JwtParser} implementation supports both the + * {@link io.jsonwebtoken.impl.compression.DeflateCompressionCodec DEFLATE} + * and {@link io.jsonwebtoken.impl.compression.GzipCompressionCodec GZIP} algorithms by default - you do not need to + * specify a {@code CompressionCodecResolver} in these cases.
+ *However, if you want to use a compression algorithm other than {@code DEF} or {@code GZIP}, you must implement + * your own {@link CompressionCodecResolver} and specify that via this method and also when + * {@link io.jsonwebtoken.JwtBuilder#compressWith(CompressionCodec) building} JWTs.
+ * + * @param compressionCodecResolver the compression codec resolver used to decompress the JWT body. + * @return the parser for method chaining. + * @since 0.6.0 + */ + JwtParser setCompressionCodecResolver(CompressionCodecResolver compressionCodecResolver); + + /** + * Returns {@code true} if the specified JWT compact string represents a signed JWT (aka a 'JWS'), {@code false} + * otherwise. + *+ *
Note that if you are reasonably sure that the token is signed, it is more efficient to attempt to + * parse the token (and catching exceptions if necessary) instead of calling this method first before parsing.
+ * + * @param jwt the compact serialized JWT to check + * @return {@code true} if the specified JWT compact string represents a signed JWT (aka a 'JWS'), {@code false} + * otherwise. + */ + boolean isSigned(String jwt); + + /** + * Parses the specified compact serialized JWT string based on the builder's current configuration state and + * returns the resulting JWT or JWS instance. + *+ *
This method returns a JWT or JWS based on the parsed string. Because it may be cumbersome to determine if it + * is a JWT or JWS, or if the body/payload is a Claims or String with {@code instanceof} checks, the + * {@link #parse(String, JwtHandler) parse(String,JwtHandler)} method allows for a type-safe callback approach that + * may help reduce code or instanceof checks.
+ * + * @param jwt the compact serialized JWT to parse + * @return the specified compact serialized JWT string based on the builder's current configuration state. + * @throws MalformedJwtException if the specified JWT was incorrectly constructed (and therefore invalid). + * Invalid + * JWTs should not be trusted and should be discarded. + * @throws SignatureException if a JWS signature was discovered, but could not be verified. JWTs that fail + * signature validation should not be trusted and should be discarded. + * @throws ExpiredJwtException if the specified JWT is a Claims JWT and the Claims has an expiration time + * before the time this method is invoked. + * @throws IllegalArgumentException if the specified string is {@code null} or empty or only whitespace. + * @see #parse(String, JwtHandler) + * @see #parsePlaintextJwt(String) + * @see #parseClaimsJwt(String) + * @see #parsePlaintextJws(String) + * @see #parseClaimsJws(String) + */ + Jwt parse(String jwt) throws ExpiredJwtException, MalformedJwtException, SignatureException, IllegalArgumentException; + + /** + * Parses the specified compact serialized JWT string based on the builder's current configuration state and + * invokes the specified {@code handler} with the resulting JWT or JWS instance. + *+ *
If you are confident of the format of the JWT before parsing, you can create an anonymous subclass using the + * {@link io.jsonwebtoken.JwtHandlerAdapter JwtHandlerAdapter} and override only the methods you know are relevant + * for your use case(s), for example:
+ *+ *
+ * String compactJwt = request.getParameter("jwt"); //we are confident this is a signed JWS + * + * String subject = Jwts.parser().setSigningKey(key).parse(compactJwt, new JwtHandlerAdapter<String>() { + * @Override + * public String onClaimsJws(Jws<Claims> jws) { + * return jws.getBody().getSubject(); + * } + * }); + *+ *
+ *
If you know the JWT string can be only one type of JWT, then it is even easier to invoke one of the + * following convenience methods instead of this one:
+ *+ *
+ *
This is a convenience method that is usable if you are confident that the compact string argument reflects an + * unsigned plaintext JWT. An unsigned plaintext JWT has a String (non-JSON) body payload and it is not + * cryptographically signed.
+ *+ *
If the compact string presented does not reflect an unsigned plaintext JWT with non-JSON string body, + * an {@link UnsupportedJwtException} will be thrown.
+ * + * @param plaintextJwt a compact serialized unsigned plaintext JWT string. + * @return the {@link Jwt Jwt} instance that reflects the specified compact JWT string. + * @throws UnsupportedJwtException if the {@code plaintextJwt} argument does not represent an unsigned plaintext + * JWT + * @throws MalformedJwtException if the {@code plaintextJwt} string is not a valid JWT + * @throws SignatureException if the {@code plaintextJwt} string is actually a JWS and signature validation + * fails + * @throws IllegalArgumentException if the {@code plaintextJwt} string is {@code null} or empty or only whitespace + * @see #parseClaimsJwt(String) + * @see #parsePlaintextJws(String) + * @see #parseClaimsJws(String) + * @see #parse(String, JwtHandler) + * @see #parse(String) + * @since 0.2 + */ + Jwt+ *
This is a convenience method that is usable if you are confident that the compact string argument reflects an + * unsigned Claims JWT. An unsigned Claims JWT has a {@link Claims} body and it is not cryptographically + * signed.
+ *+ *
If the compact string presented does not reflect an unsigned Claims JWT, an + * {@link UnsupportedJwtException} will be thrown.
+ * + * @param claimsJwt a compact serialized unsigned Claims JWT string. + * @return the {@link Jwt Jwt} instance that reflects the specified compact JWT string. + * @throws UnsupportedJwtException if the {@code claimsJwt} argument does not represent an unsigned Claims JWT + * @throws MalformedJwtException if the {@code claimsJwt} string is not a valid JWT + * @throws SignatureException if the {@code claimsJwt} string is actually a JWS and signature validation + * fails + * @throws ExpiredJwtException if the specified JWT is a Claims JWT and the Claims has an expiration time + * before the time this method is invoked. + * @throws IllegalArgumentException if the {@code claimsJwt} string is {@code null} or empty or only whitespace + * @see #parsePlaintextJwt(String) + * @see #parsePlaintextJws(String) + * @see #parseClaimsJws(String) + * @see #parse(String, JwtHandler) + * @see #parse(String) + * @since 0.2 + */ + Jwt+ *
This is a convenience method that is usable if you are confident that the compact string argument reflects a + * plaintext JWS. A plaintext JWS is a JWT with a String (non-JSON) body (payload) that has been + * cryptographically signed.
+ *+ *
If the compact string presented does not reflect a plaintext JWS, an {@link UnsupportedJwtException} + * will be thrown.
+ * + * @param plaintextJws a compact serialized JWS string. + * @return the {@link Jws Jws} instance that reflects the specified compact JWS string. + * @throws UnsupportedJwtException if the {@code plaintextJws} argument does not represent an plaintext JWS + * @throws MalformedJwtException if the {@code plaintextJws} string is not a valid JWS + * @throws SignatureException if the {@code plaintextJws} JWS signature validation fails + * @throws IllegalArgumentException if the {@code plaintextJws} string is {@code null} or empty or only whitespace + * @see #parsePlaintextJwt(String) + * @see #parseClaimsJwt(String) + * @see #parseClaimsJws(String) + * @see #parse(String, JwtHandler) + * @see #parse(String) + * @since 0.2 + */ + Jws+ *
This is a convenience method that is usable if you are confident that the compact string argument reflects a + * Claims JWS. A Claims JWS is a JWT with a {@link Claims} body that has been cryptographically signed.
+ *+ *
If the compact string presented does not reflect a Claims JWS, an {@link UnsupportedJwtException} will be + * thrown.
+ * + * @param claimsJws a compact serialized Claims JWS string. + * @return the {@link Jws Jws} instance that reflects the specified compact Claims JWS string. + * @throws UnsupportedJwtException if the {@code claimsJws} argument does not represent an Claims JWS + * @throws MalformedJwtException if the {@code claimsJws} string is not a valid JWS + * @throws SignatureException if the {@code claimsJws} JWS signature validation fails + * @throws ExpiredJwtException if the specified JWT is a Claims JWT and the Claims has an expiration time + * before the time this method is invoked. + * @throws IllegalArgumentException if the {@code claimsJws} string is {@code null} or empty or only whitespace + * @see #parsePlaintextJwt(String) + * @see #parseClaimsJwt(String) + * @see #parsePlaintextJws(String) + * @see #parse(String, JwtHandler) + * @see #parse(String) + * @since 0.2 + */ + JwsSignatureAlgorithm | + *Family Name | + *
---|---|
HS256 | + *HMAC | + *
HS384 | + *HMAC | + *
HS512 | + *HMAC | + *
RS256 | + *RSA | + *
RS384 | + *RSA | + *
RS512 | + *RSA | + *
PS256 | + *RSA | + *
PS384 | + *RSA | + *
PS512 | + *RSA | + *
ES256 | + *Elliptic Curve | + *
ES384 | + *Elliptic Curve | + *
ES512 | + *Elliptic Curve | + *
A {@code SigningKeyResolver} is necessary when the signing key is not already known before parsing the JWT and the + * JWT header or payload (plaintext body or Claims) must be inspected first to determine how to look up the signing key. + * Once returned by the resolver, the JwtParser will then verify the JWS signature with the returned key. For + * example:
+ * + *+ * Jws<Claims> jws = Jwts.parser().setSigningKeyResolver(new SigningKeyResolverAdapter() { + * @Override + * public byte[] resolveSigningKeyBytes(JwsHeader header, Claims claims) { + * //inspect the header or claims, lookup and return the signing key + * return getSigningKeyBytes(header, claims); //implement me + * }}) + * .parseClaimsJws(compact); + *+ * + *
A {@code SigningKeyResolver} is invoked once during parsing before the signature is verified.
+ * + *If you only need to resolve a signing key for a particular JWS (either a plaintext or Claims JWS), consider using + * the {@link io.jsonwebtoken.SigningKeyResolverAdapter} and overriding only the method you need to support instead of + * implementing this interface directly.
+ * + * @see io.jsonwebtoken.SigningKeyResolverAdapter + * @since 0.4 + */ +public interface SigningKeyResolver { + + /** + * Returns the signing key that should be used to validate a digital signature for the Claims JWS with the specified + * header and claims. + * + * @param header the header of the JWS to validate + * @param claims the claims (body) of the JWS to validate + * @return the signing key that should be used to validate a digital signature for the Claims JWS with the specified + * header and claims. + */ + Key resolveSigningKey(JwsHeader header, Claims claims); + + /** + * Returns the signing key that should be used to validate a digital signature for the Plaintext JWS with the + * specified header and plaintext payload. + * + * @param header the header of the JWS to validate + * @param plaintext the plaintext body of the JWS to validate + * @return the signing key that should be used to validate a digital signature for the Plaintext JWS with the + * specified header and plaintext payload. + */ + Key resolveSigningKey(JwsHeader header, String plaintext); +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/SigningKeyResolverAdapter.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/SigningKeyResolverAdapter.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/SigningKeyResolverAdapter.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +import io.jsonwebtoken.lang.Assert; + +import javax.crypto.spec.SecretKeySpec; +import java.security.Key; + +/** + * An Adapter implementation of the + * {@link SigningKeyResolver} interface that allows subclasses to process only the type of JWS body that + * is known/expected for a particular case. + * + *The {@link #resolveSigningKey(JwsHeader, Claims)} and {@link #resolveSigningKey(JwsHeader, String)} method + * implementations delegate to the + * {@link #resolveSigningKeyBytes(JwsHeader, Claims)} and {@link #resolveSigningKeyBytes(JwsHeader, String)} methods + * respectively. The latter two methods simply throw exceptions: they represent scenarios expected by + * calling code in known situations, and it is expected that you override the implementation in those known situations; + * non-overridden *KeyBytes methods indicates that the JWS input was unexpected.
+ * + *If either {@link #resolveSigningKey(JwsHeader, String)} or {@link #resolveSigningKey(JwsHeader, Claims)} + * are not overridden, one (or both) of the *KeyBytes variants must be overridden depending on your expected + * use case. You do not have to override any method that does not represent an expected condition.
+ * + * @since 0.4 + */ +public class SigningKeyResolverAdapter implements SigningKeyResolver { + + @Override + public Key resolveSigningKey(JwsHeader header, Claims claims) { + SignatureAlgorithm alg = SignatureAlgorithm.forName(header.getAlgorithm()); + Assert.isTrue(alg.isHmac(), "The default resolveSigningKey(JwsHeader, Claims) implementation cannot be " + + "used for asymmetric key algorithms (RSA, Elliptic Curve). " + + "Override the resolveSigningKey(JwsHeader, Claims) method instead and return a " + + "Key instance appropriate for the " + alg.name() + " algorithm."); + byte[] keyBytes = resolveSigningKeyBytes(header, claims); + return new SecretKeySpec(keyBytes, alg.getJcaName()); + } + + @Override + public Key resolveSigningKey(JwsHeader header, String plaintext) { + SignatureAlgorithm alg = SignatureAlgorithm.forName(header.getAlgorithm()); + Assert.isTrue(alg.isHmac(), "The default resolveSigningKey(JwsHeader, String) implementation cannot be " + + "used for asymmetric key algorithms (RSA, Elliptic Curve). " + + "Override the resolveSigningKey(JwsHeader, String) method instead and return a " + + "Key instance appropriate for the " + alg.name() + " algorithm."); + byte[] keyBytes = resolveSigningKeyBytes(header, plaintext); + return new SecretKeySpec(keyBytes, alg.getJcaName()); + } + + /** + * Convenience method invoked by {@link #resolveSigningKey(JwsHeader, Claims)} that obtains the necessary signing + * key bytes. This implementation simply throws an exception: if the JWS parsed is a Claims JWS, you must + * override this method or the {@link #resolveSigningKey(JwsHeader, Claims)} method instead. + * + *NOTE: You cannot override this method when validating RSA signatures. If you expect RSA signatures, + * you must override the {@link #resolveSigningKey(JwsHeader, Claims)} method instead.
+ * + * @param header the parsed {@link JwsHeader} + * @param claims the parsed {@link Claims} + * @return the signing key bytes to use to verify the JWS signature. + */ + public byte[] resolveSigningKeyBytes(JwsHeader header, Claims claims) { + throw new UnsupportedJwtException("The specified SigningKeyResolver implementation does not support " + + "Claims JWS signing key resolution. Consider overriding either the " + + "resolveSigningKey(JwsHeader, Claims) method or, for HMAC algorithms, the " + + "resolveSigningKeyBytes(JwsHeader, Claims) method."); + } + + /** + * Convenience method invoked by {@link #resolveSigningKey(JwsHeader, String)} that obtains the necessary signing + * key bytes. This implementation simply throws an exception: if the JWS parsed is a plaintext JWS, you must + * override this method or the {@link #resolveSigningKey(JwsHeader, String)} method instead. + * + * @param header the parsed {@link JwsHeader} + * @param payload the parsed String plaintext payload + * @return the signing key bytes to use to verify the JWS signature. + */ + public byte[] resolveSigningKeyBytes(JwsHeader header, String payload) { + throw new UnsupportedJwtException("The specified SigningKeyResolver implementation does not support " + + "plaintext JWS signing key resolution. Consider overriding either the " + + "resolveSigningKey(JwsHeader, String) method or, for HMAC algorithms, the " + + "resolveSigningKeyBytes(JwsHeader, String) method."); + } +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/UnsupportedJwtException.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/UnsupportedJwtException.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/UnsupportedJwtException.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken; + +/** + * Exception thrown when receiving a JWT in a particular format/configuration that does not match the format expected + * by the application. + * + *For example, this exception would be thrown if parsing an unsigned plaintext JWT when the application + * requires a cryptographically signed Claims JWS instead.
+ * + * @since 0.2 + */ +public class UnsupportedJwtException extends JwtException { + + public UnsupportedJwtException(String message) { + super(message); + } + + public UnsupportedJwtException(String message, Throwable cause) { + super(message, cause); + } +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/AbstractTextCodec.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/AbstractTextCodec.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/AbstractTextCodec.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken.impl; + +import io.jsonwebtoken.lang.Assert; + +import java.nio.charset.Charset; + +public abstract class AbstractTextCodec implements TextCodec { + + protected static final Charset UTF8 = Charset.forName("UTF-8"); + protected static final Charset US_ASCII = Charset.forName("US-ASCII"); + + @Override + public String encode(String data) { + Assert.hasText(data, "String argument to encode cannot be null or empty."); + byte[] bytes = data.getBytes(UTF8); + return encode(bytes); + } + + @Override + public String decodeToString(String encoded) { + byte[] bytes = decode(encoded); + return new String(bytes, UTF8); + } +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/AndroidBase64Codec.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/AndroidBase64Codec.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/AndroidBase64Codec.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2015 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken.impl; + +public class AndroidBase64Codec extends AbstractTextCodec { + + @Override + public String encode(byte[] data) { + int flags = android.util.Base64.NO_PADDING | android.util.Base64.NO_WRAP; + return android.util.Base64.encodeToString(data, flags); + } + + @Override + public byte[] decode(String encoded) { + return android.util.Base64.decode(encoded, android.util.Base64.DEFAULT); + } +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/Base64Codec.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/Base64Codec.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/Base64Codec.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken.impl; + +public class Base64Codec extends AbstractTextCodec { + + public String encode(byte[] data) { + return javax.xml.bind.DatatypeConverter.printBase64Binary(data); + } + + @Override + public byte[] decode(String encoded) { + return javax.xml.bind.DatatypeConverter.parseBase64Binary(encoded); + } +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/Base64UrlCodec.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/Base64UrlCodec.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/Base64UrlCodec.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken.impl; + +public class Base64UrlCodec extends AbstractTextCodec { + + @Override + public String encode(byte[] data) { + String base64Text = TextCodec.BASE64.encode(data); + byte[] bytes = base64Text.getBytes(US_ASCII); + + //base64url encoding doesn't use padding chars: + bytes = removePadding(bytes); + + //replace URL-unfriendly Base64 chars to url-friendly ones: + for (int i = 0; i < bytes.length; i++) { + if (bytes[i] == '+') { + bytes[i] = '-'; + } else if (bytes[i] == '/') { + bytes[i] = '_'; + } + } + + return new String(bytes, US_ASCII); + } + + protected byte[] removePadding(byte[] bytes) { + + byte[] result = bytes; + + int paddingCount = 0; + for (int i = bytes.length - 1; i > 0; i--) { + if (bytes[i] == '=') { + paddingCount++; + } else { + break; + } + } + if (paddingCount > 0) { + result = new byte[bytes.length - paddingCount]; + System.arraycopy(bytes, 0, result, 0, bytes.length - paddingCount); + } + + return result; + } + + @Override + public byte[] decode(String encoded) { + char[] chars = encoded.toCharArray(); //always ASCII - one char == 1 byte + + //Base64 requires padding to be in place before decoding, so add it if necessary: + chars = ensurePadding(chars); + + //Replace url-friendly chars back to normal Base64 chars: + for (int i = 0; i < chars.length; i++) { + if (chars[i] == '-') { + chars[i] = '+'; + } else if (chars[i] == '_') { + chars[i] = '/'; + } + } + + String base64Text = new String(chars); + + return TextCodec.BASE64.decode(base64Text); + } + + protected char[] ensurePadding(char[] chars) { + + char[] result = chars; //assume argument in case no padding is necessary + + int paddingCount = 0; + + //fix for https://github.com/jwtk/jjwt/issues/31 + int remainder = chars.length % 4; + if (remainder == 2 || remainder == 3) { + paddingCount = 4 - remainder; + } + + if (paddingCount > 0) { + result = new char[chars.length + paddingCount]; + System.arraycopy(chars, 0, result, 0, chars.length); + for (int i = 0; i < paddingCount; i++) { + result[chars.length + i] = '='; + } + } + + return result; + } + +} Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/DefaultClaims.java =================================================================== diff -u --- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/DefaultClaims.java (revision 0) +++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/DefaultClaims.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835) @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2014 jsonwebtoken.io + * + * Licensed 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 io.jsonwebtoken.impl; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.RequiredTypeException; + +import java.util.Date; +import java.util.Map; + +public class DefaultClaims extends JwtMap implements Claims { + + public DefaultClaims() { + super(); + } + + public DefaultClaims(Mapnew {@link Date}()
.
+ *
+ * @return a new {@link Date} instance.
+ */
+ @Override
+ public Date now() {
+ return new Date();
+ }
+}
Index: 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/DefaultHeader.java
===================================================================
diff -u
--- 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/DefaultHeader.java (revision 0)
+++ 3rdParty_sources/jsonwebtoken/io/jsonwebtoken/impl/DefaultHeader.java (revision dd64f16fdf89f789b8c2179d421290dcabf15835)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2014 jsonwebtoken.io
+ *
+ * Licensed 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 io.jsonwebtoken.impl;
+
+import io.jsonwebtoken.Header;
+import io.jsonwebtoken.lang.Strings;
+
+import java.util.Map;
+
+@SuppressWarnings("unchecked")
+public class DefaultHeader