@Test void testGetClaim() { Jwt jwt = Jwt.builder() .issuer("issuer") .subject("subject") .addUserGroup("users") .addUserGroup("admins") .build(); SignedJwt signed = SignedJwt.sign(jwt, Jwk.NONE_JWK); JsonWebTokenImpl impl = JsonWebTokenImpl.create(signed); assertAll( () -> testClaimType(impl, Claims.sub), () -> testClaimType(impl, Claims.groups), () -> testClaimType(impl, Claims.iss) ); }
@SuppressWarnings("unchecked") @Override public <T> T getClaim(String claimName) { try { return (T) getClaim(Claims.valueOf(claimName)); } catch (IllegalArgumentException e) { return (T) getJsonValue(claimName).orElse(null); } }
JsonWebTokenImpl implements JsonWebToken, Principal { @SuppressWarnings("unchecked") @Override public <T> T getClaim(String claimName) { try { return (T) getClaim(Claims.valueOf(claimName)); } catch (IllegalArgumentException e) { return (T) getJsonValue(claimName).orElse(null); } } }
JsonWebTokenImpl implements JsonWebToken, Principal { @SuppressWarnings("unchecked") @Override public <T> T getClaim(String claimName) { try { return (T) getClaim(Claims.valueOf(claimName)); } catch (IllegalArgumentException e) { return (T) getJsonValue(claimName).orElse(null); } } private  JsonWebTokenImpl(SignedJwt signed); }
JsonWebTokenImpl implements JsonWebToken, Principal { @SuppressWarnings("unchecked") @Override public <T> T getClaim(String claimName) { try { return (T) getClaim(Claims.valueOf(claimName)); } catch (IllegalArgumentException e) { return (T) getJsonValue(claimName).orElse(null); } } private  JsonWebTokenImpl(SignedJwt signed); @Override String getName(); @Override Set<String> getClaimNames(); @SuppressWarnings("unchecked") @Override T getClaim(String claimName); @SuppressWarnings("unchecked") T getClaim(String claimName, Class<T> clazz); @Override Object abacAttributeRaw(String key); @Override Collection<String> abacAttributeNames(); @Override String id(); }
JsonWebTokenImpl implements JsonWebToken, Principal { @SuppressWarnings("unchecked") @Override public <T> T getClaim(String claimName) { try { return (T) getClaim(Claims.valueOf(claimName)); } catch (IllegalArgumentException e) { return (T) getJsonValue(claimName).orElse(null); } } private  JsonWebTokenImpl(SignedJwt signed); @Override String getName(); @Override Set<String> getClaimNames(); @SuppressWarnings("unchecked") @Override T getClaim(String claimName); @SuppressWarnings("unchecked") T getClaim(String claimName, Class<T> clazz); @Override Object abacAttributeRaw(String key); @Override Collection<String> abacAttributeNames(); @Override String id();  }