How to get username after login with FORM based authentication

社会主义新天地 提交于 2020-01-04 10:41:41

问题


I am following the link http://middlewaremagic.com/weblogic/?p=2034 to perform form based authentication. I have created a security realm then successfully delegate the authentication check to weblogic 10.3. Everything is fine, but I could not get username, HttpServletRequest->getRemoteUser() returns null.

Do you have an idea how to get username after login? I am going to use username in every Managed bean to log user operations.

EDIT: I have found my mistake that I invalidated the session before logging user operation (logout operation), that is why HttpServletRequest->getRemoteUser() returns null. Thanks for contribution.


回答1:


You can obtain it from SecurityContext as well :

SecurityContextHolder.getContext().getAuthentication().getPrincipal().getUserName();



回答2:


Try to get user principal from request and then get name from it. Like this:

Principal p = request.getUserPrincipal();
String username = p.getName();



回答3:


j_username is available in the Principe, so just check there is any Principle in the request object.

String username;
Principal principal = request.getUserPrincipal();
            if (principal != null) {
                username= principal.getName(); // Find User by j_username.
            }



回答4:


I have found my mistake that I invalidated the session before logging user operation (logout operation), that is why HttpServletRequest->getRemoteUser() returns null. Thanks for contribution.



来源:https://stackoverflow.com/questions/20369034/how-to-get-username-after-login-with-form-based-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!