0

I have been cracking my head for the past 3 weeks on this issue and I try my best to explain it in simplest term since I don't have the source code.

  1. Platform

. Tomcat 7
. Window Server 2008
. JRE 7

  1. Using Tomcat JAAS realm

Defined in the web application META-INF/context.xml.

<Context>    
    <Realm className="org.apache.catalina.realm.JAASRealm" appName="ABC" userClassNames="com.abc.xyz" useContextClassLoader="true"/>
  1. Here's the difficult part since i don't have the source code.

I have WEB-INF/classes/a123 & b123 class files

. This class a123 uses logincontext
. The logincontext has some configuration defined
. This configuration file i believe is part of JAAS realm needs to access b123.

Problem. Class b123 is not found.

I believe this issue is that the Tomcat JAAS realm is on Tomcat Server and cannot find b123 since b123 is under the webappsclassloader.

So as you can see in my context.xml, I did set the useContextClassLoader="true" which I believe by default is webappsclassloader.

I tried putting the b123 in the Tomcat startup classpath which works then but now I believe I have 2 copies of b123.

. b123 under Tomcat server
. b123 under webappsclassloader

I think the issue here a class higher in the class loading hierarchy is trying to access the web apps class in the lower hierarchy. That would definitely fail based on the way class loading delegation work. So the only way i could think which works is to use the Thread context class loader.

As you can see on the context.xml i did set the useContextClassLoader to "true". But how do i set the context class loader through Tomcat configuration since i don't have access to the source code? I guess the context class loader needs to be set before the JAAS realm uses the context class loader.

Any help would be great!

yapkm01
  • 3,590
  • 7
  • 37
  • 62
  • Works for me, and without `useContextClassLoader`. I use the Tomcat lib directory but don't repeat the class in the webapp. – user207421 Jun 13 '16 at 01:58
  • @EJP which tomcat version you are using? – yapkm01 Jun 13 '16 at 02:35
  • 7.0.27. The key is to not repeat the classes in the webapp. – user207421 Jun 13 '16 at 02:39
  • @EJP i don't understand .. can you give explain to me in simplicity? Do you have a situation where example class in common classloader need to access web apps classes? Basically access child classes .. this of course will not work when comes to java class delegation model – yapkm01 Jun 13 '16 at 02:41
  • Everything the JAAS module needs should be in a JAR file in the Tomcat lib directory, and nowhere else. – user207421 Jun 13 '16 at 03:04

0 Answers0