io.jsonwebtoken.RequiredTypeException Java Examples
The following examples show how to use
io.jsonwebtoken.RequiredTypeException.
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: DefaultOAuthJwtAccessToken.java From athenz with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public List<String> getAudiences() { // https://tools.ietf.org/html/rfc7519#page-9 List<String> audiences; try { // returns null if not found audiences = this.body.get(Claims.AUDIENCE, ArrayList.class); } catch (RequiredTypeException e) { if (LOG.isDebugEnabled()) { LOG.debug("DefaultOAuthJwtAccessToken:getAudiences treat audience as string, err: " + e.getMessage()); } // found but class mismatch audiences = Arrays.asList(new String[]{ this.body.getAudience() }); } return audiences; }
Example #2
Source File: DefaultOAuthJwtAccessToken.java From athenz with Apache License 2.0 | 6 votes |
@Override public String getCertificateThumbprint() { // https://github.com/jwtk/jjwt/issues/404, custom model class not supported LinkedHashMap<?, ?> certConf = null; try { certConf = this.body.get(OAuthJwtAccessToken.CLAIM_CONFIRM, LinkedHashMap.class); if (certConf == null) { return null; } } catch (RequiredTypeException e) { if (LOG.isDebugEnabled()) { LOG.debug("DefaultOAuthJwtAccessToken:getCertificateThumbprint expected data type to be JSON object, err: " + e.getMessage()); } return null; } return (String) certConf.get(OAuthJwtAccessToken.CLAIM_CONFIRM_X509_HASH); }
Example #3
Source File: DefaultClaims.java From jjwt with Apache License 2.0 | 6 votes |
private <T> T castClaimValue(Object value, Class<T> requiredType) { if (value instanceof Integer) { int intValue = (Integer) value; if (requiredType == Long.class) { value = (long) intValue; } else if (requiredType == Short.class && Short.MIN_VALUE <= intValue && intValue <= Short.MAX_VALUE) { value = (short) intValue; } else if (requiredType == Byte.class && Byte.MIN_VALUE <= intValue && intValue <= Byte.MAX_VALUE) { value = (byte) intValue; } } if (!requiredType.isInstance(value)) { throw new RequiredTypeException(String.format(CONVERSION_ERROR_MSG, value.getClass(), requiredType)); } return requiredType.cast(value); }
Example #4
Source File: Device.java From hono with Eclipse Public License 2.0 | 5 votes |
/** * Creates a new device for a token. * <p> * The token is expected to contain the device identifier in the <em>sub</em> claim and * the tenant identifier in the <em>ten</em> claim. * * @param token The token asserting the device's identity. * @throws NullPointerException if the token does not contain a tenant and device identifier. */ public Device(final Jws<Claims> token) { this(Objects.requireNonNull(token).getBody().get("ten", String.class), token.getBody().getSubject()); try { final Set<?> aut = token.getBody().get("aut", Set.class); if (aut != null) { authorities.addAll(aut); } } catch (final RequiredTypeException e) { // token contains no authorities claim } }
Example #5
Source File: Auth0Jwt.java From athenz with Apache License 2.0 | 5 votes |
@Override public String getCertificateThumbprint() { LinkedHashMap<?, ?> certConf = null; try { certConf = this.body.get(Auth0Jwt.claimConfirm, LinkedHashMap.class); if (certConf == null) { return null; } } catch (RequiredTypeException e) { return null; } return (String) certConf.get(OAuthJwtAccessToken.CLAIM_CONFIRM_X509_HASH); }