question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple applications using jjwt leading to ServiceConfigurationError io.jsonwebtoken.jackson.io.JacksonSerializer not a subtype

See original GitHub issue

Describe the bug Since we updated jjwt from version 0.10.7 to 0.11.X we encounter an error saying io.jsonwebtoken.io.Serializer: Provider io.jsonwebtoken.jackson.io.JacksonSerializer not a subtype We run multiple cxf rest clients on the same TomEE instance, all of them using our internal security module which is working with jjwt to create and validate jwts. Since we updated from version 0.10.7 to a version starting from 0.11.0 we encounter the problem that only the first application using jjwt functionality works like expected. All others following encounter following problem: io.jsonwebtoken.io.Serializer: Provider io.jsonwebtoken.jackson.io.JacksonSerializer not a subtype while creating a JWT. The order of the webservices creating a token doesn’t matter. Trying to mix up which one calls for a jwt first still leads to errors on all other following. Creating a jwt for the first webservice still works after the others tried to get jwts and produce the exception.

This is the code we use to create JWTs:

public static String getNewJWT(@NotNull Key key, String userId, String username, Date expirationDate, HashMap<String, Object> additionalClaims) throws JwtException {
	JwtBuilder builder = Jwts.builder();

	if(!QUtils.mapNullOrEmpty(additionalClaims)) {
		builder.setClaims(additionalClaims);
	}

	return builder.setId(userId).setSubject(username).setExpiration(expirationDate)
		      .setIssuedAt(new Date()).setIssuer(CERTIFICATE_ISSUER).signWith(key)
		      .compact();
}

The Problem happens while doing the compact(). There the serializer is loaded which throws the error mentioned above.

Checking the code I can see the there was a change done starting from 0.11.0 which changed the way the serializer is loaded. Seeing the code my guess is a classLoader problem.

DefaultJwtBuilder.compact(); in V 0.10.7

    if (this.serializer == null) {
        //try to find one based on the runtime environment:
        InstanceLocator<Serializer<Map<String,?>>> locator =
            Classes.newInstance("io.jsonwebtoken.impl.io.RuntimeClasspathSerializerLocator");
        this.serializer = locator.getInstance();
    }`

DefaultJwtBuilder.compact(); in V 0.11.0

    if (this.serializer == null) {
        // try to find one based on the services available
        // TODO: This util class will throw a UnavailableImplementationException here to retain behavior of previous version, remove in v1.0
        // use the previous commented out line instead
        this.serializer = LegacyServices.loadFirst(Serializer.class);
    }`

To Reproduce Steps to reproduce the behavior:

  1. Doing authentication on first webservice
  2. DefaultJwtBuilder.compact() loads an instance of JacksonSerializer without problem
  3. Doing authentication on any following webservice
  4. DefaultJwtBuilder.compact() fails to load an instance of JacksonSerializer saying io.jsonwebtoken.io.Serializer: Provider io.jsonwebtoken.jackson.io.JacksonSerializer not a subtype

Expected behavior DefaultJwtBuilder.compact() loads an instance of JacksonSerializer correctly

stacktrace.txt

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
raphisutercommented, Aug 9, 2022

Thank you @lhazlewood for your help and effort, really appreciate it.

1reaction
lhazlewoodcommented, Aug 8, 2022

Thanks again for the report on this @raphisuter. I’m closing this issue now that we have #752 to represent work to address this issue as well as #648.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to find an implementation for interface io ... - GitHub
Hi guys, We are seeing this error: Unable to find an implementation for interface io.jsonwebtoken.io.Serializer using java.util.
Read more >
JJWT / Jackson alter the ObjectMapper used - Stack Overflow
For a project I am working on, I am required to use Spring Security and JSON Webtokens as provided by the ...
Read more >
jwts signwith deprecated | The Search Engine You Control
jwtk/jjwtMultiple applications using jjwt leading to ServiceConfigurationError io.jsonwebtoken.jackson.io.JacksonSerializer not a subtype#751.
Read more >
JacksonSerializer (JJWT :: Extensions :: Jackson 0.11.1 API)
Class JacksonSerializer<T>. java.lang.Object. io.jsonwebtoken.jackson.io.JacksonSerializer<T>. All Implemented Interfaces: Serializer<T> ...
Read more >
io.jsonwebtoken.jackson.io.JacksonDeserializer Maven ...
JacksonDeserializer maven / gradle build tool code. The class is part of the package ➦ Group: io.jsonwebtoken ➦ Artifact: jjwt-jackson ➦ Version: 0.11.2....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found