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 2eb978e01b
commit 8553d79655
1 changed files with 16 additions and 0 deletions

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();
}
}