I am using the Eclipse Virgo (3.6.1) OSGi container, which runs on Tomcat 7.0.31. I am attempting to implement a custom authentication realm according to the Tomcat documentation, but I am running into a ClassNotFoundException
when attempting to start up the server.
My realm implementation is very simple; it simply extends JDBCRealm
and overrides the authenticate
method. As per the documentation, I compiled this class into a jar, titled com.authentication.MyCustomRealm.jar
, and placed it in $SERVER_HOME/lib.
The configuration I added to tomcat-server.xml is as follows:
<Realm className="com.authentication.MyCustomRealm"
resourceName="Custom Realm"
driverName="{jdbc.driverClassName}"
dbConnectionName="{jdbc.username}"
dbConnectionPassword="{jdbc.password}"
dbConnectionURL="{jdbc.url}"
userTable="USER_DATA"
userNameCol="ID" />
</Realm>
Here is a partial stack trace:
org.xml.sax.SAXParseException: Error at (103, 40) : com.authentication.MyCustomRealm
at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2687)
at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2719)
at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1279)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1303)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2717)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1556)
at org.eclipse.gemini.web.tomcat.internal.OsgiAwareEmbeddedTomcat.configure(OsgiAwareEmbeddedTomcat.java:309)
... 42 common frames omitted com.authentication.MyCustomRealm
at org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.doLoadClass(ChainedClassLoader.java:181)
at org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.loadClass(ChainedClassLoader.java:164)
at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:144)
at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1276)
Caused by: java.lang.ClassNotFoundException: com.authentication.MyCustomRealm
at org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.doLoadClass(ChainedClassLoader.java:181)
at org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.loadClass(ChainedClassLoader.java:164)
at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:144)
at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1276)
... 55 common frames omitted
I am suspecting there is something special I need to do with my OSGi configuration in order for the class to be found, but I'm not sure exactly what that is.
From the stack trace, I discovered that the org.eclipse.gemini.web.tomcat
bundle was attempting to load my custom realm. My solution was to create a new fragment bundle that uses org.eclipse.gemini.web.tomcat
as a host. I placed my custom realm in this bundle, which resolved this exception.