获取 jhi_persistenet_audit_event table 当前记录的用户详细信息

Geting Current logged user details for jhi_persistenet_audit_event table

我正在使用 jhipster。我需要创建一个新的 table 来审核我的数据库更改,并使用 Jhipster 生成的默认值 jhi_persistenet_audit_event table link 来创建它。如何获取当前登录的用户记录,从 jhi_persistenet_audit_event table 到 link 那个 id 到我的新 table?

Solution 1: Principal principal

    @RequestMapping(value = {"/", ""})
    public String start(Principal principal, Model model) {
           String currentUser = principal.getName();       
           return currentUser;
    }

Solution 2: Authentication authentication

@RequestMapping(value = {"/", ""})
public String currentUserName(Authentication authentication) {
        return authentication.getName();
}

Solution 3: SecurityContextHolder

Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
  String username = ((UserDetails)principal).getUsername();
} else {
  String username = principal.toString();
}

Details 1 Details 2