Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.springframework.security.core.Authentication;
- import org.springframework.security.core.context.SecurityContextHolder;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RestController;
- @RestController
- public class ExampleController {
- @GetMapping("/")
- public Object index() {
- return getCurrentUser();
- }
- public Object getCurrentUser() {
- Authentication auth = SecurityContextHolder.getContext().getAuthentication();
- return auth.getPrincipal();
- }
- }
Add Comment
Please, Sign In to add comment