/** * 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"); }
/** * 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); }
/** * 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"); }
/** * 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"); }
/** * Creates a new {@link Header} instance suitable for <em>plaintext</em> (not digitally signed) JWTs. As this * is a less common use of JWTs, consider using the {@link #jwsHeader()} 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() { return Classes.newInstance("io.jsonwebtoken.impl.DefaultHeader"); }
/** * Returns a new {@link Claims} instance populated with the specified name/value pairs. * * @param claims the name/value pairs to populate the new Claims instance. * @return a new {@link Claims} instance populated with the specified name/value pairs. */ public static Claims claims(Map<String, Object> claims) { return Classes.newInstance("io.jsonwebtoken.impl.DefaultClaims", MAP_ARG, claims); }
/** * Returns a new {@link JwsHeader} instance suitable for digitally signed JWTs (aka 'JWS's), populated with the * specified name/value pairs. * * @return a new {@link JwsHeader} instance suitable for digitally signed JWTs (aka 'JWS's), populated with the * specified name/value pairs. * @see JwtBuilder#setHeader(Header) */ public static JwsHeader jwsHeader(Map<String, Object> header) { return Classes.newInstance("io.jsonwebtoken.impl.DefaultJwsHeader", MAP_ARG, header); }
/** * Returns a new {@link JwtBuilder} instance that can be configured and then used to create JWT compact serialized * strings. * * @return a new {@link JwtBuilder} instance that can be configured and then used to create JWT compact serialized * strings. */ public static JwtBuilder builder() { return Classes.newInstance("io.jsonwebtoken.impl.DefaultJwtBuilder"); } }
@SuppressWarnings("WeakerAccess") //to allow testing override protected Deserializer<T> locate() { if (isAvailable("com.fasterxml.jackson.databind.ObjectMapper")) { return Classes.newInstance("io.jsonwebtoken.io.JacksonDeserializer"); } else if (isAvailable("org.json.JSONObject")) { return Classes.newInstance("io.jsonwebtoken.io.OrgJsonDeserializer"); } else { throw new IllegalStateException("Unable to discover any JSON Deserializer implementations on the classpath."); } }
@SuppressWarnings("unchecked") public static <T> T newInstance(String fqcn, Object... args) { return (T)newInstance(forName(fqcn), args); }
@SuppressWarnings("WeakerAccess") //to allow testing override protected Serializer<Object> locate() { if (isAvailable("com.fasterxml.jackson.databind.ObjectMapper")) { return Classes.newInstance("io.jsonwebtoken.io.JacksonSerializer"); } else if (isAvailable("org.json.JSONObject")) { return Classes.newInstance("io.jsonwebtoken.io.OrgJsonSerializer"); } else { throw new IllegalStateException("Unable to discover any JSON Serializer implementations on the classpath."); } }
@SuppressWarnings("unchecked") public static <T> T newInstance(String fqcn) { return (T)newInstance(forName(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 } }
Classes.newInstance("io.jsonwebtoken.impl.io.RuntimeClasspathDeserializerLocator"); this.deserializer = locator.getInstance();
Classes.newInstance("io.jsonwebtoken.impl.io.RuntimeClasspathSerializerLocator"); this.serializer = locator.getInstance();
/** * 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"); }
/** * 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); }
/** * 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"); }
@SuppressWarnings("WeakerAccess") //to allow testing override protected Deserializer<T> locate() { if (isAvailable("com.fasterxml.jackson.databind.ObjectMapper")) { return Classes.newInstance("io.jsonwebtoken.io.JacksonDeserializer"); } else if (isAvailable("org.json.JSONObject")) { return Classes.newInstance("io.jsonwebtoken.io.OrgJsonDeserializer"); } else { throw new IllegalStateException("Unable to discover any JSON Deserializer implementations on the classpath."); } }
@SuppressWarnings("unchecked") public static Object newInstance(String fqcn, Object... args) { return newInstance(forName(fqcn), args); }