Question about SecurityContextHolder from Spring Boot Security

Speaking about Spring Boot RestController... - can I extract a username from SecurityContextHolder only once outside of all methods and then use that string username in any methods as a class scope variable or a constant? Or should the username acquiring be only inside any particular method that has @Secured({"..."}) and mapping annotations? Can the SecurityContextHolder be in a service?
8 Replies
JavaBot
JavaBot3y ago
Hey, @Tomasm21! Please remember to /close this post once your question has been answered!
dan1st
dan1st3y ago
as long as it runs in the same thread as the controller ig
Tomasm21
Tomasm21OP3y ago
what's ig
dan1st
dan1st3y ago
I guess
Tomasm21
Tomasm21OP3y ago
mk.. ok I'll test it myself anytime.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dan1st
dan1st3y ago
I meant that SecurityContextHolder uses ThreadLocal
JavaBot
JavaBot3y ago
Post Closed
This post has been closed by <@312509109863710732> for the following reason:
Andrew and Dan answered
Want results from more Discord servers?
Add your server