获取jhi_persistenet_audit_event表的当前已记录用户详细信息 [英] Geting Current logged user details for jhi_persistenet_audit_event table
本文介绍了获取jhi_persistenet_audit_event表的当前已记录用户详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在和jhipster一起工作.我需要创建一个新表来审核数据库更改,并将其与Jhipster生成的默认jhi_persistenet_audit_event表链接.如何从jhi_persistenet_audit_event表中获取当前记录的用户记录,以将该ID链接到我的新表?
I am working with jhipster. I need to create a new table for auditing my database changes and link it with the default jhi_persistenet_audit_event table generated by the Jhipster. How I can get the current logged user record from the jhi_persistenet_audit_event table to link that id to my new table?
推荐答案
解决方案1:主要负责人
Solution 1: Principal principal
@RequestMapping(value = {"/", ""})
public String start(Principal principal, Model model) {
String currentUser = principal.getName();
return currentUser;
}
解决方案2:身份验证
Solution 2: Authentication authentication
@RequestMapping(value = {"/", ""})
public String currentUserName(Authentication authentication) {
return authentication.getName();
}
解决方案3:SecurityContextHolder
Solution 3: SecurityContextHolder
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
String username = ((UserDetails)principal).getUsername();
} else {
String username = principal.toString();
}
这篇关于获取jhi_persistenet_audit_event表的当前已记录用户详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文