/** * Assert that an object is not <code>null</code> . * <pre class="code">Assert.notNull(clazz);</pre> * @param object the object to check * @throws IllegalArgumentException if the object is <code>null</code> */ public static void notNull(Object object) { notNull(object, "[Assertion failed] - this argument is required; it must not be null"); }
@Override public JwtParser base64UrlDecodeWith(Decoder<String, byte[]> base64UrlDecoder) { Assert.notNull(base64UrlDecoder, "base64UrlDecoder cannot be null."); this.base64UrlDecoder = base64UrlDecoder; return this; }
@SuppressWarnings("WeakerAccess") //intended for end-users to use when providing a custom ObjectMapper public JacksonSerializer(ObjectMapper objectMapper) { Assert.notNull(objectMapper, "ObjectMapper cannot be null."); this.objectMapper = objectMapper; }
@Override public JwtParser setSigningKeyResolver(SigningKeyResolver signingKeyResolver) { Assert.notNull(signingKeyResolver, "SigningKeyResolver cannot be null."); this.signingKeyResolver = signingKeyResolver; return this; }
@Override public JwtParser setCompressionCodecResolver(CompressionCodecResolver compressionCodecResolver) { Assert.notNull(compressionCodecResolver, "compressionCodecResolver cannot be null."); this.compressionCodecResolver = compressionCodecResolver; return this; }
@Override public JwtParser setClock(Clock clock) { Assert.notNull(clock, "Clock instance cannot be null."); this.clock = clock; return this; }
@Override public JwtParser setSigningKey(Key key) { Assert.notNull(key, "signing key cannot be null."); this.key = key; return this; }
@Override public JwtBuilder serializeToJsonWith(Serializer<Map<String,?>> serializer) { Assert.notNull(serializer, "Serializer cannot be null."); this.serializer = serializer; return this; }
@Override public JwtBuilder compressWith(CompressionCodec compressionCodec) { Assert.notNull(compressionCodec, "compressionCodec cannot be null"); this.compressionCodec = compressionCodec; return this; }
public DefaultJwtSigner(SignerFactory factory, SignatureAlgorithm alg, Key key, Encoder<byte[], String> base64UrlEncoder) { Assert.notNull(factory, "SignerFactory argument cannot be null."); Assert.notNull(base64UrlEncoder, "Base64Url Encoder cannot be null."); this.base64UrlEncoder = base64UrlEncoder; this.signer = factory.createSigner(alg, key); }
@Override public JwtBuilder signWith(Key key, SignatureAlgorithm alg) throws InvalidKeyException { Assert.notNull(key, "Key argument cannot be null."); Assert.notNull(alg, "SignatureAlgorithm cannot be null."); alg.assertValidSigningKey(key); //since 0.10.0 for https://github.com/jwtk/jjwt/issues/334 this.algorithm = alg; this.key = key; return this; }
public DefaultJwtSignatureValidator(SignatureValidatorFactory factory, SignatureAlgorithm alg, Key key, Decoder<String, byte[]> base64UrlDecoder) { Assert.notNull(factory, "SignerFactory argument cannot be null."); Assert.notNull(base64UrlDecoder, "Base64Url decoder argument cannot be null."); this.signatureValidator = factory.createSignatureValidator(alg, key); this.base64UrlDecoder = base64UrlDecoder; }
public static Date parseIso8601Date(String s) throws ParseException { Assert.notNull(s, "String argument cannot be null."); if (s.lastIndexOf('.') > -1) { //assume ISO-8601 with milliseconds return ISO_8601_MILLIS.get().parse(s); } else { //assume ISO-8601 without millis: return ISO_8601.get().parse(s); } } }
@Override public byte[] decode(String s) throws DecodingException { Assert.notNull(s, "String argument cannot be null"); return this.base64.decodeFast(s.toCharArray()); } }
private String getAlgorithmFromHeader(Header header) { Assert.notNull(header, "header cannot be null."); return header.getCompressionAlgorithm(); } }
@Override public byte[] serialize(T t) throws SerializationException { Assert.notNull(t, "Object to serialize cannot be null."); try { return writeValueAsBytes(t); } catch (JsonProcessingException e) { String msg = "Unable to serialize object: " + e.getMessage(); throw new SerializationException(msg, e); } }
@Override public JwtParser require(String claimName, Object value) { Assert.hasText(claimName, "claim name cannot be null or empty."); Assert.notNull(value, "The value cannot be null for claim name: " + claimName); expectedClaims.put(claimName, value); return this; }
@Override public JwtBuilder signWith(Key key) throws InvalidKeyException { Assert.notNull(key, "Key argument cannot be null."); SignatureAlgorithm alg = SignatureAlgorithm.forSigningKey(key); return signWith(key, alg); }
@Override public JwtBuilder signWith(SignatureAlgorithm alg, byte[] secretKeyBytes) throws InvalidKeyException { Assert.notNull(alg, "SignatureAlgorithm cannot be null."); Assert.notEmpty(secretKeyBytes, "secret key byte array cannot be null or empty."); Assert.isTrue(alg.isHmac(), "Key bytes may only be specified for HMAC signatures. If using RSA or Elliptic Curve, use the signWith(SignatureAlgorithm, Key) method instead."); SecretKey key = new SecretKeySpec(secretKeyBytes, alg.getJcaName()); return signWith(key, alg); }