I have a spring 3 application that performs user authentication using spring3. On the server side I can access the current user logged in from SecurityContextHolder.getContext(). But I want to access the current user logged in in the client side in my jquery page. does the spring 3 provide any capability for that? Can somebody suggest some thing regarding this please?
Thanks
As far as I know there is no magic way to expose the principal and authorities to JavaScript in Spring Security.
You can try to do it yourself. Provide a controller that will be responsible for loading the principal and authorities (via SecurityContextHolder) and print them as JSON. Call this controller from within your page and use the result in JS.
From security point of view you cannot trust this info (because user can modify your JS using Chrome inspector for example). You can do two things to make it more secure:
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With