Wednesday, April 08, 2009

Add Authentication for your Tomcat Web Application (Using Tomcat Security Realms )

Here im going to note down small set of steps which are very esay and fster to do and create a login for your tomcat web application.
1. get root access and get into the tomcat folder.
2. Open conf/server.xml and uncomment the following line.

<Realm className="org.apache.catalina.realm.MemoryRealm" />
package com.infosys.hanumant.rome;

3. Open webapps/your_tomcat_application/WEB-INF/web.xml and add the following security constraint:


here you have to use the same "web-resource-name" and the "realm-name".

Open conf/tomcat-users.xml and add the following <user> sub-element:

<user name="anyUserName" password="anyPassword" roles="name_of_the_role_which_has_access">

remember that the role which we use here in this tomcat-users.xml and the one which we used in the step 3 should be same. And here we dont need to creat a role differently. Just adding the above line will be enough.

5. Now its time to restart tomcat server.


No comments: