Beispiel #1
0
  private JwsCompactProducer initSpecJwtTokenWriter(JwtHeaders headers) throws Exception {

    JwtClaims claims = new JwtClaims();
    claims.setIssuer("joe");
    claims.setExpiryTime(1300819380L);
    claims.setClaim("http://example.com/is_root", Boolean.TRUE);

    JwtToken token = new JwtToken(headers, claims);
    return new JwsJwtCompactProducer(token, getWriter());
  }
Beispiel #2
0
  private void doTestWriteJwsWithJwkSignedByMac(Object jsonWebKey) throws Exception {
    JwtHeaders headers = new JwtHeaders(Algorithm.HmacSHA256.getJwtName());

    headers.setHeader(JwtConstants.HEADER_JSON_WEB_KEY, jsonWebKey);

    JwtClaims claims = new JwtClaims();
    claims.setIssuer("joe");
    claims.setExpiryTime(1300819380L);
    claims.setClaim("http://example.com/is_root", Boolean.TRUE);

    JwtToken token = new JwtToken(headers, claims);
    JwsCompactProducer jws = new JwsJwtCompactProducer(token, getWriter());
    jws.signWith(new HmacJwsSignatureProvider(ENCODED_MAC_KEY));

    assertEquals(ENCODED_TOKEN_WITH_JSON_KEY_SIGNED_BY_MAC, jws.getSignedEncodedJws());
  }
Beispiel #3
0
  @Test
  public void testWriteReadJwsUnsigned() throws Exception {
    JwtHeaders headers = new JwtHeaders(JwtConstants.PLAIN_TEXT_ALGO);

    JwtClaims claims = new JwtClaims();
    claims.setIssuer("https://jwt-idp.example.com");
    claims.setSubject("mailto:[email protected]");
    claims.setAudience("https://jwt-rp.example.net");
    claims.setNotBefore(1300815780L);
    claims.setExpiryTime(1300819380L);
    claims.setClaim("http://claims.example.com/member", true);

    JwsCompactProducer writer = new JwsJwtCompactProducer(headers, claims);
    String signed = writer.getSignedEncodedJws();

    JwsJwtCompactConsumer reader = new JwsJwtCompactConsumer(signed);
    assertEquals(0, reader.getDecodedSignature().length);

    JwtToken token = reader.getJwtToken();
    assertEquals(new JwtToken(headers, claims), token);
  }
Beispiel #4
0
 private void validateSpecClaim(JwtClaims claims) {
   assertEquals("joe", claims.getIssuer());
   assertEquals(Long.valueOf(1300819380), claims.getExpiryTime());
   assertEquals(Boolean.TRUE, claims.getClaim("http://example.com/is_root"));
 }