Re: Retrieve User Role
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Ben, Ben Tomlinson wrote: > How do I retrieve information about the user that > is actually logged in? Mainly I want the user role or the user name > but I can't seem to get it from the session. As Alan points out, you can get the UserPrincipal (or just the name) from the request. Unfortunately, you cannot get the list of roles for the user from that object. The best you can do using the servlet API is to ask the request if the currently-logged-in user is in a specific role (you have to know what role you want to ask for up front). I've always maintained a separate "user" object in the session that contains information like this, so you can consult it to, say, determine the complete list of roles a particular user has without having to check each one individually. Hope that helps, - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAklvUHMACgkQ9CaO5/Lv0PDtcgCffRSeKwQOLN3dQKPaJ6lN2arX EaUAnjg1T98W5VAv8u4EVvHJoB5176Qz =OUWm -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Retrieve User Role
Perfect. Thanks. On Thu, Jan 8, 2009 at 5:40 PM, Alan Chaney wrote: > Hi Ben > > You can get it from the request. In JSP you can access the request implict > object to get the value of the HttpServletRequest#getRemoteUser() method ... > > "Returns the login of the user making this request, if the user has been > authenticated, or null if the user has not been authenticated." > > (quote from j2ee docs for HttpServletRequest) > > The exact syntax to use depends upon whether or not you are using EL. > If you are using tags.. > <% String username = request.getRemoteUser() %> > > and in EL you can use the 'pageContext'. Try: > > ${pageContext.request.remoteUser} /// I think... you may need to check. > > and use as you see fit... > > Alan > > > Ben Tomlinson wrote: >> >> I have set up login security for some of the pages in my website. I >> have a JDBCRealm setup and working correctly. But now I want to >> change the layout of my pages (all jsp pages) according to the user >> that is logged in. How do I retrieve information about the user that >> is actually logged in? Mainly I want the user role or the user name >> but I can't seem to get it from the session. Any help would be >> appreciated. >> >> Ben >> >> - >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> For additional commands, e-mail: users-h...@tomcat.apache.org >> >> >> >> !DSPAM:49667e4a164556657853550! >> > > - > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > > - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Retrieve User Role
Hi Ben You can get it from the request. In JSP you can access the request implict object to get the value of the HttpServletRequest#getRemoteUser() method ... "Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated." (quote from j2ee docs for HttpServletRequest) The exact syntax to use depends upon whether or not you are using EL. If you are using tags.. <% String username = request.getRemoteUser() %> and in EL you can use the 'pageContext'. Try: ${pageContext.request.remoteUser} /// I think... you may need to check. and use as you see fit... Alan Ben Tomlinson wrote: I have set up login security for some of the pages in my website. I have a JDBCRealm setup and working correctly. But now I want to change the layout of my pages (all jsp pages) according to the user that is logged in. How do I retrieve information about the user that is actually logged in? Mainly I want the user role or the user name but I can't seem to get it from the session. Any help would be appreciated. Ben - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org !DSPAM:49667e4a164556657853550! - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Retrieve User Role
I have set up login security for some of the pages in my website. I have a JDBCRealm setup and working correctly. But now I want to change the layout of my pages (all jsp pages) according to the user that is logged in. How do I retrieve information about the user that is actually logged in? Mainly I want the user role or the user name but I can't seem to get it from the session. Any help would be appreciated. Ben - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org