Created
January 16, 2022 16:04
-
-
Save iamprafful/aa7c5d6215f7ccd63ba33114eb51204c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.api.controller; | |
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.RequestMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
import java.util.HashMap; | |
import java.util.Map; | |
@RestController | |
@RequestMapping("/user") | |
public class UserController { | |
@GetMapping | |
public Map<String, Object> getUserName() { | |
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | |
Map<String, Object> userMap = new HashMap<>(); | |
userMap.put("username", authentication.getName()); | |
userMap.put("error", false); | |
return userMap; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment