A Nair

+ Follow
since Aug 12, 2016
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by A Nair

Thank you for taking out time and explaining in such detail! This helped configure it at my end.

7 years ago

Thank you Tim for the information! This helps a lot.

Just one quick question on role in realm configuration. As per requirement only loginrole user should be able to login, so would stating the expected role as part of roleName property suffice, or do we have to explicitly write the code to check the role once authentication is done ?

<Realm   className="org.apache.catalina.realm.JNDIRealm"
7 years ago
Hi All,
 I have created a Login html page that authenticates the users based on role, for that I am configuring the users in Tomcat-user.xml. But now we need to authenticate the users using Active Directory and I am not sure how to configure this as I am new to tomcat/Apache. Does this configuration need to be done at Apache level or can it be done similar to the way we did for using tomcat-user.xml . We need to allow a specific group of users to access the page and not all.

Current configuration in code

     <web-resource-name>Login admin</web-resource-name>
 <role rolename="loginrole"/>
<user username="tomcat" password="tomcat" roles="loginrole"/>

<form method="POST" action="j_security_check">
   <div class="form-group"><input type="text" name="j_username" id="j_username" placeholder="Username" class="form-control resetval"></div>
   <div class="form-group"><input type="password" name="j_password" id="j_password" placeholder="Password" class="form-control resetval"></div>
   <input type="submit" value="Submit" class="btn btn-default">

Thanks for all the help in advance!

7 years ago
Thanks Paul. I will surely check the ServletContextListener option.

And you are right, on start up we just do the DB set up configuration. Whenever the actual service call happens only then do we create the actual connection and close it after the work is done.

So looks like I cannot keep the DB set up code common between web applications.
7 years ago
Thank you Tim and K.Tsang for your reply.

I believe I did not communicate my query well. This is what I have implemented so far

1. I have 3 servelt applications deployed independently in their own container.
2. Each servlet code connects to multiple DB for executing logic.
3. So in each application I have defined a DbConnectionServlet which loads all the required DB connection  (setupDataSources) for that servlet on load (loadOnStartup=1) . The init function of DB servlet looks up a config file to pull all the required JNDI for that application.
4. For actual execution I pass a parameter which helps decide which datasource connection is needed.

But the question is can this DbConnectionServlet be deployed as common code and then be referred to by other 3 servlet applications, if yes how ?. As I said I am not sure if this is right option or even if its possible.

Thanks in advance for all the help!
7 years ago
Hi All,

 I am new to Tomcat/Java, so please bear with my silly questions.

We have multiple independent servlet applications deployed on tomcat that calls DB for performing various operations. So I have put java code in place for loading the connections during start up inside each of the application
Referred to this - http://tomcat.apache.org/tomcat-4.1-doc/printer/jndi-datasource-examples-howto.html#MySQL%20DBCP%20Example

Now the requirement is to make the connection pooling piece as a Common DataSource Code and load all the required connections at one go. Then from each independent application call this code to get the existing connection from the pool.

Is this the right way to do it and how can we achieve it ?

7 years ago