directory-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kiran Ayyagari <kayyag...@apache.org>
Subject Re: Advice on how to deal with SEARCH_RESULT_REFERENCE response in SearchCursor
Date Wed, 28 Aug 2013 14:20:44 GMT
On Wed, Aug 28, 2013 at 7:31 PM, <Carlo.Accorsi@ibs-ag.com> wrote:

> Hi,
> We're trying to use the API with Active Directory.  Sometimes a search
> result includes a SEARCH_RESULT_REFERENCE..
> Even though I'm getting my result, I think this is telling me somewhere
> else I can go find it.
>
> I've never encountered this with ApacheDS as a server but in those cases
> it's a single stand alone machine.
>
> Any patterns or ideas about how to correctly handle this case are
> appreciated.  Thanks!
>
>
> Here is the search request..
>
> MessageType : SEARCH_REQUEST
> Message ID : 2
>     SearchRequest
>         baseDn : 'dc=qualitysys,dc=com'
>         filter : '(sAMAccountName=test.user)'
>         scope : whole subtree
>         typesOnly : false
>         Size Limit : 1
>         Time Limit : 10000
>         Deref Aliases : deref Always
>         attributes : '*'
> org.apache.directory.api.ldap.model.message.SearchRequestImpl@6a8393b3
> <mailto:
> org.apache.directory.api.ldap.model.message.SearchRequestImpl@6a8393b3>
>
>
> Value of Response response = cursor.get();
>
> MessageType : SEARCH_RESULT_REFERENCE
> Message ID : 2
>     Search Result Reference
>         References
>             'ldap://
> ForestDnsZones.qualitysys.com/DC=ForestDnsZones,DC=qualitysys,DC=com'
>
>
> Here's the code I'm using.
>
>               List<Entry> lstEntries = new ArrayList<Entry>();
>               req.setSizeLimit(limit);
>               SearchCursor cursor = connection.search(req);
>               try
>               {
>                      int count = 0;
>                      while(cursor.next())
>                      {
>                            count++;
>                            Response response = cursor.get();
>
>                            Entry entry =
> ((SearchResultEntry)response).getEntry(); // Exception is thrown here.
>
here you need to handle the reference types (as the exception states)
but if you don't want to follow this referral (known as 'chasing') you can
send a special
control to tell the server to return the reference types as
SearchResultEntry types
to do this you need to add the ManageDsaControl
e.x.

        ManageDsaITImpl managedsa = new ManageDsaITImpl();
        SearchRequest req = new SearchRequestImpl();
        req.addControl( managedsa );

then the below shown exception will not occur, but note that you may want
to do this
only if you don't want to chase the referrals


>                            if (entry != null)
>                            {
>                                   lstEntries.add(entry);
>                            }
>                      }
>                      SearchResultDone done = cursor.getSearchResultDone();
>
>
>
> java.lang.ClassCastException:
> org.apache.directory.api.ldap.codec.decorators.SearchResultReferenceDecorator
> cannot be cast to
> org.apache.directory.api.ldap.model.message.SearchResultEntry
>         at
> com.ibsamericainc.dir.DirectoryServerConnection.getEntries(Unknown Source)
>         at
> com.ibsamericainc.dir.DirectoryServerConnection.searchEntries(Unknown
> Source)
>         at
> com.ibsamericainc.dir.DirectoryServerConnection.searchEntries(Unknown
> Source)
>         at
> com.ibsamericainc.dir.DirectoryServerConnection.searchEntry(Unknown Source)
>         at
> com.ibsamericainc.dir.DirectoryServerConnection.getEntryFromUsername(Unknown
> Source)
>         at
> com.ibsamericainc.dir.DirectoryServerConnection.getEntryFromUsername(Unknown
> Source)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
>
>


-- 
Kiran Ayyagari
http://keydap.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message