Since version 5.2 you can use CurrentSecurityContext annotation to get the current user authentication:
@GetMapping("/authentication")
public Object authentication(@CurrentSecurityContext(expression="authentication")
Authentication authentication) {
return authentication.getDetails();
}
or even:
@GetMapping("/hello")
public String hello(@CurrentSecurityContext(expression="authentication.name")
String username) {
return "Hello, " + username + "!";
}
https://stackoverflow.com/questions/32052076/how-to-get-the-current-logged-in-user-object-from-spring-security
Aucun commentaire:
Enregistrer un commentaire
to criticize, to improve