How to protect directories with a password in Tomcat? is there any .htaccess-like way to achieve this?

Daniele Galluccio

To password protect your pages you can use a Realm.
Please referer at the Tomcat Documentation for detailed info, like the Realm Configuration HOW-TO. Please always read the documentation.
However to give you starting point:
Once you've defined a realm resource(as the tomcat-users.xml or a your own jdbc realm) in server.xml, you have to modify the web.xml file of your application. Here's a sample for adding basic realm support (Form authentication is quite similar, look at docs)

	<!-- Define reference to the user database for looking up roles -->
		<description>Link to the UserDatabase instance from which
                    we request lists of defined role names.</description>

	<!-- Define a Security Constraint on this Application -->
			<web-resource-name>Entire Application</web-resource-name>

		<realm-name>Your Realm Name</realm-name>

		<description>The role that is required to log in to 
                    the Manager Application</description>
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact