Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package com.example.api.controller;
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;
public class UserController {
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