package com.example.rzgb.auth; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Component; /** 用户 ID 从服务端已验证身份获取,业务接口不接受浏览器提交的 owner/userId。 */ @Component public class CurrentUser { private final JdbcTemplate jdbc; public CurrentUser(JdbcTemplate jdbc) { this.jdbc = jdbc; } public String id(Authentication auth) { return jdbc.queryForObject("SELECT id FROM app_user WHERE username=?", String.class, auth.getName()); } }