logoUserbooster Forum

Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

EJP
#1 Posted : Wednesday, October 19, 2016 11:58:21 PM(UTC)
EJP

Rank: Advanced Member

Groups: Registered
Joined: 6/21/2011(UTC)
Posts: 75

Was thanked: 2 time(s) in 2 post(s)
I noticed this some years ago and failed to report it here until now. It has just bitten me again. Java 1.5+ provides a JNDI SortControl where you can either provide a SortKey containing an attribute name and an ordering rule name, or else just provide the attribute name(s) as a String or String[] and the ordering rule isn't set at all in the SortControl (where it is optional). However with OpenLDAP using the latter returns an error saying 'no ordering rule'.

Is this a known problem and has it been fixed? I'm a release or two behind here.

If not I can provide a Java test case here. It's not critical for me, as I can use new SortControl(SortKey[],...) easily enough instead of new SortControl(String,...) or new SortControl(String[],...), but it should be fixed.
hacker
#2 Posted : Friday, October 28, 2016 2:56:26 AM(UTC)
hacker

Rank: Newbie

Groups: Registered
Joined: 3/7/2016(UTC)
Posts: 6

Hi.

We are testing the latest version at the moment. I'd appreciate if you could email me a (detailed) test case so I can run it locally.

Thanks in advance.
EJP
#3 Posted : Monday, October 31, 2016 7:53:22 AM(UTC)
EJP

Rank: Advanced Member

Groups: Registered
Joined: 6/21/2011(UTC)
Posts: 75

Was thanked: 2 time(s) in 2 post(s)
Yes, I can let you have that on Wednesday, we are on 1/2 holoday today and full holiday tomorrow. You will need Java 1.8 to execute it, and you'll have to change the source code to match your own test DIT and user credentials.

EJP
EJP
#4 Posted : Friday, November 4, 2016 2:01:07 AM(UTC)
EJP

Rank: Advanced Member

Groups: Registered
Joined: 6/21/2011(UTC)
Posts: 75

Was thanked: 2 time(s) in 2 post(s)
Here is a JUnit test case. You will need Java 1.5 at least, JUnit 3.something, and you will need to customize the credentials and the sort and the search at the points marked 'CUSTOMIZE HERE'. The key point is the construction of the SortControl. If it is constructed with just "cn", it fails: if it is contructed with the SortKeys, which specify an ordering, it succeeds.

package com.verismart.ldap;

import java.io.IOException;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.Control;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.SortControl;
import javax.naming.ldap.SortKey;
import javax.naming.ldap.SortResponseControl;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
*
* @author Esmond Pitt
*/
public class SortControlTest
{

public SortControlTest()
{
}

@BeforeClass
public static void setUpClass()
{
}

@AfterClass
public static void tearDownClass()
{
}

@Before
public void setUp()
{
}

@After
public void tearDown()
{
}

@Test
public void testSortControlDefault() throws NamingException, IOException
{
Hashtable<String,Object> env = new Hashtable<>();

env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.PROVIDER_URL, "ldap://localhost");
env.put(Context.SECURITY_AUTHENTICATION, "simple");

// CUSTOMIZE HERE
env.put(Context.SECURITY_PRINCIPAL, "cn=Esmond Pitt+mail=esmond.pitt@entirelydifferentsolutions.com,ou=Exec,ou=Corporate,ou=Users,dc=verismartlabs,dc=com");
env.put(Context.SECURITY_CREDENTIALS, "XXXXX");

try
{
/* Create initial context with no connection request controls */
LdapContext ctx = new InitialLdapContext(env, null);

/* Sort Control key definitions */
// CUSTOMIZE HERE
SortKey[] sortKeys =
{
// sort by cn
new SortKey("cn", true, "caseIgnoreOrderingMatch")
};
// Note: the constructors for SortControl that take String or String[]
// as the first argument produce 'no ordering rule' errors with OpenLDAP.
// CUSTOMIZE HERE
SortControl sctl = new SortControl(
"cn",
// new String[]{"cn"},
// sortKeys,
Control.CRITICAL);

/* Set context's request controls */
ctx.setRequestControls(new Control[]
{
sctl,
});

int count = 0;
SearchControls sc = new SearchControls(SearchControls.SUBTREE_SCOPE, 0, 0, null, false, false);
/* Perform search */
// System.out.println("namespace="+ctx.getNameInNamespace());
// System.out.println("count limit="+sc.getCountLimit());
// System.out.println("search scope="+sc.getSearchScope());

// CUSTOMIZE HERE
NamingEnumeration<SearchResult> ne =
ctx.search("ou=Customers,ou=Users,dc=verismartlabs,dc=com", "(objectClass={0})", new String[]{"inetOrgPerson"}, sc);

/* Enumerate search results */
while (ne.hasMore())
{
count++;
SearchResult sr = ne.next();
// System.out.println(i+": "+sr.getName());
System.out.println(count+": "+sr.getNameInNamespace());
}

ne.close();

/* examine the response controls (if any) */
printControls(ctx.getResponseControls());
ctx.close();
}
finally
{
}
}

static void printControls(Control[] controls)
{
if (controls == null)
{
System.out.println("No response controls");
return;
}

for (int j = 0; j < controls.length; j++)
{
if (controls[j] instanceof SortResponseControl)
{
SortResponseControl src = (SortResponseControl)controls[j];
if (src.isSorted())
{
System.out.println("Sorted-Search completed successfully");
}
else
{
System.out.println(
"Sorted-Search did not complete successfully: error ("
+ src.getResultCode() + ") on attribute '"
+ src.getAttributeID() + "'");
}
}
}
}
}
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF | YAF © 2003-2017, Yet Another Forum.NET
This page was generated in 0.223 seconds.