How to access to current logged user in controllers?
Mistral opened this issue · 1 comments
Mistral commented
How can I get access to current logged user in rest controllers? Now I am injecting Principal principal
after that I have to load user using principal.getName()
and then I can pass to other services User object.
Is there any better solution to inject current User (object) to any methods?
Mistral commented
Ok. I found the solution.
User
entity should implementsUserDetails
- In
MyUserDetails
changeloadUserByUsername()
method to return ourUser
model, notorg.springframework.security.core.userdetails.User
. Remember to implement all necessary methods, and make them toreturn true
- Inject
User user
to your controller method.