Java Code Examples for io.jsonwebtoken.Jwt#getBody()

The following examples show how to use io.jsonwebtoken.Jwt#getBody() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JjwtDeserializerTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void foo() {
    final Map<String, Object> claims = new HashMap<>();
    claims.put(Claims.ISSUER, KNOWN_ISS);
    claims.put(Claims.SUBJECT, KNOWN_SUB);
    final String compact = Jwts.builder()
            .serializeToJsonWith(JjwtSerializer.getInstance())
            .setClaims(claims)
            .setExpiration(KNOWN_EXP)
            .compact();

    final Jwt jwt = Jwts.parser()
            .deserializeJsonWith(JjwtDeserializer.getInstance())
            .parse(compact);

    final Object jwtBody = jwt.getBody();

    Assertions.assertThat(jwtBody).isInstanceOf(Claims.class);
    Assertions.assertThat(((Claims) jwtBody).get(Claims.ISSUER)).isEqualTo(KNOWN_ISS);
    Assertions.assertThat(((Claims) jwtBody).get(Claims.SUBJECT)).isEqualTo(KNOWN_SUB);
    Assertions.assertThat(((Claims) jwtBody).get(Claims.EXPIRATION)).isEqualTo((int) (KNOWN_EXP.getTime() / 1000L));
}
 
Example 2
Source File: ConfigCheckingJwtHandler.java    From apiman-plugins with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Object> onClaimsJwt(@SuppressWarnings("rawtypes") Jwt<Header, Claims> jwt) {
    return config.getRequireSigned() ? super.onClaimsJwt(jwt) : jwt.getBody();
}