Tomcat Security
Security Configurations for Tomcat Applications
A Tomcat application can be protected by requiring user authentication, blocking selected client IP addresses, or applying both methods together.
Security Options
Configure User Authentication
Open Tomcat configuration
In the platform dashboard, click Config beside the Tomcat application server.
Add a Tomcat user
Open /opt/tomcat/conf/tomcat-users.xml and add the required username, password, and role.
<user username="test" password="test" roles="admin">

Add the security constraint
Open /opt/tomcat/conf/web.xml and define the protected URL pattern, permitted roles, authentication method, and realm name.
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Test Realm</realm-name>
</login-config>

Save and restart Tomcat
Save both configuration files and restart the Tomcat application server.

Use strong credentials
Replace the example username and password with secure production values and assign only the roles required by the application.
Deny Client IP Addresses
Open the application context file
Click Config beside Tomcat and open /opt/tomcat/webapps/ROOT/META-INF/context.xml.
Add the IP deny rule
Add the Remote IP Valve and Remote Address Valve configuration, replacing {IP_address} with the client address to block.
<Context antiJARLocking="true" path="/">
<Valve className="org.apache.catalina.valves.RemoteIpValve" />
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
deny="{IP_address}" />
</Context>

Public IP exception
When a public IP is attached directly to the environment, the RemoteIpValve line can be omitted.
Save and restart Tomcat
Save context.xml and restart the Tomcat server.

Expected Result
The Tomcat application requires valid credentials, rejects selected client IP addresses, or applies both controls according to the configured security policy.
Important Notes
- Back up Tomcat configuration files before editing them.
- Restart Tomcat after saving the changes.
- Use strong passwords instead of the example credentials.
- Keep role names consistent between
tomcat-users.xmlandweb.xml. - Confirm whether traffic reaches Tomcat through a proxy or through a direct public IP before configuring RemoteIpValve.
- Test security rules from an allowed and a blocked client before production use.
