I'd like to follow the referrals only when I'm not getting any SearchResultEntry types back from the search. Meaning the cursor contains only SearchResultReference types. I can manage that logic but do you do with the Reference? Do you add it to the original request and search again or somehow use it to perform a new search? Thanks.
I like the idea about getting references back as Entries but we're expecting Entries to be either users or groups. Thanks! Carlo Accorsi -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Kiran Ayyagari Sent: Wednesday, August 28, 2013 10:21 AM To: [email protected] Subject: Re: Advice on how to deal with SEARCH_RESULT_REFERENCE response in SearchCursor On Wed, Aug 28, 2013 at 7:31 PM, <[email protected]> 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.SearchResultReferenceDe > corator > 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(U > nknown > Source) > at > com.ibsamericainc.dir.DirectoryServerConnection.getEntryFromUsername(U > nknown > Source) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. > > -- Kiran Ayyagari http://keydap.com
