我正在关注链接http://middlewaremagic.com/weblogic/?p=2034以执行基于表单的身份验证。我创建了一个安全领域,然后成功将身份验证检查委托给weblogic 10.3。 一切都很好,但我无法获得用户名,HttpServletRequest-> getRemoteUser()返回null。
您是否知道如何在登录后获取用户名?我将在每个Managed bean中使用username来记录用户操作。
修改 我发现我的错误是在记录用户操作(注销操作)之前使会话无效,这就是为什么HttpServletRequest-> getRemoteUser()返回null。感谢您的贡献。
答案 0 :(得分:2)
您也可以从SecurityContext获取它:
SecurityContextHolder.getContext().getAuthentication().getPrincipal().getUserName();
答案 1 :(得分:1)
尝试从请求中获取用户主体,然后从中获取名称。像这样:
Principal p = request.getUserPrincipal();
String username = p.getName();
答案 2 :(得分:1)
j_username
中提供了 Principe
,因此请检查请求对象中是否有Principle
。
String username;
Principal principal = request.getUserPrincipal();
if (principal != null) {
username= principal.getName(); // Find User by j_username.
}
答案 3 :(得分:0)
我发现我的错误是在记录用户操作(注销操作)之前使会话无效,这就是HttpServletRequest-> getRemoteUser()返回null的原因。 感谢您的贡献。