Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

LDAP Serach Error - NotContextException

monikaa6
Level 3
Level 3

Hi All,

We are upgarding from CQ5.6.1 to AEM 6.2. In the earlier version we had a code that search the content of Ldap using javax.naming.directory* classes.

Like the way

DirContext ctx = new InitialDirContext(env); //Creating context NamingEnumeration<SearchResult> ldapResults = ctx.search(base.get(), filter, sc); //Calling search method with arguments, this line throws Exception

When we are running the same code in AEM 6.2, getting the error.

javax.naming.NotContextException: Not an instance of DirContext at javax.naming.directory.InitialDirContext.getURLOrDefaultInitDirCtx(InitialDirContext.java:111) at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:267)

Any one faced this issue? The only difference I know is that in Cq5.6.1, we used to do the LDAP configs at server level, in AEm 6.2 they are available in OSGI configs.

Note:- We are defaining the LDAP enviornment varaibles in the Java class as well where we are getting the exception

Thanks

Monika

1 Accepted Solution
Sham_HC
Correct answer by
Level 10
Level 10

Hi Monika,

Osgi is an JNDI implementation does not interact well with factory DirContext or LdapContext for casting it back. You can find couple of issue in web on this with various osgi providers. To over come this make use of enhanced LDAP API which replaces JNDI and the existing LDAP API like "schema aware" API with convenient ways to access any LDAP server.

 

Thanks,

View solution in original post

15 Replies
Sham_HC
Correct answer by
Level 10
Level 10

Hi Monika,

Osgi is an JNDI implementation does not interact well with factory DirContext or LdapContext for casting it back. You can find couple of issue in web on this with various osgi providers. To over come this make use of enhanced LDAP API which replaces JNDI and the existing LDAP API like "schema aware" API with convenient ways to access any LDAP server.

 

Thanks,

View solution in original post

Dineshkumar_L
Level 3
Level 3

Hi Sham, Monika,

I am trying to use LDAP API 2.0 in AEM 63 SP2 for our requirement. My maven build is getting succeed but bundle is not getting resolved after uploading it to felix console. Below highlighted packages are not getting resolved. Did you face similar issue?

org.apache.directory.api.ldap.model.exception -- Cannot be resolved

org.apache.directory.ldap.client.api -- Cannot be resolved

Thanks,

Dinesh Kumar L.

jons96862376
Level 2
Level 2

I have this same issue

org.apache.directory.ldap.client.api -- Cannot be resolved

did you ever get it solved?

I have read you can take any jar and wrap it to for use as a bundle but I really want this to be self contained.

Thanks

Dineshkumar_L
Level 3
Level 3

I have embedded the jar inside my bundle to solve this issue. I could not get through any other options.

Regards,

Dinesh kumar L.

jons96862376
Level 2
Level 2

Thanks for the quick reply!  I have made a couple of attempts at that, but I am also fairly new to maven. Can you let me know how you achieved this or point me in the direction of an online guide.

Thanks again.

Dineshkumar_L
Level 3
Level 3

Yeah, I could recollect it was not that easy. Even embed has introduced some other collision after installing it in OSGI container. So, I had to add some not conditions under the import package too along with embed jar list. Open your Core POM.xml and update it as highlighted below under <Embed-Dependency> and <Import-Package> sections.

1785421_pastedImage_0.png

Regards,

Dinesh kumar L.

jons96862376
Level 2
Level 2

That's great, thanks I got it to not error, now if I can just figure out why the connection statement is dying without throwing an exception... LOL

Seriously though, really appreciate the help!

nitinjl
Level 4
Level 4

Hi Jon, Dinesh,

Facing the same dependency issue you have faced. 

console.JPG

tried to resolve using below jar files but no luck.

dependency.JPG

Embed dependency as part of bundle and remove some from import, as suggested by Dinesh

embed.JPG

Can you please have a look and suggest whether I am using correct jar and version.

Using AEM 6.4 sp4 version.

I was able to resolve dependency issues after creating separate bundles, but when invoking the servlet getting "no class definition found issue for LdapConnectionConfig.

Thanks,

Dineshkumar_L
Level 3
Level 3

Hi Nitin,

Try adding the dependencies as listed in the below snaps:

In Main POM.xml:

1786864_pastedImage_0.png

In core - child POM.xml

1786868_pastedImage_1.png

With embed and import packages as mentioned in my previous post, it should solve your NoClassDef exception.

Regards,

Dinesh kumar L.

nitinjl
Level 4
Level 4

Thanks Dinesh, was able to resolve dependency issue.

Same dependencies are available in OAK Ldap Authentication Support bundle, but not sure why required dependencies are not picked of from there.

ldap-auth.JPG Any thoughts ?

iabhisheksinha1
Level 1
Level 1

Hi All,

I'm still stuck at this point and the below mentioned pom snap is not working for me.

To summarize, I can import jar/package in eclipse and compile but the osgi dependency is not resolved. 

AEM 6.4

nitinjl
Level 4
Level 4

Hey Abhishek,

Below changes are working for me (below are core-pom changes), same needs to be there in apps pom with version info.

<dependency>

<groupId>org.codehaus.jackson</groupId>

<artifactId>jackson-mapper-asl</artifactId>

</dependency>

<dependency>

<groupId>org.apache.directory.api</groupId>

<artifactId>api-all</artifactId>

</dependency>

<dependency>

<groupId>commons-lang</groupId>

<artifactId>commons-lang</artifactId>

</dependency>

<dependency>

<groupId>commons-pool</groupId>

<artifactId>commons-pool</artifactId>

</dependency>

<dependency>

<groupId>org.apache.mina</groupId>

<artifactId>mina-core</artifactId>

</dependency>

<dependency>

<groupId>antlr</groupId>

<artifactId>antlr</artifactId>

</dependency>

-------------------

<Embed-Dependency>api-all;commons-pool;commons-lang;mina-core;antlr;scope=compile|runtime</Embed-Dependency>

<Import-Package>

!org.dom4j.*, !org.xmlpull.v1, !sun.net.util,

javax.inject;version=0.0.0,*

</Import-Package>

Thanks,

Regards,

Nitin

rahull37081255
Level 1
Level 1

Hello Team,

I am facing same kind error  'javax.naming.NotContextException: Not an instance of DirContext' when trying to fetch users from group of LDAP in Java. I am deploying my code in AEM 6.4. Code is working when i am testing through main method in Local eclipse tool but when deploy on server using maven and test, it gives this kind of error. We are using DirContext.

Could you please assist me?

Thanks in  Advance,

Rahul

monikaa6
Level 3
Level 3

Hi Rahul,

We were never able to use DirContext starting from AEM 6.2 and moved to LDAP API. Here is some documentation around this.

LDAP API Downloads — Apache Directory.

And others mentioned above, added the new pom dependencies to utilize the LDAP API.

Hope that helps!!