io.jsonwebtoken.io.Deserializer Java Examples

The following examples show how to use io.jsonwebtoken.io.Deserializer. 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: DefaultJwtParser.java    From jjwt with Apache License 2.0 6 votes vote down vote up
DefaultJwtParser(SigningKeyResolver signingKeyResolver,
                 Key key,
                 byte[] keyBytes,
                 Clock clock,
                 long allowedClockSkewMillis,
                 Claims expectedClaims,
                 Decoder<String, byte[]> base64UrlDecoder,
                 Deserializer<Map<String, ?>> deserializer,
                 CompressionCodecResolver compressionCodecResolver) {
    this.signingKeyResolver = signingKeyResolver;
    this.key = key;
    this.keyBytes = keyBytes;
    this.clock = clock;
    this.allowedClockSkewMillis = allowedClockSkewMillis;
    this.expectedClaims = expectedClaims;
    this.base64UrlDecoder = base64UrlDecoder;
    this.deserializer = deserializer;
    this.compressionCodecResolver = compressionCodecResolver;
}
 
Example #2
Source File: DefaultJwtParserBuilder.java    From jjwt with Apache License 2.0 6 votes vote down vote up
@Override
public JwtParser build() {

    // Only lookup the deserializer IF it is null. It is possible a Deserializer implementation was set
    // that is NOT exposed as a service and no other implementations are available for lookup.
    if (this.deserializer == null) {
        // try to find one based on the services available:
        this.deserializer = Services.loadFirst(Deserializer.class);
    }

    return new ImmutableJwtParser(
            new DefaultJwtParser(signingKeyResolver,
                                 key,
                                 keyBytes,
                                 clock,
                                 allowedClockSkewMillis,
                                 expectedClaims,
                                 base64UrlDecoder,
                                 deserializer,
                                 compressionCodecResolver));
}
 
Example #3
Source File: JjwtDeserializer.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return the instance of {@link JjwtDeserializer}.
 */
public static Deserializer getInstance() {
    if (instance == null) {
        instance = new JjwtDeserializer();
    }
    return instance;
}
 
Example #4
Source File: JwksAuthenticator.java    From trellis with Apache License 2.0 5 votes vote down vote up
private static Map<String, Key> buildKeys(final String location) {
    // TODO eventually, this will become part of the JJWT library
    final Deserializer<Map<String, List<Map<String, String>>>> deserializer = new JacksonDeserializer<>();
    try (final InputStream input = new URL(location).openConnection().getInputStream()) {
        return deserializer.deserialize(IOUtils.toByteArray(input)).getOrDefault("keys", emptyList()).stream()
            .map(JwksAuthenticator::buildKeyEntry).filter(Objects::nonNull).collect(collectingAndThen(
                        toMap(Map.Entry::getKey, Map.Entry::getValue), Collections::unmodifiableMap));
    } catch (final IOException ex) {
        LOGGER.error("Error fetching/parsing jwk document", ex);
    }
    return emptyMap();
}
 
Example #5
Source File: ImmutableJwtParser.java    From jjwt with Apache License 2.0 4 votes vote down vote up
@Override
public JwtParser deserializeJsonWith(Deserializer<Map<String, ?>> deserializer) {
    throw doNotMutate();
}
 
Example #6
Source File: DefaultJwtParser.java    From jjwt with Apache License 2.0 4 votes vote down vote up
@Override
public JwtParser deserializeJsonWith(Deserializer<Map<String, ?>> deserializer) {
    Assert.notNull(deserializer, "deserializer cannot be null.");
    this.deserializer = deserializer;
    return this;
}
 
Example #7
Source File: DefaultJwtParserBuilder.java    From jjwt with Apache License 2.0 4 votes vote down vote up
@Override
public JwtParserBuilder deserializeJsonWith(Deserializer<Map<String, ?>> deserializer) {
    Assert.notNull(deserializer, "deserializer cannot be null.");
    this.deserializer = deserializer;
    return this;
}
 
Example #8
Source File: JwtParserBuilder.java    From jjwt with Apache License 2.0 2 votes vote down vote up
/**
 * Uses the specified deserializer to convert JSON Strings (UTF-8 byte arrays) into Java Map objects.  This is
 * used by the parser after Base64Url-decoding to convert JWT/JWS/JWT JSON headers and claims into Java Map
 * objects.
 *
 * <p>If this method is not called, JJWT will use whatever deserializer it can find at runtime, checking for the
 * presence of well-known implementations such Jackson, Gson, and org.json.  If one of these is not found
 * in the runtime classpath, an exception will be thrown when one of the various {@code parse}* methods is
 * invoked.</p>
 *
 * @param deserializer the deserializer to use when converting JSON Strings (UTF-8 byte arrays) into Map objects.
 * @return the builder for method chaining.
 */
JwtParserBuilder deserializeJsonWith(Deserializer<Map<String,?>> deserializer);
 
Example #9
Source File: JwtParser.java    From jjwt with Apache License 2.0 2 votes vote down vote up
/**
 * Uses the specified deserializer to convert JSON Strings (UTF-8 byte arrays) into Java Map objects.  This is
 * used by the parser after Base64Url-decoding to convert JWT/JWS/JWT JSON headers and claims into Java Map
 * objects.
 *
 * <p>If this method is not called, JJWT will use whatever deserializer it can find at runtime, checking for the
 * presence of well-known implementations such Jackson, Gson, and org.json.  If one of these is not found
 * in the runtime classpath, an exception will be thrown when one of the various {@code parse}* methods is
 * invoked.</p>
 *
 * @param deserializer the deserializer to use when converting JSON Strings (UTF-8 byte arrays) into Map objects.
 * @return the parser for method chaining.
 * @since 0.10.0
 * @deprecated see {@link JwtParserBuilder#deserializeJsonWith(Deserializer)} )}.
 * To construct a JwtParser use the corresponding builder via {@link Jwts#parserBuilder()}. This will construct an
 * immutable JwtParser.
 * <p><b>NOTE: this method will be removed before version 1.0</b>
 */
@Deprecated
JwtParser deserializeJsonWith(Deserializer<Map<String,?>> deserializer);