79480140

Date: 2025-03-03 04:04:22
Score: 2.5
Natty:
Report link

To get username of the authenticated user, we have to use getName()

Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String currentUser = auth.getName();

Refer: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/security/Principal.html#getName()

Reasons:
  • Probably link only (1):
  • Low length (0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Naveen Raj