SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Returns the current user object. This can be User
, UserDetails
or your custom user object.
You will need to cast the return object to UserDetails
or your own user object if it is a custom one.
OR you can inject Authentication
or Principal
directly in to your controllers.
Principle is your UserDetails
/custom user object.
Note: UserDetails
is an interface