So I am just moving from the InMemoryTokenStore
to the JdbcTokenStore
. As usual, one seemingly simple change is followed by a handful of side effects including swallowed exceptions - sorry for the rant.
This is how I used to access the users' principal:
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String username = (String) authentication.getPrincipal();
First
For some reason, getPrincipal()
always returned just the username instead of the UserDetails
object. This was good enough for me so I went with it.
Now that I changed the token store, getPrincipal()
does indeed return the UserDetails
object. I can live with that but I would like to know why this changed all of a sudden - I have to refactor some code because of that since I always expected the username from getPrincipal()
up to now. I also would like to know whether I can change that.
Second
From what I can see, the JdbcTokenStore
seems to serialize Java objects. It tries to serialize a Token
object and a UserDetails
object. The columns token
and authentication
seem to represent those serialized objects and I would like to understand why this is actually necessary. After all this is information which could be recoverd during startup/runtime from the database. Except the Token
of course but I don't get why they don't just store the token (the String
) but instead the object.
Most of all: The slightest change to any of those classes and they won't be deserializable! Every user will be forced to a new login if one of those classes gets changed which kind of defies the reason why I want to use the JdbcTokenStore
in the first place - so there must be something fishy or I am not getting it.
Maybe somebody could shed more light on this.