Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Lately I've been working on implementing security for my web application, running on a Glassfish v3. I successfully managed to secure some resources by setting a basic authentication up like following:

<login-config>
<auth-method>BASIC</auth-method>
<realm-name>vcards-admin</realm-name>
</login-config>

Now I was wondering how to get the user name introduced on the login prompt to fecth the actual data of the user. I thought there could be a session attribute to get that piece of data, but I don't know which one it is.

Am I wrong about the session attribute? Is there any other way to access that login information?

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
305 views
Welcome To Ask or Share your Answers For Others

1 Answer

It's available by HttpServletRequest#getUserPrincipal() or its shorthand HttpServletRequest#getRemoteUser():

String name = request.getUserPrincipal().getName();
// Or
String name = request.getRemoteUser();

Equivalently in JSP EL:

${pageContext.request.userPrincipal.name}
<!-- or -->
${pageContext.request.remoteUser}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...