Re: LdapConnection.search() Help

2018-03-07 Thread Emmanuel Lécharny


Le 07/03/2018 à 16:35, George S. a écrit :
> Using 1.0.0 If I run this code:
> 
> EntryCursor cursor=lc.search(base,"(objectclass=*)",SearchScope.ONELEVEL);
> for  (Entry entry : cursor){
>   entries.add(entry);
> } I get this exception. It may be related to referrals. The reason I
> tried this library is because the Novell one was having big problems
> with referrals.


Indeed !

The way the LDAP API will handle referral is by throwing exceptions
(LdapReferralException), so you have to catch it in the loop. The
problem being that if you use a 'for' to loop on the entries, this
exception will be swallowed and you will get a RuntimeException instead.

That is clearly and area we can improve.

In the mean time, using the next()/get() methods, and catching the
LdapReferralException on a get(), that should work.

-- 
Emmanuel Lecharny

Symas.com
directory.apache.org



Fwd: Re: LdapConnection.search() Help

2018-03-07 Thread Emmanuel Lécharny
Transfering the mail to the list, I wrongly replied to George directly...


 Message transféré 
Delivered-To: elecha...@gmail.com
Received: by 10.74.89.138 with SMTP id k10csp5256341ood;Wed, 7
Mar 2018 07:34:15 -0800 (PST)
X-Google-Smtp-Source:
AG47ELuBKBRbZd39urfnGs0cFwHBOKH1PpuyzbwKkgWnrd7ILew2InXuQsW0i2Kko5myIGHyrbZC
X-Received: by 10.36.98.195 with SMTP id
d186mr23436935itc.88.1520436855183;Wed, 07 Mar 2018 07:34:15
-0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1520436855; cv=none;d=google.com;
s=arc-20160816;
b=SJkpAosxfiHg6uhlkNqd2WORu4QCmQySwSCNW9ubEDNx6h20632OB294WbTfNQTcQV
9/xg4Lw7U0oGA8knGvcrPpozdcQ+VDgAZXebGwbQRURa/s6tU7D1Y8nQdJesCs5vDERh

HoZd0haeYIEGYLALToVSoSlJi26d/lNg0jIg0tUuQinp0KK+n44H6UJkhwQKFGuo3sKH
WYm6ro+mvQKOq1L8DxToPVxxPl8B5j9ia7801YYqOXV+Ybkewt+nSmJyBuW+9pqizSN1

y+ZZhk0dLPgoB/unUqfvZirULfICPsEEBo+KFA4ja3ylPiLz4qx5pyRKU6PhkLL+5A5v
m5wg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=google.com; s=arc-20160816;
h=content-language:in-reply-to:mime-version:user-agent:date
:message-id:from:references:to:subject:arc-authentication-results;
 bh=gaN9v+1ST2YnYxFchkHEnlO3FZ4i5oOFtNJlB2rL0GQ=;
b=H014lBolj+v7V2/UKGUhLI/THfpI2b7xyq08vdzt5N6wtC7JHHK5zOWm8pl1PQYZ6R
6eC5Nz3RD9wgMWm6xuyP7FsK6VVj2jVA7fJaKneoyJjYsjeO0BAuTLJR6kMPm45dKp2t

tT5bWJCGz0dI1NvPBROd4V1+SH+R6Ia2cvYk3OIgLY5aL6HbKS475jzR4DWVeUDKBoYy
ovXr1O9WEYk2ws5nGgGuuu26upBMXSr1FctPp2IscsJiBLp7Kw3bvAlMWetLuo6Sos3H

oQWdcQN1MOleVf2BlI8s9q+g1AlHqXjAxMOzDkzDNw8REA3wKMjSnfOmgnRPgltzwaDX
j7+A==
ARC-Authentication-Results: i=1; mx.google.com;   spf=pass
(google.com: domain of geor...@mhsoftware.com designates 204.144.128.66
as permitted sender) smtp.mailfrom=geor...@mhsoftware.com
Return-Path: 
Received: from mail.mhsoftware.com (mail.mhsoftware.com.
[204.144.128.66])by mx.google.com with ESMTPS id
x132si5364717iod.40.2018.03.07.07.34.14for 
   (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
   Wed, 07 Mar 2018 07:34:15 -0800 (PST)
Received-SPF: pass (google.com: domain of geor...@mhsoftware.com
designates 204.144.128.66 as permitted sender) client-ip=204.144.128.66;
Authentication-Results: mx.google.com;   spf=pass (google.com:
domain of geor...@mhsoftware.com designates 204.144.128.66 as permitted
sender) smtp.mailfrom=geor...@mhsoftware.com
Received: from localhost (localhost [127.0.0.1]) by mail.mhsoftware.com
(Postfix) with ESMTP id 1B02430091D for ; Wed,  7
Mar 2018 08:34:14 -0700 (MST)
X-Virus-Scanned: amavisd-new at mhsoftware.com
Received: from mail.mhsoftware.com ([127.0.0.1]) by localhost
(mail.mhsoftware.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
id Stw0M0HWx-Q3 for ; Wed,  7 Mar 2018 08:34:10
-0700 (MST)
Received: from [192.168.1.120] (c-67-190-58-109.hsd1.co.comcast.net
[67.190.58.109]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256
(128/128 bits)) (Client did not present a certificate) by
mail.mhsoftware.com (Postfix) with ESMTPSA id 8952330091C for
; Wed,  7 Mar 2018 08:34:10 -0700 (MST)
Subject: Re: LdapConnection.search() Help
To: Emmanuel Lécharny 
References: 
<452c958c-1182-62fa-5ea5-716725808...@gmail.com>



<56806966-dffc-711a-4db0-d04dcfd72...@mhsoftware.com>
<523805e1-eefb-06ab-da26-722e7b2fe...@gmail.com>
From: George S. 
Message-ID: <8da5b63e-949d-9b9a-e6d9-251ade97a...@mhsoftware.com>
Date: Wed, 7 Mar 2018 08:33:50 -0700
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101
Thunderbird/52.6.0
MIME-Version: 1.0
In-Reply-To: <523805e1-eefb-06ab-da26-722e7b2fe...@gmail.com>
Content-Type: multipart/alternative;
boundary="26CF65067D378379E4A0FED9"
Content-Language: en-US

Using 1.0.0 If I run this code:

EntryCursor cursor=lc.search(base,"(objectclass=*)",SearchScope.ONELEVEL);
for  (Entry entry : cursor){
   entries.add(entry);
} I get this exception:

Exception in thread "main" java.lang.RuntimeException:
ERR_02002_FAILURE_ON_UNDERLYING_CURSOR Failure on underlying Cursor.
 at
org.apache.directory.api.ldap.model.cursor.CursorIterator.next(CursorIterator.java:89)
 at
com.mhsoftware.ldap.BoundConnection.search(BoundConnection.java:360)
 at
com.mhsoftware.ldap.LDAPConnectionFactory.main(LDAPConnectionFactory.java:265)
Caused by:
org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException
 at
org.apache.directory.ldap.client.api.EntryCursorImpl.get(EntryCursorImpl.java:174)
\   ldaat
org.apache.directory.ldap.client.api.EntryCursorImpl.get(EntryCursorImpl.java:52)
 at
org.apache.directory.api.ldap.model.cursor.CursorIterator.next(CursorIterator.java:82)
 ... 2 more

If I run this code, it works.


SearchRequest sr = new SearchRequestImpl();
sr.setBase(new Dn(base));
sr.setTimeLimit(Integer.MAX_VALUE);
sr.setFilter("(objectclass=*)");
sr.addAttributes(attributeNames);
sr.setScope(SearchScope.ONELEVEL);
sr.setDeref

Re: LdapConnection.search() Help

2018-03-07 Thread George S.

Using 1.0.0 If I run this code:

EntryCursor cursor=lc.search(base,"(objectclass=*)",SearchScope.ONELEVEL);
for  (Entry entry : cursor){
  entries.add(entry);
} I get this exception. It may be related to referrals. The reason I 
tried this library is because the Novell one was having big problems 
with referrals.


Exception in thread "main" java.lang.RuntimeException: 
ERR_02002_FAILURE_ON_UNDERLYING_CURSOR Failure on underlying Cursor.
at 
org.apache.directory.api.ldap.model.cursor.CursorIterator.next(CursorIterator.java:89)
at com.mhsoftware.ldap.BoundConnection.search(BoundConnection.java:360)
at 
com.mhsoftware.ldap.LDAPConnectionFactory.main(LDAPConnectionFactory.java:265)
Caused by: 
org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException
at 
org.apache.directory.ldap.client.api.EntryCursorImpl.get(EntryCursorImpl.java:174)
\   ldaat 
org.apache.directory.ldap.client.api.EntryCursorImpl.get(EntryCursorImpl.java:52)
at 
org.apache.directory.api.ldap.model.cursor.CursorIterator.next(CursorIterator.java:82)
... 2 more

If I run this code, it works.

 


SearchRequest sr = new SearchRequestImpl();
sr.setBase(new Dn(base));
sr.setTimeLimit(Integer.MAX_VALUE);
sr.setFilter("(objectclass=*)");
sr.addAttributes(attributeNames);
sr.setScope(SearchScope.ONELEVEL);
sr.setDerefAliases(AliasDerefMode.DEREF_ALWAYS);

SearchCursor cursor = lc.search(sr);


for (Response response: cursor) {
if (response instanceof SearchResultEntry) {
Entry resultEntry = ((SearchResultEntry)response).getEntry();
entries.add(resultEntry);
}
}


On 3/7/2018 8:18 AM, Emmanuel Lécharny wrote:

So I have it working fine with this code :

 EntryCursor cursor = connection.search( "ou=system",
"(objectclass=*)",
 SearchScope.ONELEVEL,
 "*", "+" );
 int count = 0;

 for ( Entry entry : cursor )
 {
 assertNotNull( entry );
 count++;
 }

 SearchResultDone done = cursor.getSearchResultDone();

As you can see, I also use an iterator, I don't user a SearchRequest,
and I get 5 entries back (count == 5 at the end).

EntryCursorImpl is Iterable, and uses a CursorIterator to handle
iteration, which move forward immediately when created, so that the
first get() works (available() will succeed).

AFAICT, it works properly.

The only annoying problem is that a cursor is never going to give you a
result if you don't move forward beforehand : its position is always
*before* the first element. It may sound weird, but it's because we need
to be able to move forward and backward properly.


Le 07/03/2018 à 01:53, George S. a écrit :

It's definitely a problem.


On 3/6/2018 5:03 PM, George S. wrote:

I looked at
LdapNetworkConnection.search(String,String,SearchScope,String...) and
it's a wrapper around a call to search using a SearchRequest, and
constructing a EntryCursorImpl from the SearchCursor.

There seems to be something wrong in EntryCursorImpl. If I change my
code to use a SearchRequest, then I get results in a SearchCursor and
I can iterate over them.

Looking at the code, EntryCursorImpl implicitly calls
searchCursor.available(), which is returning false because it appears
response is not set until a call to next(). See SearchResultImpl line
117 or so.



public  Collectionsearch(String  base,String...
attributeNames)throws  LdapException{

     if  (attributeNames.length ==0){
     attributeNames =new  String[]{
"distinguishedName","objectClass","name",
prop.getProperty("emailAddress","mail")};
     }
     Collection entries =new  ArrayList<>();
     SearchRequest sr=new  SearchRequestImpl();
     sr.setBase(new  Dn(base));
     sr.setTimeLimit(Integer.MAX_VALUE);
     sr.setFilter("(objectclass=*)");
     sr.addAttributes(attributeNames);
     sr.setScope(SearchScope.ONELEVEL);
     sr.setDerefAliases(AliasDerefMode.DEREF_ALWAYS);

     SearchCursor cursor = lc.search(sr);
     // EntryCursor cursor=new EntryCursorImpl(scursor);

     if  (isDebugMode()){
     System.err.print("search(\""+base+"\"");
     for  (String  s : attributeNames){
     System.err.print(",\""+s+"\"");
     }
     System.err.println(");");
     }
         if  (true  || cursor.available()){
     for  (Response entry: cursor){
     entries.add(entry);
     }
     }  else  {
     if  (isDebugMode()){
     System.err.println("SearchResults came back null!");
     }
     }
     try  {
     cursor.close();
     }  catch  (IOException ioeClose){
     ioeClose.printStackTrace(System.err);
     }
     return  entries;
}


On 3/6/2018 4:27 PM, Emmanuel Lécharny wrote:

Le 07/03/2018 à 00:08, George S. a écrit :

and, just to throw in another point, I've got some other code using the
Novell LDAP API library and it is able to do the query, and I can use
JXplorer to browse the tree.

It's really looking like there's something wrong in the library.


Re: LdapConnection.search() Help

2018-03-07 Thread Emmanuel Lécharny
So I have it working fine with this code :

EntryCursor cursor = connection.search( "ou=system",
"(objectclass=*)",
SearchScope.ONELEVEL,
"*", "+" );
int count = 0;

for ( Entry entry : cursor )
{
assertNotNull( entry );
count++;
}

SearchResultDone done = cursor.getSearchResultDone();

As you can see, I also use an iterator, I don't user a SearchRequest,
and I get 5 entries back (count == 5 at the end).

EntryCursorImpl is Iterable, and uses a CursorIterator to handle
iteration, which move forward immediately when created, so that the
first get() works (available() will succeed).

AFAICT, it works properly.

The only annoying problem is that a cursor is never going to give you a
result if you don't move forward beforehand : its position is always
*before* the first element. It may sound weird, but it's because we need
to be able to move forward and backward properly.


Le 07/03/2018 à 01:53, George S. a écrit :
> It's definitely a problem.
> 
> 
> On 3/6/2018 5:03 PM, George S. wrote:
>> I looked at
>> LdapNetworkConnection.search(String,String,SearchScope,String...) and
>> it's a wrapper around a call to search using a SearchRequest, and
>> constructing a EntryCursorImpl from the SearchCursor.
>>
>> There seems to be something wrong in EntryCursorImpl. If I change my
>> code to use a SearchRequest, then I get results in a SearchCursor and
>> I can iterate over them.
> 
> Looking at the code, EntryCursorImpl implicitly calls
> searchCursor.available(), which is returning false because it appears
> response is not set until a call to next(). See SearchResultImpl line
> 117 or so.
> 
> 
>>
>> public  Collectionsearch(String  base,String...
>> attributeNames)throws  LdapException{
>>
>>     if  (attributeNames.length ==0){
>>     attributeNames =new  String[]{
>> "distinguishedName","objectClass","name",
>> prop.getProperty("emailAddress","mail")};
>>     }
>>     Collection entries =new  ArrayList<>();
>>     SearchRequest sr=new  SearchRequestImpl();
>>     sr.setBase(new  Dn(base));
>>     sr.setTimeLimit(Integer.MAX_VALUE);
>>     sr.setFilter("(objectclass=*)");
>>     sr.addAttributes(attributeNames);
>>     sr.setScope(SearchScope.ONELEVEL);
>>     sr.setDerefAliases(AliasDerefMode.DEREF_ALWAYS);
>>
>>     SearchCursor cursor = lc.search(sr);
>>     // EntryCursor cursor=new EntryCursorImpl(scursor);
>>
>>     if  (isDebugMode()){
>>     System.err.print("search(\""+base+"\"");
>>     for  (String  s : attributeNames){
>>     System.err.print(",\""+s+"\"");
>>     }
>>     System.err.println(");");
>>     }
>>         if  (true  || cursor.available()){
>>     for  (Response entry: cursor){
>>     entries.add(entry);
>>     }
>>     }  else  {
>>     if  (isDebugMode()){
>>     System.err.println("SearchResults came back null!");
>>     }
>>     }
>>     try  {
>>     cursor.close();
>>     }  catch  (IOException ioeClose){
>>     ioeClose.printStackTrace(System.err);
>>     }
>>     return  entries;
>> }
>>
>>
>> On 3/6/2018 4:27 PM, Emmanuel Lécharny wrote:
>>>
>>> Le 07/03/2018 à 00:08, George S. a écrit :
 and, just to throw in another point, I've got some other code using the
 Novell LDAP API library and it is able to do the query, and I can use
 JXplorer to browse the tree.

 It's really looking like there's something wrong in the library.
>>> Sorry, I missed the point. Removed the 'if ( cursor.available() )', it
>>> should work.
>>>
>>
> 

-- 
Emmanuel Lecharny

Symas.com
directory.apache.org



Re: LdapConnection.search() Help

2018-03-06 Thread Emmanuel Lécharny


Le 07/03/2018 à 01:53, George S. a écrit :
> It's definitely a problem.

Ok. Can you fill a JIRA ? I'll have a deeper look at teh code later this
week.


-- 
Emmanuel Lecharny

Symas.com
directory.apache.org



Re: LdapConnection.search() Help

2018-03-06 Thread George S.

It's definitely a problem.


On 3/6/2018 5:03 PM, George S. wrote:
I looked at 
LdapNetworkConnection.search(String,String,SearchScope,String...) and 
it's a wrapper around a call to search using a SearchRequest, and 
constructing a EntryCursorImpl from the SearchCursor.


There seems to be something wrong in EntryCursorImpl. If I change my 
code to use a SearchRequest, then I get results in a SearchCursor and 
I can iterate over them.


Looking at the code, EntryCursorImpl implicitly calls 
searchCursor.available(), which is returning false because it appears 
response is not set until a call to next(). See SearchResultImpl line 
117 or so.





public  Collectionsearch(String  base,String... 
attributeNames)throws  LdapException{


    if  (attributeNames.length ==0){
    attributeNames =new  String[]{ 
"distinguishedName","objectClass","name", 
prop.getProperty("emailAddress","mail")};

    }
    Collection entries =new  ArrayList<>();
    SearchRequest sr=new  SearchRequestImpl();
    sr.setBase(new  Dn(base));
    sr.setTimeLimit(Integer.MAX_VALUE);
    sr.setFilter("(objectclass=*)");
    sr.addAttributes(attributeNames);
    sr.setScope(SearchScope.ONELEVEL);
    sr.setDerefAliases(AliasDerefMode.DEREF_ALWAYS);

    SearchCursor cursor = lc.search(sr);
    // EntryCursor cursor=new EntryCursorImpl(scursor);

    if  (isDebugMode()){
    System.err.print("search(\""+base+"\"");
    for  (String  s : attributeNames){
    System.err.print(",\""+s+"\"");
    }
    System.err.println(");");
    }
        if  (true  || cursor.available()){
    for  (Response entry: cursor){
    entries.add(entry);
    }
    }  else  {
    if  (isDebugMode()){
    System.err.println("SearchResults came back null!");
    }
    }
    try  {
    cursor.close();
    }  catch  (IOException ioeClose){
    ioeClose.printStackTrace(System.err);
    }
    return  entries;
}


On 3/6/2018 4:27 PM, Emmanuel Lécharny wrote:


Le 07/03/2018 à 00:08, George S. a écrit :

and, just to throw in another point, I've got some other code using the
Novell LDAP API library and it is able to do the query, and I can use
JXplorer to browse the tree.

It's really looking like there's something wrong in the library.

Sorry, I missed the point. Removed the 'if ( cursor.available() )', it
should work.





--
George S.
*MH Software, Inc.*
Voice: 303 438 9585
http://www.mhsoftware.com


Re: LdapConnection.search() Help

2018-03-06 Thread George S.
I looked at 
LdapNetworkConnection.search(String,String,SearchScope,String...) and 
it's a wrapper around a call to search using a SearchRequest, and 
constructing a EntryCursorImpl from the SearchCursor.


There seems to be something wrong in EntryCursorImpl. If I change my 
code to use a SearchRequest, then I get results in a SearchCursor and I 
can iterate over them.


public  Collectionsearch(String  base,String... attributeNames)throws 
 LdapException{

if  (attributeNames.length ==0){
attributeNames =new  String[]{  "distinguishedName","objectClass","name", 
prop.getProperty("emailAddress","mail")};
}
Collection entries =new  ArrayList<>();
SearchRequest sr=new  SearchRequestImpl();
sr.setBase(new  Dn(base));
sr.setTimeLimit(Integer.MAX_VALUE);
sr.setFilter("(objectclass=*)");
sr.addAttributes(attributeNames);
sr.setScope(SearchScope.ONELEVEL);
sr.setDerefAliases(AliasDerefMode.DEREF_ALWAYS);

SearchCursor cursor = lc.search(sr);
// EntryCursor cursor=new EntryCursorImpl(scursor);

if  (isDebugMode()){
System.err.print("search(\""+base+"\"");
for  (String  s : attributeNames){
System.err.print(",\""+s+"\"");
}
System.err.println(");");
}

if  (true  || cursor.available()){

for  (Response entry: cursor){
entries.add(entry);
}
}  else  {
if  (isDebugMode()){
System.err.println("SearchResults came back null!");
}
}
try  {
cursor.close();
}  catch  (IOException ioeClose){
ioeClose.printStackTrace(System.err);
}
return  entries;
}


On 3/6/2018 4:27 PM, Emmanuel Lécharny wrote:


Le 07/03/2018 à 00:08, George S. a écrit :

and, just to throw in another point, I've got some other code using the
Novell LDAP API library and it is able to do the query, and I can use
JXplorer to browse the tree.

It's really looking like there's something wrong in the library.

Sorry, I missed the point. Removed the 'if ( cursor.available() )', it
should work.



--
George S.
*MH Software, Inc.*
Voice: 303 438 9585
http://www.mhsoftware.com


Re: LdapConnection.search() Help

2018-03-06 Thread George S.



On 3/6/2018 4:27 PM, Emmanuel Lécharny wrote:


Le 07/03/2018 à 00:08, George S. a écrit :

and, just to throw in another point, I've got some other code using the
Novell LDAP API library and it is able to do the query, and I can use
JXplorer to browse the tree.

It's really looking like there's something wrong in the library.

Sorry, I missed the point. Removed the 'if ( cursor.available() )', it
should work.


That doesn't help. I get:

search("DC=somedistrict,DC=k12,DC=local","objectClass");
Exception in thread "main" java.lang.RuntimeException: 
ERR_02002_FAILURE_ON_UNDERLYING_CURSOR Failure on underlying Cursor.
at 
org.apache.directory.api.ldap.model.cursor.CursorIterator.next(CursorIterator.java:89)
at com.mhsoftware.ldap.BoundConnection.search(BoundConnection.java:338)







--
George S.
*MH Software, Inc.*
Voice: 303 438 9585
http://www.mhsoftware.com


Re: LdapConnection.search() Help

2018-03-06 Thread Emmanuel Lécharny


Le 07/03/2018 à 00:08, George S. a écrit :
> and, just to throw in another point, I've got some other code using the
> Novell LDAP API library and it is able to do the query, and I can use
> JXplorer to browse the tree.
> 
> It's really looking like there's something wrong in the library.

Sorry, I missed the point. Removed the 'if ( cursor.available() )', it
should work.

-- 
Emmanuel Lecharny

Symas.com
directory.apache.org



Re: LdapConnection.search() Help

2018-03-06 Thread George S.
and, just to throw in another point, I've got some other code using the 
Novell LDAP API library and it is able to do the query, and I can use 
JXplorer to browse the tree.


It's really looking like there's something wrong in the library.



On 3/6/2018 3:51 PM, Emmanuel Lécharny wrote:

Hi,

are you sure you have entries below the point you are searching from ?
You are doing a search using a ONE_LEVEL scope, which will return oly
the children entries.


Le 06/03/2018 à 22:32, George S. a écrit :

I'm trying to use the API library and i'm running into a problem. I'm
trying to do a search (see method below). Using this bound connection, I
can do a lookup. For example, I can do .lookup(base,"objectClass"),
.lookup(base,"dc"), etc. However search isn't working.

Can anyone give me an idea of what I'm doing wrong. I've looked through
the docs and I'm just not getting it.

public  Collectionsearch(String  base,String...
attributeNames)throws  LdapException{

if  (attributeNames.length ==0){
     attributeNames =new  String[]{
"distinguishedName","objectClass","name",
prop.getProperty("emailAddress","mail")};
}
Collection entries =new  ArrayList<>();
// LC is LdapNetworkConnection
  EntryCursor cursor = lc.search(new  Dn(base),"(objectclass=*)",
SearchScope.ONELEVEL,attributeNames);

if  (isDebugMode()){
     System.err.print("search(\""+base+"\"");
     for  (String  s : attributeNames){
     System.err.print(",\""+s+"\"");
     }
     System.err.println(");");
     System.err.println("cursor.available()="  + cursor.available());
}

if  (cursor.available()){
     for  (Entry entry: cursor){
     entries.add(entry);
     }
}  else  {
     if  (isDebugMode()){
     System.err.println("SearchResults came back null!");
     }
}
try  {
     cursor.close();
}  catch  (IOException ioeClose){
     ioeClose.printStackTrace(System.err);
}
return  entries;
}

The output is:

getAttribute() entry=[Entry
     dn: DC=somedistrict,DC=k12,DC=local

     dc: somedistrict
]
     dc
     somedistrict

search("DC=somedistrict,DC=k12,DC=local","objectClass");
cursor.available()=false
SearchResults came back null!

  



--
George S.
*MH Software, Inc.*
Voice: 303 438 9585
http://www.mhsoftware.com


Re: LdapConnection.search() Help

2018-03-06 Thread George S.

Thanks for responding.

I have been using SearchScope.SUBTREE, and it makes no difference.


On 3/6/2018 3:51 PM, Emmanuel Lécharny wrote:

Hi,

are you sure you have entries below the point you are searching from ?
You are doing a search using a ONE_LEVEL scope, which will return oly
the children entries.


Le 06/03/2018 à 22:32, George S. a écrit :

I'm trying to use the API library and i'm running into a problem. I'm
trying to do a search (see method below). Using this bound connection, I
can do a lookup. For example, I can do .lookup(base,"objectClass"),
.lookup(base,"dc"), etc. However search isn't working.

Can anyone give me an idea of what I'm doing wrong. I've looked through
the docs and I'm just not getting it.

public  Collectionsearch(String  base,String...
attributeNames)throws  LdapException{

if  (attributeNames.length ==0){
     attributeNames =new  String[]{
"distinguishedName","objectClass","name",
prop.getProperty("emailAddress","mail")};
}
Collection entries =new  ArrayList<>();
// LC is LdapNetworkConnection
  EntryCursor cursor = lc.search(new  Dn(base),"(objectclass=*)",
SearchScope.ONELEVEL,attributeNames);

if  (isDebugMode()){
     System.err.print("search(\""+base+"\"");
     for  (String  s : attributeNames){
     System.err.print(",\""+s+"\"");
     }
     System.err.println(");");
     System.err.println("cursor.available()="  + cursor.available());
}

if  (cursor.available()){
     for  (Entry entry: cursor){
     entries.add(entry);
     }
}  else  {
     if  (isDebugMode()){
     System.err.println("SearchResults came back null!");
     }
}
try  {
     cursor.close();
}  catch  (IOException ioeClose){
     ioeClose.printStackTrace(System.err);
}
return  entries;
}

The output is:

getAttribute() entry=[Entry
     dn: DC=somedistrict,DC=k12,DC=local

     dc: somedistrict
]
     dc
     somedistrict

search("DC=somedistrict,DC=k12,DC=local","objectClass");
cursor.available()=false
SearchResults came back null!

  



--
George S.
*MH Software, Inc.*
Voice: 303 438 9585
http://www.mhsoftware.com


Re: LdapConnection.search() Help

2018-03-06 Thread Emmanuel Lécharny
Hi,

are you sure you have entries below the point you are searching from ?
You are doing a search using a ONE_LEVEL scope, which will return oly
the children entries.


Le 06/03/2018 à 22:32, George S. a écrit :
> I'm trying to use the API library and i'm running into a problem. I'm
> trying to do a search (see method below). Using this bound connection, I
> can do a lookup. For example, I can do .lookup(base,"objectClass"),
> .lookup(base,"dc"), etc. However search isn't working.
> 
> Can anyone give me an idea of what I'm doing wrong. I've looked through
> the docs and I'm just not getting it.
> 
> public  Collectionsearch(String  base,String...
> attributeNames)throws  LdapException{
> 
> if  (attributeNames.length ==0){
>     attributeNames =new  String[]{ 
> "distinguishedName","objectClass","name",
> prop.getProperty("emailAddress","mail")};
> }
> Collection entries =new  ArrayList<>();
> // LC is LdapNetworkConnection
>  EntryCursor cursor = lc.search(new  Dn(base),"(objectclass=*)",
> SearchScope.ONELEVEL,attributeNames);
> 
> if  (isDebugMode()){
>     System.err.print("search(\""+base+"\"");
>     for  (String  s : attributeNames){
>     System.err.print(",\""+s+"\"");
>     }
>     System.err.println(");");
>     System.err.println("cursor.available()="  + cursor.available());
> }
> 
> if  (cursor.available()){
>     for  (Entry entry: cursor){
>     entries.add(entry);
>     }
> }  else  {
>     if  (isDebugMode()){
>     System.err.println("SearchResults came back null!");
>     }
> }
> try  {
>     cursor.close();
> }  catch  (IOException ioeClose){
>     ioeClose.printStackTrace(System.err);
> }
> return  entries;
> }
> 
> The output is:
> 
> getAttribute() entry=[Entry
>     dn: DC=somedistrict,DC=k12,DC=local
> 
>     dc: somedistrict
> ]
>     dc
>     somedistrict
> 
> search("DC=somedistrict,DC=k12,DC=local","objectClass");
> cursor.available()=false
> SearchResults came back null!
> 
>  
> 

-- 
Emmanuel Lecharny

Symas.com
directory.apache.org



LdapConnection.search() Help

2018-03-06 Thread George S.
I'm trying to use the API library and i'm running into a problem. I'm 
trying to do a search (see method below). Using this bound connection, I 
can do a lookup. For example, I can do .lookup(base,"objectClass"), 
.lookup(base,"dc"), etc. However search isn't working.


Can anyone give me an idea of what I'm doing wrong. I've looked through 
the docs and I'm just not getting it.


public  Collectionsearch(String  base,String... attributeNames)throws  
LdapException{

if  (attributeNames.length ==0){
attributeNames =new  String[]{  "distinguishedName","objectClass","name", 
prop.getProperty("emailAddress","mail")};
}
Collection entries =new  ArrayList<>();
// LC is LdapNetworkConnection
 EntryCursor cursor = lc.search(new  Dn(base),"(objectclass=*)", 
SearchScope.ONELEVEL,attributeNames);

if  (isDebugMode()){
System.err.print("search(\""+base+"\"");
for  (String  s : attributeNames){
System.err.print(",\""+s+"\"");
}
System.err.println(");");
System.err.println("cursor.available()="  + cursor.available());
}

if  (cursor.available()){
for  (Entry entry: cursor){
entries.add(entry);
}
}  else  {
if  (isDebugMode()){
System.err.println("SearchResults came back null!");
}
}
try  {
cursor.close();
}  catch  (IOException ioeClose){
ioeClose.printStackTrace(System.err);
}
return  entries;
}

The output is:

getAttribute() entry=[Entry
dn: DC=somedistrict,DC=k12,DC=local

dc: somedistrict
]
dc
somedistrict

search("DC=somedistrict,DC=k12,DC=local","objectClass");
cursor.available()=false
SearchResults came back null!

 


--
George S.
*MH Software, Inc.*
Voice: 303 438 9585
http://www.mhsoftware.com