NoClassDefFoundError issue with a custom LDAP authenticator

Hello,

We are using XWiki 9.9 with the LDAP authenticator extension installed, version 9.2.5. We have defined our own authenticator [1] which extends org.xwiki.contrib.ldap.XWikiLDAPAuthServiceImpl and basically converts XWiki usernames to lowercase. In xwiki.cfg, when setting the parameter xwiki.authentication.authclass to its default value, everything works as expected. However, when setting the value to the custom authenticator class name, we get a NoClassDefFoundError exception as shown below. At the moment we have no idea on how to debug this. Any help would be greatly appreciated.

[1] https://gitlab.ow2.org/ow2/ldap-authenticator-lowercase-uid

Raised exception:

Caused by: java.lang.NoClassDefFoundError: org/xwiki/contrib/ldap/XWikiLDAPAuthServiceImpl at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at org.eclipse.jetty.webapp.WebAppClassLoader.foundClass(WebAppClassLoader.java:644) at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:550) at java.lang.ClassLoader.loadClass(ClassLoader.java:411) at java.lang.ClassLoader.loadClass(ClassLoader.java:411) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at com.xpn.xwiki.XWiki.getAuthService(XWiki.java:5077) at com.xpn.xwiki.XWiki.checkAuth(XWiki.java:3801)

Thank you,

Stéphane

According to the error your extension is in a lower classloader than the LDAP authenticator. The LDAP authenticator being installed on root namespace maybe it means you put your custom authenticator JAR in WEB-INF/lib (which means it does not have access to any classloader containing extensions classes).

If that’s the case you will need either move the LDAP authenticator to WEB-INF/lib or, better, install your custom authenticator as extension with the LDAP authenticator as dependency.

Thanks a lot Thomas, we will try to install the custom authenticator as an extension then.
PS: the JAR file was put in the WEB-INF/lib directory indeed.

A follow up on this issue was posted as another topic.

NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available at compile time. After you compile your code, you end up with .class files for each class in your program. These binary files are the bytecode that Java interprets to execute your program. The NoClassDefFoundError indicates that the classloader (in this case java.net.URLClassLoader), which is responsible for dynamically loading classes, cannot find the .class file for the class that you’re trying to use.

NoClassDefFoundError can occur for multiple reasons like

  • ClassNotFoundException – .class not found for that referenced class irrespective of whether it is available at compile time or not(i.e base/child class).
  • Class file located, but Exception raised while initializing static variables
  • Class file located, Exception raised while initializing static blocks