package com.example.rzgb.auth; import java.util.Map; import org.springframework.web.bind.annotation.*; import org.springframework.security.web.csrf.CsrfToken; import org.springframework.security.core.Authentication; /** 登录由过滤器处理;这两个读取接口提供 CSRF 引导和刷新后的真实会话恢复。 */ @RestController @RequestMapping("/api/auth") public class AuthController { @GetMapping("/csrf") Map csrf(CsrfToken token) { return Map.of("token", token.getToken(), "headerName", token.getHeaderName()); } @GetMapping("/me") Map me(Authentication auth) { return Map.of("username", auth.getName()); } }