Expand my Community achievements bar.

SOLVED

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

Avatar

Level 1

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

1 Accepted Solution

Avatar

Correct answer by
Level 4
5 Replies

Avatar

Level 4

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.

Avatar

Level 1

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

Avatar

Level 10

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? 

Avatar

Level 1

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

Avatar

Correct answer by
Level 4