[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ajug-members]: Tomcat: how to get username
Use request.getUserPrincipal().getName() - note that this is a part of
the HttpServletRequest API, and can be used in any servlet container
(Tomcat, Weblogic, Websphere, etc).
-Rob
Joseph Talafous wrote:
>I'm using the usual FORM based login configuration with my Tomcat Webapp, and it works fine. I can even logout by using a link to logout.jsp which contains:
>
>USER logged out of MY WEB APP at <%= new java.util.Date()%>
><% request.getSession(invalidate();%>
>
>This works OK, except I would like to replace USER with the username that was entered in the FORM based (j_username) input by Tomcat. How do I get at the username? session.getAttribute() and servletContext.getAttribute() do not appear to have such attributes as "username" set by Tomcat when the username is entered.
>
>I'm punting, but if anyone knows a simple solution to this, please let me know. I don't see a solution (after an afternoon of researching the net) and this might be a good feature for a future Tomcat release.
>
>Cheers,
>Joe
>
>FYI: In web.xml:
>
><!-- Define a security constraint on this application -->
><security-constraint>
> <web-resource-collection>
> <web-resource-name>Entire Application</web-resource-name>
> <url-pattern>/*</url-pattern>
> </web-resource-collection>
> <auth-constraint>
> <!-- This role is not in the default user directory -->
> <role-name>manager</role-name>
> </auth-constraint>
></security-constraint>
><!-- Define the login configuration for this application -->
><login-config>
> <auth-method>FORM</auth-method>
> <realm-name>MY WEB APP</realm-name>
></login-config>
><!-- Security roles referenced by this web application -->
><security-role>
> <description>
> The role that is required to log in to the Manager Application
> </description>
> <role-name>manager</role-name>
></security-role>
>
>
>
>
>____________________________________________________________
>Find what you are looking for with the Lycos Yellow Pages
>http://r.lycos.com/r/yp_emailfooter/http://yellowpages.lycos.com/default.asp?SRC=lycos10
>
>