Getting Tomcat user in Java

There is a way to get the username (and group) registered on the Tomcat system. I read something about setting up Tomcat, so it gets user information from the database. But now I found information about getting the username (in my GWT project) that was logged in.

I am trying to write a small GWT project and want to publish the username on the first page.

Thanks for your help.

+6
tomcat
source share
2 answers

You can try these two methods from the HttpServletRequest interface.

getUserPrincipal() returns the Principal from which you can get the registration used as getUserPrincipal().getName() .

isUserInRole("Administrators") returns true if the current Principal is in the provided role.

Of course, this only works if you use the tomcat domain authentication found here .

+8
source share

getUserPrincipal (). getName ()

There is a typo in the answer above.

0
source share

All Articles