How to get the name of the logged in user in JSF service in GlassFish
I have a JSF app on GlassFish. It's designed like so:
user.xhtml > UserHandler.java > UserService.java > UserDAO.java > database
I know that in the UserHandler, I can get the logged in user name using the FacesContext.
My question is, inside the UserService (which is decoupled from the JSF view) how can I get the name of the logged in user without using FacesContext?
I don't want to reference FacesContext from inside the service because it's possible in the future that the service will be accesses from 开发者_如何学Goa webservice or alternate view technology.
Alternately, I can pass in the name of the logged in user to each method in the Service, but I prefer not to do that either just because it seems a little kludgy.
Any suggestions are greatly appreciated! Rob
javax.servlet.http.HttpServletRequest#getRemoteUser
精彩评论