forked from admin/springboot-demo
24 lines
779 B
Java
24 lines
779 B
Java
|
|
package com.example.demo.controller.auth;
|
||
|
|
|
||
|
|
import com.example.demo.common.ApiResponse;
|
||
|
|
import org.springframework.security.core.Authentication;
|
||
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RestController;
|
||
|
|
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/api/secure")
|
||
|
|
public class SecureDemoController {
|
||
|
|
|
||
|
|
@GetMapping("/me")
|
||
|
|
public ApiResponse<Map<String, Object>> me(Authentication authentication) {
|
||
|
|
return ApiResponse.ok(Map.of(
|
||
|
|
"principal", authentication.getName(),
|
||
|
|
"authorities", authentication.getAuthorities(),
|
||
|
|
"message", "你已通过学习用 JWT 鉴权"
|
||
|
|
));
|
||
|
|
}
|
||
|
|
}
|