Пример #1
0
  /**
   * Sets a header parameter with the specified key and value.
   *
   * <p>If the key matches one of the reserved header parameter names, then the relevant
   * <tt>set</tt> method is called to set that header parameter with the specified value.
   *
   * @param key The key of the header parameter.
   * @param value The value of the header parameter.
   */
  public void setParameter(String key, Object value) {
    JwtHeaderKey headerKey = getHeaderKey(key.toUpperCase());

    switch (headerKey) {
      case TYP:
        {
          if (isValueOfType(value, JwtType.class)) {
            setType((JwtType) value);
          } else {
            checkValueIsOfType(value, String.class);
            setType(JwtType.jwtType((String) value));
          }
          break;
        }
      case ALG:
        {
          if (isValueOfType(value, Algorithm.class)) {
            setAlgorithm((Algorithm) value);
          } else {
            checkValueIsOfType(value, String.class);
            put(ALG.value(), value);
          }
          break;
        }
      default:
        {
          put(key, value);
        }
    }
  }
Пример #2
0
 /**
  * Gets the string representation of the Algorithm set in the JWT header.
  *
  * @return The algorithm as a String.
  */
 protected String getAlgorithmString() {
   return get(ALG.value()).asString();
 }
Пример #3
0
 /**
  * Sets the algorithm used to perform cryptographic signing and/or encryption on the JWT.
  *
  * @param algorithm The Algorithm.
  */
 public void setAlgorithm(Algorithm algorithm) {
   put(ALG.value(), algorithm.toString());
 }