Skip to main content
Mar 16, 2016 7:42 PM UTC
Solved

java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory

Hello,

i am trying to connect our Active Directory to retrieve some user Information. When trying to get an InitialLdapContext i get the following exception:

javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.jndi.ldap.LdapCtxFactory [Root exception is java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory]
 at com.day.commons.simplejndi.impl.ContextService$ICFactoryBuilder.createInitialContextFactory(ContextService.java:165)
 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:681)
 at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
 at javax.naming.InitialContext.init(InitialContext.java:242)
 at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:153)
 at com.company.cq.directory.LdapUtil.getInitialContext(LdapUtil.java:294)
 at com.company.cq.directory.LdapUtil.getAttribute(LdapUtil.java:263)
 at org.apache.jsp.apps.company.components.passwordteaser.passwordteaser_jsp._jspService(passwordteaser_jsp.java:263)
 at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)


.......

Caused by: java.lang.ClassNotFoundException: com.sun.jndi.ldap.LdapCtxFactory
 at org.apache.sling.commons.classloader.impl.ClassLoaderFacade.loadClass(ClassLoaderFacade.java:127)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:274)
 at com.day.commons.simplejndi.impl.ContextService$ICFactoryBuilder.createInitialContextFactory(ContextService.java:162)
 ... 85 more

 


The code Looks as follows:

private LdapContext getInitialContext() throws NamingException {
     
  Hashtable<String,String> env = new Hashtable<String,String>();
  env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
  env.put(Context.SECURITY_AUTHENTICATION, "simple");
  env.put(Context.SECURITY_PRINCIPAL, ADMIN_NAME);
  env.put(Context.SECURITY_CREDENTIALS, ADMIN_PASSWORD);
  env.put(Context.PROVIDER_URL, "ldap://" + HOST + ":" + PORT);

  return new InitialLdapContext(env, null);
 }

Has anyone an idea why the factory class cannot be found? I am using CQ5.5.


Btw, when i execute the same code outside of CQ5 on my Windows command line (CLASSPATH=.) the code works fine.

 


Best Regards

Jan

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
stevec2515680Accepted solution
Level 4
Mar 18, 2016 7:35 PM UTC

5 replies

Level 4
Mar 16, 2016 8:00 PM UTC

This looks related to the workaround that is documented when worknig with with web services.

https://helpx.adobe.com/experience-manager/using/creating-cxf-bundles-consume-web.html

Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl

at org.apache.sling.commons.classloader.impl.ClassLoaderFacade.loadClass(ClassLoaderFacade.java:127)
at java.lang.ClassLoader.loadClass(Unknown Source)
at javax.xml.ws.spi.FactoryFinder.safeLoadClass(Unknown Source)
... 107 more
Solution:
To fix this issue and ensure that you can create a bundle that consumes web services as described in this article, modify the sling.properties file located in the crx-quickstart\conf folder. Add the following line of code to this file: sling.bootdelegation.com.sun=com.sun.*. Then restart the server using the JCR file. Once you perform this task, you can follow along with this article.

Translate
Mar 17, 2016 6:23 AM UTC

Hello Steve,

 

thanks for your reply. I tried this, added the line "sling.bootdelegation.com.sun=com.sun.*" to the sling.properties file and restarted the CQ5.5 instance. The problem is still the same :-(.

Any other suggestions?

 

Best Regards

Jan

Translate
smacdonald2008
Level 10
Mar 17, 2016 12:57 PM UTC

We have an article that shows you how to successfully configure AEM to use ApacheDS (as an example) 

https://helpx.adobe.com/experience-manager/using/configuring-aem6-apache-directory-service.html

Have you tired following this article and configuring Apache Jackrabbit Oak LDAP Identity Provider in AEM? 

Translate
Mar 18, 2016 1:55 PM UTC

Hi,

 

thanks for your reply. Your article is for AEM 5.6 and newer versions of AEM and we are using CQ5.5 which has no Apache Oak.

 

Any other suggestions?

 

Best regards

Jan

Translate
stevec2515680Accepted solution
Level 4
Mar 18, 2016 7:35 PM UTC