Problem while Deserializing java.timeDuration.class with org.springframework.security.oauth2.server.authorization.jackson2.DurationMixin with JdbcRegisteredClientRepository #1984
Labels
type: bug
A general bug
Describe the bug
Deserializing a Duration.class instance stored as JSON in oauth2_registered_client table in the token_settings column doesn't use the registered mixin of org.springframework.security.oauth2.server.authorization.jackson2.DurationMixin annotated with
but the:
com.fasterxml.jackson.datatype.jsr310.ser.DurationSerializer
registered from the:
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
resulting in the following exception:
Because the token_settings are stored as a JSON in the database, and are deserialized in runtime using
JdbcRegisteredClientRepository's parseMap:
as far as I understand the stored JSON value must declared its' class types like this for the Generic deserializer to work:
If the above statement is wrong, then this whole issue is non existing, and I'm just not persisting the information correct to the database.
To Reproduce
I am using PostgresSQL and I am attaching my flyway db migration files for the schema I am using, grabbed it from the official documentation.
Register a jdbc client with the client credential flow and a token setting of access token expiration:
Try to issue a token from the authorization server:
Expected behavior
I am expecting to get a success 200 Resposne and an access token which will be valid for 7200 seconds, but I am getting a response of 302 Found and prompt for login, because internally there was an error which was not handled properly.
There is not login also in the client_credentials flow.
Sample
You can recreate the problem by pulling:
https://github.com/Ibanezos92/spring_authorization_server_deserialization_problem
You need a postgres that you can create with docker:
docker run -e POSTGRES_PASSWORD=pass123 -p 5432:5432 -d -v /Users/home/Documents/psql/data:/var/lib/postgresql/data postgres
I have created a fix, that I am registering a custom deserializing as I think that the mixin is the problem. Maybe because the java.time.Duration is a final class, those mixin annotations cannot be applied, so it reverts to the registered com.fasterxml.jackson.datatype.jsr310.ser.DurationSerializer.
Also the JsonCreator of org.springframework.security.oauth2.server.authorization.jackson2.DurationMixin does not return a java.time.Duration object but a void, which it seems wrong (or maybe I am missing something).
To see a working solution Instead of using the problematic:
com.example.AuthServerConfig_Problem
which replicates the problem, you may use:
com.example.AuthServerConfig_CustomFix
by commenting/uncommenting the @configuration.
which uses my custom registered Duration Deserializer.
The repository uses Groovy instead of Java.
The text was updated successfully, but these errors were encountered: