wolfi
wolfi

Reputation: 91

Getting Tomcat user in Java

is there a way to get the logged in user name (and group) from a Tomcat system. I read something about configuring Tomcat, so it is getting the user information out of a database. But I found now information about getting the name of the user (in my GWT Project), which is logged in.

I'm trying to write a little GWT project and would like to publish the user name to the front page.

Thx for your help.

Upvotes: 7

Views: 10188

Answers (2)

Ricardo Marimon
Ricardo Marimon

Reputation: 10687

You can try these two methods from the HttpServletRequest interface.

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

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

Of course this only works if you are using tomcat realm authentication found here.

Upvotes: 9

DAB
DAB

Reputation: 1873

getUserPrincipal().getName()

There's a typo in above answer.

Upvotes: 0

Related Questions