To provide access to your Tomcat website, you can implement your simple security restriction (e.g. in /var/lib/tomcat7/webapps/*/WEB-INF/web.xml ) as shown below (just add it before the end </web-app> ):
<login-config> <auth-method>BASIC</auth-method> <realm-name>Webapp</realm-name> </login-config> <security-constraint> <web-resource-collection> <web-resource-name>Admin</web-resource-name> <url-pattern>/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <auth-constraint> <role-name>*</role-name> </auth-constraint> <user-data-constraint> <transport-guarantee>NONE</transport-guarantee> </user-data-constraint> </security-constraint> <security-role> <role-name>*</role-name> </security-role>
The login-config element contains the auth-method element, which specifies the authentication method that is used, BASIC . The security-constraint element contains 3 elements: web-resource-collection , auth-constraint and user-data-constraint . The web resource collection lists parts of our application that require authentication. /* indicates that authentication is required for the entire application. The auth constraint defines the role that a user must have in order to access protected resources. The transport guarantee for user data restrictions can be NONE , CONFIDENTIAL or INTEGRAL . We set it to NONE , which means that redirection to SSL not required when you try to get into a protected resource.
Also make sure you have the line:
<Realm className="org.apache.catalina.realm.MemoryRealm" />
inside the conf/server.xml ( Engine ) section.
If you have not changed any configuration files, view the conf/tomcat-users.xml in your installation ( locate tomcat-users.xml ). This file must contain credentials that allow you to use Tomcat webapp.
For example, to add the gui manager role to a user named tomcat with the password s3cret , add the following to the configuration file above:
<role rolename="manager-gui"/> <user username="tomcat" password="s3cret" roles="manager-gui"/>
You can then access your webapps manager from /manager/html (e.g. rebooting after configuration changes).
Read more: App Manager HOW-TO .
Then restart Tomcat and, turning to your webapp, it will ask you to enter the correct credentials.
See also: