Where to call getUserPrincipal(), or other methods to find out the logged on user
Posted on 2008-01-29
I have succesfully setup security (with Glassfish but that seems to be somewhat irrelevant to this question) for a Netbeans visual application.
Within my application I need to know the user name (for logging f.i.) and I found out that I can get it via request.getUserPrincipal(). However, I do not have access to a request within, either my sessionbean (which I can understand since it is something else) but also not in my jsp (and the related java classes).
The only place in code where exist a HTTPServletRequest is in the login_jsp.java but that seems to early (and I cannot access any sessionbean from there).
So the question is: How to put request.getUserPrincipal() into a sessionbean? Accessable via f.i. getSessionBean1().getUsername() throughout my application.