How to get active user's UserDetails with AuthenticationPrincipal (#14398)
This commit is contained in:
parent
2eb978e01b
commit
8553d79655
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue