You are viewing a plain text version of this content. The canonical link for it is here.
Posted to api@directory.apache.org by "Harris, Christopher P" <ch...@baxter.com> on 2015/02/02 21:28:01 UTC

RE: Proper use of LdapConnectionPool

Hi, Emmanuel.

Do you have any updates on this issue?

I really want to use the LDAP API, but this is a showstopper for me that leaves me with 2 choices:
1.) Use another API.  I'd rather not but will do it if I have no other option.
2.) If you have no one to test against AD, then I'll attempt to fix the problem myself and provide a patch.  However, I need pointers on which .java files I should concentrate.

 - Chris


-----Original Message-----
From: Harris, Christopher P 
Sent: Wednesday, January 28, 2015 2:03 AM
To: 'api@directory.apache.org'
Subject: RE: Proper use of LdapConnectionPool

Hi, Emmanuel.

Yes, the following code does not return an Entry.  Nothing is printed to my console when I use OBJECT.  As soon as I change it to SUBTREE, 1 Entry is printed to my console.

I'm observing comparable behavior in Apache Directory Studio.

public Person searchLdapUsingHybridApproach(String query) {
		SearchCursor cursor = new SearchCursorImpl(null, 30000, TimeUnit.SECONDS);
        LdapConnection connection = new LdapNetworkConnection(host, port);
        Entry entry = null;
        Person p = null;
        try {
            connection.bind(dn, pwd);
            
            SearchRequest sr = new SearchRequestImpl();
            sr.setBase(new Dn(searchBase));
            StringBuilder sb = new StringBuilder(query);
            sr.setFilter(sb.toString());
            sr.setScope( SearchScope.OBJECT );
            cursor = connection.search(sr);
            Response response;

            while (cursor.next() && cursor.isEntry()) {
                response = cursor.get();
                System.out.println(((SearchResultEntry)response).getEntry());
                entry = cursor.getEntry();
                EntryMapper<Person> em = Person.getEntryMapper();
	            p = em.map(entry);
            }
        } catch (LdapException ex) {
            Logger.getLogger(LdapClient.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CursorException ex) {
            Logger.getLogger(LdapClient.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            cursor.close();
            try {
                connection.close();
            } catch (IOException ex) {
                Logger.getLogger(LdapClient.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        return p;
    }

 - Chris

-----Original Message-----
From: Emmanuel Lécharny [mailto:elecharny@gmail.com] 
Sent: Tuesday, January 27, 2015 6:49 PM
To: api@directory.apache.org
Subject: Re: Proper use of LdapConnectionPool

Le 28/01/15 01:27, Harris, Christopher P a écrit :
> O.K.  I think I remember why I stopped looking at the SearchScope.  If I just change the scope to either ONELEVEL or OBJECT, the cursor comes back empty.
ONE_LEVEL applied on a terminal entry will return nothing. With OBJECT, if the entry exists, it should work.

If you can test the simplest possible code that grab an entry with OBJECT scope, and if it does not work, then it may be a bug, but then, I'd like to know about.

The information transmitted is intended only for the person(s) or entity to which it is addressed and may contain confidential and/or legally privileged material. Delivery of this message to any person other than the intended recipient(s) is not intended in any way to waive privilege or confidentiality. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by entities other than the intended recipient is prohibited. If you receive this in error, please contact the sender and delete the material from any computer.

For Translation:

http://www.baxter.com/email_disclaimer

RE: Proper use of LdapConnectionPool

Posted by "Harris, Christopher P" <ch...@baxter.com>.
Emmanuel,

I agree with you.

 - Chris


-----Original Message-----
From: Emmanuel Lécharny [mailto:elecharny@gmail.com] 
Sent: Monday, February 02, 2015 9:35 PM
To: api@directory.apache.org
Subject: Re: Proper use of LdapConnectionPool

Le 02/02/15 23:56, Harris, Christopher P a écrit :
> givenName is present in AD.  That maps to our employees' first names.
>
> I just checked the Person mapping again.  All the attributes defined in my Person object are populated when I inspect the person instance in the debugger.

My test was done with a server that obviously does not contain everything you expected to get, thus the NPE. What I was just saying is that the basic search works (ie, whetever scope I'm using, I'm receiving all the entries), and if there is a pb, it's not the API which is the cause of it.


The information transmitted is intended only for the person(s) or entity to which it is addressed and may contain confidential and/or legally privileged material. Delivery of this message to any person other than the intended recipient(s) is not intended in any way to waive privilege or confidentiality. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by entities other than the intended recipient is prohibited. If you receive this in error, please contact the sender and delete the material from any computer.

For Translation:

http://www.baxter.com/email_disclaimer

Re: Proper use of LdapConnectionPool

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 02/02/15 23:56, Harris, Christopher P a écrit :
> givenName is present in AD.  That maps to our employees' first names.
>
> I just checked the Person mapping again.  All the attributes defined in my Person object are populated when I inspect the person instance in the debugger.

My test was done with a server that obviously does not contain
everything you expected to get, thus the NPE. What I was just saying is
that the basic search works (ie, whetever scope I'm using, I'm receiving
all the entries), and if there is a pb, it's not the API which is the
cause of it.



RE: Proper use of LdapConnectionPool

Posted by "Harris, Christopher P" <ch...@baxter.com>.
givenName is present in AD.  That maps to our employees' first names.

I just checked the Person mapping again.  All the attributes defined in my Person object are populated when I inspect the person instance in the debugger.

 - Chris

-----Original Message-----
From: Harris, Christopher P 
Sent: Monday, February 02, 2015 4:33 PM
To: api@directory.apache.org
Subject: RE: Proper use of LdapConnectionPool

O.K.  I can try that.

However, this issue is reproducible in Apache Directory Studio for me.

 - Chris

-----Original Message-----
From: Emmanuel Lécharny [mailto:elecharny@gmail.com] 
Sent: Monday, February 02, 2015 4:22 PM
To: api@directory.apache.org
Subject: Re: Proper use of LdapConnectionPool

Le 02/02/15 21:28, Harris, Christopher P a écrit :
> Hi, Emmanuel.
>
> Do you have any updates on this issue?

Sorry, was busy the last few days...

Here are my findings :

Basically, it works. I have used a slightly different version of the code :

    public void searchLdapUsingHybridApproach()
    {
        SearchCursor cursor = new SearchCursorImpl( null, 30000, TimeUnit.SECONDS );
        Entry entry = null;

        try
        {
            SearchRequest sr = new SearchRequestImpl();
            sr.setBase( new Dn( "ou=system" ) );
            sr.setFilter( "(ObjectClass=*)" );
            sr.setScope( SearchScope.SUBTREE );
            cursor = connection.search( sr );
            Response response;

            while ( cursor.next() && cursor.isEntry() )
            {
                response = cursor.get();
                System.out.println( ( ( SearchResultEntry ) response
).getEntry() );
                entry = cursor.getEntry();
            }
        }
        catch ( LdapException ex )
        {
            ex.printStackTrace();
        }
        catch ( CursorException ex )
        {
            ex.printStackTrace();
        }
        finally
        {
            cursor.close();
            try
            {
                connection.close();
            }
            catch ( IOException ex )
            {
                ex.printStackTrace();
            }
        }
    }

just to check that ther API returns the correct entries in the various cases (OBJECT, ONELEVEL and SUBTREE). It does.

So now, here is my hypothesys : there is a bug in the EntryMapper.

When I run the code using the EntryMapper, I get a NPE because the EntryMapper tries to do that :

                public Person map( Entry entry ) throws LdapException
                {
                    try
                    {
                        return new Person.Builder()
                            .setDistinguishedName( entry.getDn().getName() )
                            .setFirstName( entry.get( "givenName"
).getString() )   <---- NPE here because I have no givenName in the
entry I'm reading
                            .setLastName( entry.get( "sn" ).getString() )
                            .setTitle( entry.get( "title" ).getString() )
                            .setDepartment( entry.get( "department"
).getString() )
                            .setDivision( entry.get( "extensionAttribute14" ).getString() )
                            .setCity( entry.get( "l" ).getString() )
                            .setCountry( entry.get( "co" ).getString() )
                            .setEmail( ( entry.get( "mail" ) != null ) ?
entry.get( "mail" ).getString() : "" )
                            .setDeskLocation( entry.get( "postOfficeBox"
).getString() )
                            .setOfficePhone(
                                ( entry.get( "telephoneNumber" ) != null
) ? entry.get( "telephoneNumber" ).getString()
                                    : "" )
                            .setDirectReports( entry.get( "directreports" ) )
                            .build();

So my guess is that in your case your entry is missing some of the expected attribute, and this is why you get no result.

Can you chack that by printing the entry just hafter having pulled it from the LDAP server ?

Thanks !


The information transmitted is intended only for the person(s) or entity to which it is addressed and may contain confidential and/or legally privileged material. Delivery of this message to any person other than the intended recipient(s) is not intended in any way to waive privilege or confidentiality. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by entities other than the intended recipient is prohibited. If you receive this in error, please contact the sender and delete the material from any computer.

For Translation:

http://www.baxter.com/email_disclaimer
The information transmitted is intended only for the person(s) or entity to which it is addressed and may contain confidential and/or legally privileged material. Delivery of this message to any person other than the intended recipient(s) is not intended in any way to waive privilege or confidentiality. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by entities other than the intended recipient is prohibited. If you receive this in error, please contact the sender and delete the material from any computer.

For Translation:

http://www.baxter.com/email_disclaimer

RE: Proper use of LdapConnectionPool

Posted by "Harris, Christopher P" <ch...@baxter.com>.
O.K.  I can try that.

However, this issue is reproducible in Apache Directory Studio for me.

 - Chris

-----Original Message-----
From: Emmanuel Lécharny [mailto:elecharny@gmail.com] 
Sent: Monday, February 02, 2015 4:22 PM
To: api@directory.apache.org
Subject: Re: Proper use of LdapConnectionPool

Le 02/02/15 21:28, Harris, Christopher P a écrit :
> Hi, Emmanuel.
>
> Do you have any updates on this issue?

Sorry, was busy the last few days...

Here are my findings :

Basically, it works. I have used a slightly different version of the code :

    public void searchLdapUsingHybridApproach()
    {
        SearchCursor cursor = new SearchCursorImpl( null, 30000, TimeUnit.SECONDS );
        Entry entry = null;

        try
        {
            SearchRequest sr = new SearchRequestImpl();
            sr.setBase( new Dn( "ou=system" ) );
            sr.setFilter( "(ObjectClass=*)" );
            sr.setScope( SearchScope.SUBTREE );
            cursor = connection.search( sr );
            Response response;

            while ( cursor.next() && cursor.isEntry() )
            {
                response = cursor.get();
                System.out.println( ( ( SearchResultEntry ) response
).getEntry() );
                entry = cursor.getEntry();
            }
        }
        catch ( LdapException ex )
        {
            ex.printStackTrace();
        }
        catch ( CursorException ex )
        {
            ex.printStackTrace();
        }
        finally
        {
            cursor.close();
            try
            {
                connection.close();
            }
            catch ( IOException ex )
            {
                ex.printStackTrace();
            }
        }
    }

just to check that ther API returns the correct entries in the various cases (OBJECT, ONELEVEL and SUBTREE). It does.

So now, here is my hypothesys : there is a bug in the EntryMapper.

When I run the code using the EntryMapper, I get a NPE because the EntryMapper tries to do that :

                public Person map( Entry entry ) throws LdapException
                {
                    try
                    {
                        return new Person.Builder()
                            .setDistinguishedName( entry.getDn().getName() )
                            .setFirstName( entry.get( "givenName"
).getString() )   <---- NPE here because I have no givenName in the
entry I'm reading
                            .setLastName( entry.get( "sn" ).getString() )
                            .setTitle( entry.get( "title" ).getString() )
                            .setDepartment( entry.get( "department"
).getString() )
                            .setDivision( entry.get( "extensionAttribute14" ).getString() )
                            .setCity( entry.get( "l" ).getString() )
                            .setCountry( entry.get( "co" ).getString() )
                            .setEmail( ( entry.get( "mail" ) != null ) ?
entry.get( "mail" ).getString() : "" )
                            .setDeskLocation( entry.get( "postOfficeBox"
).getString() )
                            .setOfficePhone(
                                ( entry.get( "telephoneNumber" ) != null
) ? entry.get( "telephoneNumber" ).getString()
                                    : "" )
                            .setDirectReports( entry.get( "directreports" ) )
                            .build();

So my guess is that in your case your entry is missing some of the expected attribute, and this is why you get no result.

Can you chack that by printing the entry just hafter having pulled it from the LDAP server ?

Thanks !


The information transmitted is intended only for the person(s) or entity to which it is addressed and may contain confidential and/or legally privileged material. Delivery of this message to any person other than the intended recipient(s) is not intended in any way to waive privilege or confidentiality. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by entities other than the intended recipient is prohibited. If you receive this in error, please contact the sender and delete the material from any computer.

For Translation:

http://www.baxter.com/email_disclaimer

Re: Proper use of LdapConnectionPool

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 02/02/15 21:28, Harris, Christopher P a écrit :
> Hi, Emmanuel.
>
> Do you have any updates on this issue?

Sorry, was busy the last few days...

Here are my findings :

Basically, it works. I have used a slightly different version of the code :

    public void searchLdapUsingHybridApproach()
    {
        SearchCursor cursor = new SearchCursorImpl( null, 30000,
TimeUnit.SECONDS );
        Entry entry = null;

        try
        {
            SearchRequest sr = new SearchRequestImpl();
            sr.setBase( new Dn( "ou=system" ) );
            sr.setFilter( "(ObjectClass=*)" );
            sr.setScope( SearchScope.SUBTREE );
            cursor = connection.search( sr );
            Response response;

            while ( cursor.next() && cursor.isEntry() )
            {
                response = cursor.get();
                System.out.println( ( ( SearchResultEntry ) response
).getEntry() );
                entry = cursor.getEntry();
            }
        }
        catch ( LdapException ex )
        {
            ex.printStackTrace();
        }
        catch ( CursorException ex )
        {
            ex.printStackTrace();
        }
        finally
        {
            cursor.close();
            try
            {
                connection.close();
            }
            catch ( IOException ex )
            {
                ex.printStackTrace();
            }
        }
    }

just to check that ther API returns the correct entries in the various
cases (OBJECT, ONELEVEL and SUBTREE). It does.

So now, here is my hypothesys : there is a bug in the EntryMapper.

When I run the code using the EntryMapper, I get a NPE because the
EntryMapper tries to do that :

                public Person map( Entry entry ) throws LdapException
                {
                    try
                    {
                        return new Person.Builder()
                            .setDistinguishedName( entry.getDn().getName() )
                            .setFirstName( entry.get( "givenName"
).getString() )   <---- NPE here because I have no givenName in the
entry I'm reading
                            .setLastName( entry.get( "sn" ).getString() )
                            .setTitle( entry.get( "title" ).getString() )
                            .setDepartment( entry.get( "department"
).getString() )
                            .setDivision( entry.get(
"extensionAttribute14" ).getString() )
                            .setCity( entry.get( "l" ).getString() )
                            .setCountry( entry.get( "co" ).getString() )
                            .setEmail( ( entry.get( "mail" ) != null ) ?
entry.get( "mail" ).getString() : "" )
                            .setDeskLocation( entry.get( "postOfficeBox"
).getString() )
                            .setOfficePhone(
                                ( entry.get( "telephoneNumber" ) != null
) ? entry.get( "telephoneNumber" ).getString()
                                    : "" )
                            .setDirectReports( entry.get(
"directreports" ) )
                            .build();

So my guess is that in your case your entry is missing some of the
expected attribute, and this is why you get no result.

Can you chack that by printing the entry just hafter having pulled it
from the LDAP server ?

Thanks !