Pass data between applications in Tomcat server
<p>We have several applications deployed in Tomcat and want to add 1 application to handle authentication for all of the other applications.</p>

<p>All applications are defined as different host elements in Tomcat configuration (server.xml) like following example:</p>

<pre><code>&lt;Host name="loginapp.localhost" appBase="loginapp" /&gt;

&lt;Host name="webapp1.localhost" appBase="webapp1" /&gt;
&lt;Host name="webapp2.localhost" appBase="webapp2" /&gt;
...
</code></pre>

<p>What is a best practice to accomplish this?</p>

<p>How I see things are going to work and what I have tried so far:</p>

<p>When a user goes to an url that points to webapp1, a request filter in the application sees that the user has not been authenticated yet and redirects to the "loginapp" where authentication happens and redirects back to webapp1 where the user now has been authenticated for (only for this specific application).</p>

<p>What I need is to share data between these applications. And I've found it should be possible to share session attributes across applications like following (example I've found):</p>

<pre><code>request.getSession().setAttribute("sharedId", shared);
request.getRequestDispatcher("/URLofOtherServlet").forward(request, response);
</code></pre>

<p>But I'm not sure how I can achieve this as my applications are running inside the same Tomcat server, but are accessed by different domain names. Is this even possible this way? Or are there other options for my case?</p>

<hr>

<p>EDIT:</p>

<p>Apparently my "solution" above is only possible for use inside one application.</p>

<p>What I have found now while researching further is JNDI resources. Would this be something I can use to share some data between my applications?</p>