How to get active user's UserDetails with AuthenticationPrincipal (#14398)

This commit is contained in:
Michael Olayemi
2023-07-15 01:40:27 +00:00
committed by GitHub
parent 1476484426
commit 43faa3ff58

View File

@@ -0,0 +1,16 @@
package com.baeldung.web.controller;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class SecurityController4 {
@GetMapping("/user")
public String getUser(@AuthenticationPrincipal UserDetails userDetails) {
return "User Details: " + userDetails.getUsername();
}
}