I have configured a form based log in in my JSF 2.0 Application on GlassFish 3 server, using a custom Realm. What is the simpliest way of getting information about a logged in user, i.e. the users name.
Is this possible? Or is the current session just associated with a security role? If so, is there some way of making this possible without changing the log in configuration?
Simply put, what I want is to display a simple message like:
Logged in as username
on my webpages.
The easiest way to get at the logged in user via EL (Expression Language) in JSF 2.0 would be:
#{request.remoteUser}
Tobbe's answer would work well to get at the remote user from within a backing bean.
The simple (maybe not the best) answer was:
FacesContext.getCurrentInstance().getExternalContext().getRemoteUser()
I'm shocked about how long it took me to figure that out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With