Hi,
first of all, please avoid cross posting on multiple mailing list.
[email protected] is correct.
As Kiran saind, we don't yet support referrals in ConnectionTemplate.
please fill a JIRA for us to remember to implement it.
Otherwise, using a LdapNetworkConnection to do so is not really complex.
Here is a code exemple that does the job :
EntryCursor cursor = connection.search(
"ou=Countries,ou=system", "(objectClass=*)",
SearchScope.SUBTREE, "*", "+" );
int count = 0;
Entry entry = null;
List<String> refs = new ArrayList<String>();
while ( cursor.next() )
{
try
{
entry = cursor.get();
// Do whatever you want with your entry
count++;
}
catch ( CursorLdapReferralException clre )
{
count++;
do
{
// We gather all the referrals here. It's up to you
to decide to follow them or not
String ref = clre.getReferralInfo();
refs.add( ref );
}
while ( clre.skipReferral() );
}
}
One more thing : the API does not support yet referral chasing (ie the
client does not automatically send a new request to the remote server,
you have to do it by hand).
Hope it helps.
Le 06/08/14 15:51, prabhjot singh a écrit :
> Hi Kiran & Team,
>
> Can you please advise on this?
>
> Thanks,
> Prabhjot
>
>
> On Wed, Aug 6, 2014 at 1:33 PM, prabhjot singh <[email protected]>
> wrote:
>
>> Thanks Kiran.
>>
>> I'm not very clear how to achieve this using LdapNetworkConnection.
>>
>> If I understand correctly, I see we've
>> LdapNetworkConnection.search(SearchRequest
>> request)
>> <https://directory.apache.org/api/gen-docs/latest/apidocs/org/apache/directory/ldap/client/api/LdapNetworkConnection.html#search(org.apache.directory.api.ldap.model.message.SearchRequest)>and
>> set the followReferrals on the search request passed here (the way I was
>> doing in my code snippet)?
>>
>> Also, I'm not terribly familiar with how to process SearchCursor and
>> specifically handle referrals (if I've to do this). Will appreciate if you
>> can point to some example code.
>>
>>
>>
>> On Tue, Aug 5, 2014 at 10:35 PM, Kiran Ayyagari <[email protected]>
>> wrote:
>>
>>>
>>>
>>> On Tue, Aug 5, 2014 at 10:27 PM, prabhjot singh <[email protected]>
>>> wrote:
>>>
>>>> Thanks Kiran. That would mean LdapConnectionTemplate won't be safe to
>>>> use in any of the search operations.
>>>>
>>>> it is not about safety, just that this template class decided not to
>>> support referrals
>>>
>>>> Is it safe to use LdapConnectionTemplate for lookup operations at least?
>>>>
>>> yes, you can use, but you will face the same issue if a referral entry is
>>> recieved during lookup
>>>
>>> Looks like you are making heavy use of template in your code, if so, may
>>> be you can just extend
>>> the template to support referral entries or use LdapNetworkConnection
>>> directly.
>>>
>>>> Thanks,
>>>> Prabhjot
>>>> ------------------------------
>>>> From: Kiran Ayyagari <[email protected]>
>>>> Sent: 8/5/2014 10:19 PM
>>>> To: [email protected]; [email protected]
>>>> Cc: [email protected]
>>>> Subject: Re: Apache LDAP API - ActiveDirectory Handling referrals
>>>>
>>>>
>>>>
>>>>
>>>> On Tue, Aug 5, 2014 at 9:45 PM, Prabhjot Singh <
>>>> [email protected]> wrote:
>>>>
>>>>> Hi Experts,
>>>>>
>>>>>
>>>>>
>>>>> Can you please point me on how to handle referrals in the search
>>>>> operation?
>>>>> I want the logic to follow the referrals so it collects results from all
>>>>> Active Directory DCs. I get below exception even with followReferrals
>>>>> set
>>>>> to true.
>>>>>
>>>>>
>>>>>
>>>>> public List<Group> getAllGroups(String customer, String baseDn) throws
>>>>> Exception {
>>>>>
>>>>> LdapConnectionTemplate connection =
>>>>> connections.getLdapConnectionTemplate(customer);
>>>>>
>>>>> LdapConnectionTemplate doesn't support referrals, so search using
>>>> LdapNetworkConnection directly
>>>>
>>>>> SearchRequest searchRequest =
>>>>> connection.newSearchRequest(baseDn,
>>>>> "(objectclass=organizationalUnit)", SearchScope.ONELEVEL,
>>>>> GROUP_ATTRIBUTES);
>>>>>
>>>>> searchRequest = searchRequest.followReferrals();
>>>>>
>>>>> return connection.search(searchRequest, new GroupMapper());
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> 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:86)
>>>>>
>>>>> at
>>>>>
>>>>> org.apache.directory.ldap.client.template.LdapConnectionTemplate.search(LdapConnectionTemplate.java:662)
>>>>>
>>>>> at
>>>>>
>>>>> com.kaseya.mobility.directory.core.dao.group.DirectoryDetailsDaoImpl.getAllGroups(DirectoryDetailsDaoImpl.java:53)
>>>>>
>>>>> at
>>>>>
>>>>> com.kaseya.mobility.directory.core.dao.group.DirectoryDetailsDaoImplTest.testGetAllGroups(DirectoryDetailsDaoImplTest.java:66)
>>>>>
>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
>>>>> Method)
>>>>>
>>>>> at
>>>>>
>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>>>>>
>>>>> at
>>>>>
>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>>>>
>>>>> at
>>>>>
>>>>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>>>>>
>>>>> at
>>>>>
>>>>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>>>>
>>>>> at
>>>>>
>>>>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>>>>>
>>>>> at
>>>>>
>>>>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>>>>
>>>>> at
>>>>>
>>>>> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>>>>>
>>>>> at
>>>>>
>>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
>>>>>
>>>>> at
>>>>>
>>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>>>>>
>>>>> at
>>>>> org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>>>>>
>>>>> at
>>>>> org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>>>>>
>>>>> at
>>>>> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>>>>>
>>>>> at
>>>>> org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>>>>>
>>>>> at
>>>>> org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>>>>>
>>>>> at
>>>>> org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>>>>>
>>>>> at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
>>>>>
>>>>> at
>>>>>
>>>>> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
>>>>>
>>>>> at
>>>>>
>>>>> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
>>>>>
>>>>> at
>>>>> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
>>>>>
>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
>>>>> Method)
>>>>>
>>>>> at
>>>>>
>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>>>>>
>>>>> at
>>>>> com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
>>>>>
>>>>> Caused by:
>>>>> org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException
>>>>>
>>>>> at
>>>>>
>>>>> org.apache.directory.ldap.client.api.EntryCursorImpl.get(EntryCursorImpl.java:164)
>>>>>
>>>>> at
>>>>>
>>>>> org.apache.directory.ldap.client.api.EntryCursorImpl.get(EntryCursorImpl.java:50)
>>>>>
>>>>> at
>>>>>
>>>>> org.apache.directory.api.ldap.model.cursor.CursorIterator.next(CursorIterator.java:80)
>>>>>
>>>>> ... 29 more
>>>>>
>>>>
>>>>
>>>> --
>>>> Kiran Ayyagari
>>>> http://keydap.com
>>>>
>>>
>>>
>>> --
>>> Kiran Ayyagari
>>> http://keydap.com
>>>
>>
>>
>> --
>> Thanks,
>> Prabhjot
>>
>
>