@SuppressWarnings("unchecked") public static <T> T newInstance(String fqcn, Object... args) { return (T)newInstance(forName(fqcn), args); }
public static <T> T newInstance(String fqcn, Class[] ctorArgTypes, Object... args) { Class<T> clazz = forName(fqcn); Constructor<T> ctor = getConstructor(clazz, ctorArgTypes); return instantiate(ctor, args); }
@SuppressWarnings("WeakerAccess") //for testing protected byte[] toBytes(Object o) { String s; // https://github.com/jwtk/jjwt/issues/380 for Android compatibility (Android doesn't have org.json.JSONWriter): // This instanceof check is a sneaky (hacky?) heuristic: A JwtBuilder only ever provides Map<String,Object> // instances to its serializer instances, so by the time this method is invoked, 'o' will always be a // JSONObject. // // This is sufficient for all JJWT-supported scenarios on Android since Android users shouldn't ever use // JJWT's internal Serializer implementation for general JSON serialization. That is, its intended use // is within the context of JwtBuilder execution and not for application use outside of that. if (o instanceof JSONObject) { s = o.toString(); } else { // we still call JSONWriter for all other values 'just in case', and this works for all valid JSON values // This would fail on Android unless they include the newer org.json dependency and ignore Android's. s = Classes.invokeStatic(JSON_WRITER_CLASS_NAME, "valueToString", VALUE_TO_STRING_ARG_TYPES, o); } return s.getBytes(Strings.UTF_8); } }
public static <T> T newInstance(Class<T> clazz, Object... args) { Class[] argTypes = new Class[args.length]; for (int i = 0; i < args.length; i++) { argTypes[i] = args[i].getClass(); } Constructor<T> ctor = getConstructor(clazz, argTypes); return instantiate(ctor, args); }
/** * Returns a new {@link JwsHeader} instance suitable for digitally signed JWTs (aka 'JWS's). * * @return a new {@link JwsHeader} instance suitable for digitally signed JWTs (aka 'JWS's). * @see JwtBuilder#setHeader(Header) */ public static JwsHeader jwsHeader() { return Classes.newInstance("io.jsonwebtoken.impl.DefaultJwsHeader"); }
public static boolean isAvailable(String fullyQualifiedClassName) { try { forName(fullyQualifiedClassName); return true; } catch (UnknownClassException e) { return false; } }
@SuppressWarnings("WeakerAccess") //to allow testing override protected boolean isAvailable(String fqcn) { return Classes.isAvailable(fqcn); } }
/** * Creates a new {@link Header} instance suitable for <em>plaintext</em> (not digitally signed) JWTs, populated * with the specified name/value pairs. As this is a less common use of JWTs, consider using the * {@link #jwsHeader(java.util.Map)} factory method instead if you will later digitally sign the JWT. * * @return a new {@link Header} instance suitable for <em>plaintext</em> (not digitally signed) JWTs. */ public static Header header(Map<String, Object> header) { return Classes.newInstance("io.jsonwebtoken.impl.DefaultHeader", MAP_ARG, header); }
/** * @since 0.10.0 */ @SuppressWarnings("unchecked") public static <T> T invokeStatic(String fqcn, String methodName, Class[] argTypes, Object... args) { try { Class clazz = Classes.forName(fqcn); Method method = clazz.getDeclaredMethod(methodName, argTypes); method.setAccessible(true); return(T)method.invoke(null, args); } catch (Exception e) { String msg = "Unable to invoke class method " + fqcn + "#" + methodName + ". Ensure the necessary " + "implementation is in the runtime classpath."; throw new IllegalStateException(msg, e); } }
public static <T> T newInstance(Class<T> clazz, Object... args) { Class[] argTypes = new Class[args.length]; for (int i = 0; i < args.length; i++) { argTypes[i] = args[i].getClass(); } Constructor<T> ctor = getConstructor(clazz, argTypes); return instantiate(ctor, args); }
@SuppressWarnings("WeakerAccess") //to allow testing override protected boolean isAvailable(String fqcn) { return Classes.isAvailable(fqcn); } }
@SuppressWarnings("unchecked") public static <T> T newInstance(String fqcn) { return (T)newInstance(forName(fqcn)); }
/** * Returns a new {@link Claims} instance to be used as a JWT body. * * @return a new {@link Claims} instance to be used as a JWT body. */ public static Claims claims() { return Classes.newInstance("io.jsonwebtoken.impl.DefaultClaims"); }
public static <T> T newInstance(String fqcn, Class[] ctorArgTypes, Object... args) { Class<T> clazz = forName(fqcn); Constructor<T> ctor = getConstructor(clazz, ctorArgTypes); return instantiate(ctor, args); }
public static boolean isAvailable(String fullyQualifiedClassName) { try { forName(fullyQualifiedClassName); return true; } catch (UnknownClassException e) { return false; } }
public static <T> T newInstance(Class<T> clazz, Object... args) { Class[] argTypes = new Class[args.length]; for (int i = 0; i < args.length; i++) { argTypes[i] = args[i].getClass(); } Constructor<T> ctor = getConstructor(clazz, argTypes); return instantiate(ctor, args); }
case RS512: case PS512: return Classes.invokeStatic(RSA, "generateKeyPair", SIG_ARG_TYPES, alg); case ES256: case ES384: case ES512: return Classes.invokeStatic(EC, "generateKeyPair", SIG_ARG_TYPES, alg); default: String msg = "The " + alg.name() + " algorithm does not support Key Pairs.";
@SuppressWarnings("WeakerAccess") //to allow testing override protected boolean isAvailable(String fqcn) { return Classes.isAvailable(fqcn); } }
public static void enableBouncyCastleIfPossible() { if (!BOUNCY_CASTLE_AVAILABLE || bcLoaded.get()) { return; } try { Class clazz = Classes.forName(BC_PROVIDER_CLASS_NAME); //check to see if the user has already registered the BC provider: Provider[] providers = Security.getProviders(); for(Provider provider : providers) { if (clazz.isInstance(provider)) { bcLoaded.set(true); return; } } //bc provider not enabled - add it: Security.addProvider((Provider)Classes.newInstance(clazz)); bcLoaded.set(true); } catch (UnknownClassException e) { //not available } }
/** * Returns a new {@link JwtParser} instance that can be configured and then used to parse JWT strings. * * @return a new {@link JwtParser} instance that can be configured and then used to parse JWT strings. */ public static JwtParser parser() { return Classes.newInstance("io.jsonwebtoken.impl.DefaultJwtParser"); }