Closed pvannierop closed 4 years ago
Stackoverflow would be a better place for such questions (lot more audience).
There are a lot of different solutions depending on your use case (and maybe a little confusion).
java.security.Principal
or the dirty shapeless Object
returned by org.springframework.security.core.Authentication::getPrincipal
?Considering your requirements, I would discourage a widely spread solution: authorities claim in a JWT. A JWT is sealed and self sufficient until its expiry which is programmed. There is no simple way to change the authorities it contains. If you want to change authorities the JWT holder is granted with, you basically have to wait until the token expires and the holder returns to the authorisation-server to get a new access-token.
This leaves you with at least two solutions:
You can find a sample for second option in this repo (samples involving JPA), but if your client requests a centralized authorities management on Keycloak server, this is not what you need and should consider introspection instead.
@ch4mpy Thank you for this great explanation! Especially your advise on the specific restrictions on authorities claim in a JWT is an eye opener. I will look further into introspection, since this seems to fit my usecase very well. Again, many thanks for taking the time to inform me.
@ch4mpy This issue is not so much a bug report, but a request on whether the spring-addons tools are useful in this use-case.
My client uses keycloak IDP and adds roles to a user at some moments. I would like to trigger a refresh of the user principal in the same session when this happens. One way I see would be to manually update the keycloakSecurityContext in the Principal. Another would be to trigger a refresh of the access token with the normal OAuth2 workflow. Do your Authorities addons support any of these situations?
Please be aware that I am not very experienced in Spring Security so after reading the README of the relevant section it is not entirely clear to me what (if at all) your lib can do for my needs.