Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Tomcat user in Java

Tags:

tomcat

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.

like image 835
wolfi Avatar asked Feb 11 '10 13:02

wolfi


People also ask

How do I get Tomcat user xml?

Tomcat configuration files are found in the directory: CATALINA_HOME/conf (where CATALINA_HOME environment variable is the Tomcat installation directory). The main configuration file is server. xml .

How do I find my Tomcat username and password?

After restarting Tomcat, you should be able to access the Manager app (http://localhost:8080/manager/html) using username = admin and password = admin.

What are the roles for users in Tomcat?

The available roles are: manager-gui — Access to the HTML interface. manager-status — Access to the "Server Status" page only. manager-script — Access to the tools-friendly plain text interface that is described in this document, and to the "Server Status" page.


1 Answers

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.

like image 149
Ricardo Marimon Avatar answered Oct 05 '22 12:10

Ricardo Marimon