/** * Assert that the given String has valid text content; that is, it must not * be <code>null</code> and must contain at least one non-whitespace character. * <pre class="code">Assert.hasText(name, "'name' must not be empty");</pre> * @param text the String to check * @see Strings#hasText */ public static void hasText(String text) { hasText(text, "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank"); }
@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 JwtParser setSigningKey(String base64EncodedSecretKey) { Assert.hasText(base64EncodedSecretKey, "signing key cannot be null or empty."); this.keyBytes = Decoders.BASE64.decode(base64EncodedSecretKey); return this; }
@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(SignatureAlgorithm alg, String base64EncodedSecretKey) throws InvalidKeyException { Assert.hasText(base64EncodedSecretKey, "base64-encoded secret key cannot be null or empty."); Assert.isTrue(alg.isHmac(), "Base64-encoded key bytes may only be specified for HMAC signatures. If using RSA or Elliptic Curve, use the signWith(SignatureAlgorithm, Key) method instead."); byte[] bytes = Decoders.BASE64.decode(base64EncodedSecretKey); return signWith(alg, bytes); }
@Override public JwtBuilder claim(String name, Object value) { Assert.hasText(name, "Claim property name cannot be null or empty."); if (this.claims == null) { if (value != null) { ensureClaims().put(name, value); } } else { if (value == null) { this.claims.remove(name); } else { this.claims.put(name, value); } } return this; }
@Override public <T> T parse(String compact, JwtHandler<T> handler) throws ExpiredJwtException, MalformedJwtException, SignatureException { Assert.notNull(handler, "JwtHandler argument cannot be null."); Assert.hasText(compact, "JWT String argument cannot be null or empty."); Jwt jwt = parse(compact); if (jwt instanceof Jws) { Jws jws = (Jws) jwt; Object body = jws.getBody(); if (body instanceof Claims) { return handler.onClaimsJws((Jws<Claims>) jws); } else { return handler.onPlaintextJws((Jws<String>) jws); } } else { Object body = jwt.getBody(); if (body instanceof Claims) { return handler.onClaimsJwt((Jwt<Header, Claims>) jwt); } else { return handler.onPlaintextJwt((Jwt<Header, String>) jwt); } } }
Assert.hasText(jwt, "JWT String argument cannot be null or empty.");
/** * Assert that the given String has valid text content; that is, it must not * be <code>null</code> and must contain at least one non-whitespace character. * <pre class="code">Assert.hasText(name, "'name' must not be empty");</pre> * @param text the String to check * @see Strings#hasText */ public static void hasText(String text) { hasText(text, "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank"); }
/** * Assert that the given String has valid text content; that is, it must not * be <code>null</code> and must contain at least one non-whitespace character. * <pre class="code">Assert.hasText(name, "'name' must not be empty");</pre> * @param text the String to check * @see Strings#hasText */ public static void hasText(String text) { hasText(text, "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank"); }
@Override public JwtParser setSigningKey(String base64EncodedKeyBytes) { Assert.hasText(base64EncodedKeyBytes, "signing key cannot be null or empty."); this.keyBytes = TextCodec.BASE64.decode(base64EncodedKeyBytes); return this; }
@Override public JwtParser setSigningKey(String base64EncodedSecretKey) { Assert.hasText(base64EncodedSecretKey, "signing key cannot be null or empty."); this.keyBytes = Decoders.BASE64.decode(base64EncodedSecretKey); return this; }
@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 encode(String data) { Assert.hasText(data, "String argument to encode cannot be null or empty."); byte[] bytes = data.getBytes(UTF8); return encode(bytes); }
public void setSecrets(Map<String, String> secrets) { Assert.notNull(secrets); Assert.hasText(secrets.get(SignatureAlgorithm.HS256.getValue())); Assert.hasText(secrets.get(SignatureAlgorithm.HS384.getValue())); Assert.hasText(secrets.get(SignatureAlgorithm.HS512.getValue())); this.secrets = secrets; }
@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 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(SignatureAlgorithm alg, String base64EncodedSecretKey) { Assert.hasText(base64EncodedSecretKey, "base64-encoded secret key cannot be null or empty."); Assert.isTrue(alg.isHmac(), "Base64-encoded key bytes may only be specified for HMAC signatures. If using RSA or Elliptic Curve, use the signWith(SignatureAlgorithm, Key) method instead."); byte[] bytes = TextCodec.BASE64.decode(base64EncodedSecretKey); return signWith(alg, bytes); }
@Override public JwtBuilder signWith(SignatureAlgorithm alg, String base64EncodedSecretKey) throws InvalidKeyException { Assert.hasText(base64EncodedSecretKey, "base64-encoded secret key cannot be null or empty."); Assert.isTrue(alg.isHmac(), "Base64-encoded key bytes may only be specified for HMAC signatures. If using RSA or Elliptic Curve, use the signWith(SignatureAlgorithm, Key) method instead."); byte[] bytes = Decoders.BASE64.decode(base64EncodedSecretKey); return signWith(alg, bytes); }
@Override public JwtBuilder claim(String name, Object value) { Assert.hasText(name, "Claim property name cannot be null or empty."); if (this.claims == null) { if (value != null) { ensureClaims().put(name, value); } } else { if (value == null) { this.claims.remove(name); } else { this.claims.put(name, value); } } return this; }