Here I am going to show you how to create users in Tomcat server to manage applications, server status, etc. When you deploy application into Tomcat server, generally you put the war archive files under webapps folder of the Tomcat server.
You can easily access the application once it is successfully deployed through its context path of the application. The context path is generally the application name. If you want to change the context path of the application then you can change it in the conf/server.xml file.
Why do you need to create users?
You may want to manage your applications through GUI (Graphical User interface), then you need to create users. You can deploy, undeploy applications through GUI. To access GUI you need to have credentials for login and if you do not have credentials then you won’t be able to login to the management console.
You need to specify the username, password and roles for the users while creating.
Therefore, to access Server Status or Manager App or Host Manager, you need to have a user with proper role.
The error page you would see in absence of the user is shown below:
Create Users in Tomcat
Now when you create user, you need to open the file conf/tomcat-users.xml file. If you do not have proper role mapped to your username then you will see 401 status with Unauthorized access error.
For example, to add the manager-gui role to a user named roytuts with a password of roy, add the following to the config file (conf/tomcat-users.xml):
<user username="roytuts" password="roy" roles="manager-gui"/>
If you want to specify multiple roles then use comma separated value.
<user username="roytuts" password="roy" roles="admin, manager, manager-gui"/>
Once added the above values you need to restart the server. Now you can easily login with the username and password (roytuts/roy) and you will see a page similar to the below image:
Using the above page you can start/stop applications, you can undeploy applications, you can deploy applications. You can check server status from the link Server Status.
You can check Tomcat Manager Application by clicking on /manager link, but remember for this manager application you need to have admin-gui role. So, you can also specify this admin-gui role for a user.
Hope you got an idea how to create users in Tomcat server for managing applications through GUI.