问题
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