Closed
Description
Before reporting an issue
- I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.
Area
core
Describe the bug
Encoding a token can result in an NPE in case no client is set to the session.
In the DefaultTokenManager some functions check for that fact but not the type(TokenCategory) function. As a result, when calling encode(Token) a NPE is thrown.
Version
26.2.5
Regression
- The issue is a regression
Expected behavior
I would like to have the token encoded without having an NPE thrown.
Actual behavior
The NPE is thrown.
How to Reproduce?
AccessToken newToken = new AccessToken();
newToken.id(KeycloakModelUtils.generateId());
newToken.type(TokenUtil.TOKEN_TYPE_BEARER);
...
...
newTokenString = session.tokens().encode(newToken);
Anything else?
I will provide a PR to fix the issue.