43 lines
1.2 KiB
Java
43 lines
1.2 KiB
Java
package com.tanqidi.survey.controller;
|
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.oauth2.core.user.OAuth2User;
|
|
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;
|
|
|
|
/**
|
|
* <pre>
|
|
* com.edw.controller.IndexController
|
|
* </pre>
|
|
*
|
|
* @author Muhammad Edwin < edwin at redhat dot com >
|
|
* 21 Mar 2023 20:09
|
|
*/
|
|
@RestController
|
|
public class IndexController {
|
|
|
|
@GetMapping(path = "/")
|
|
public Map<String, Object> index() {
|
|
OAuth2User user = (OAuth2User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
return new HashMap<String, Object>() {{
|
|
put("name", user.getAttribute("name"));
|
|
put("email", user.getAttribute("email"));
|
|
put("allAttributes", user.getAttributes()); // 👈 打印所有属性
|
|
}};
|
|
}
|
|
|
|
|
|
|
|
@GetMapping(path = "/unauthenticated")
|
|
public HashMap unauthenticatedRequests() {
|
|
return new HashMap(){{
|
|
put("this is", "unauthenticated endpoint");
|
|
}};
|
|
}
|
|
|
|
}
|