Beispiel #1
0
 @Test
 public void testWriteJwsWithJwkSignedByMac() throws Exception {
   JsonWebKey key = new JsonWebKey();
   key.setKeyType(JsonWebKey.KEY_TYPE_OCTET);
   key.setKeyOperation(
       Arrays.asList(new String[] {JsonWebKey.KEY_OPER_SIGN, JsonWebKey.KEY_OPER_VERIFY}));
   doTestWriteJwsWithJwkSignedByMac(key);
 }
Beispiel #2
0
  @Test
  public void testReadJwsWithJwkSignedByMac() throws Exception {
    JwsJwtCompactConsumer jws =
        new JwsJwtCompactConsumer(ENCODED_TOKEN_WITH_JSON_KEY_SIGNED_BY_MAC);
    assertTrue(jws.verifySignatureWith(new HmacJwsSignatureProvider(ENCODED_MAC_KEY)));
    JwtToken token = jws.getJwtToken();
    JwtHeaders headers = token.getHeaders();
    assertEquals(JwtConstants.TYPE_JWT, headers.getType());
    assertEquals(Algorithm.HmacSHA256.getJwtName(), headers.getAlgorithm());

    JsonWebKey key = headers.getJsonWebKey();
    assertEquals(JsonWebKey.KEY_TYPE_OCTET, key.getKeyType());
    List<String> keyOps = key.getKeyOperation();
    assertEquals(2, keyOps.size());
    assertEquals(JsonWebKey.KEY_OPER_SIGN, keyOps.get(0));
    assertEquals(JsonWebKey.KEY_OPER_VERIFY, keyOps.get(1));

    validateSpecClaim(token.getClaims());
  }