forked from admin/springboot-demo
feat(learning-auth): add optional JWT learning flow with secure demo endpoint
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
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 鉴权"
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user