0
votes

I am trying to create sub context for domain component, but its showing the following error

javax.naming.OperationNotSupportedException: [LDAP: error code 53 - no global superior knowledge]; remaining name 'uid=user3, dc=example'

This is my Code

public class OpenLDAPTest {

public static void main(String[] args) {
    String url = "ldap://localhost:389";
    // String url = "ldap://localhost:10389";
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "cn=Manager,dc=maxcrc,dc=com");
    // env.put(Context.SECURITY_PRINCIPAL, "uid=admin, ou=system");
    env.put(Context.SECURITY_CREDENTIALS, "secret");
    try {
        DirContext ctx = new InitialDirContext(env);
        System.out.println("connected");
        System.out.println(ctx.getEnvironment());
        System.out.println("Creating subContext");
        String name = "uid=user3, dc=example";
        Attributes atrs = new BasicAttributes();
        Attribute atr1 = new BasicAttribute("objectClass");
        atr1.add("inetOrgPerson");
        atrs.put(atr1);
        Attribute atr2 = new BasicAttribute("cn");
        atr2.add("sathish");
        atrs.put(atr2);
        Attribute atr3 = new BasicAttribute("o");
        atr3.add("Kumar");
        atrs.put(atr3);
        Attribute atr4 = new BasicAttribute("sn");
        atr4.add("example");
        atrs.put(atr4);
        Context c = ctx.createSubcontext(name, atrs);
        System.out.println(c.getEnvironment());
        ctx.close();

    } catch (AuthenticationNotSupportedException ex) {
        System.out
                .println("The authentication is not supported by the server");
    } catch (AuthenticationException ex) {
        System.out.println("incorrect password or username");
    } catch (NamingException ex) {
        // System.out.println("error when trying to create the context");
        ex.printStackTrace();
    }
}

}

If I use the same code for ApacheDS(by changing credentials) its working. but its not working for openLDAP.

2
You should not use the Manager account for anything. That's for slapd.exe itself. You should create an administrative account inside the DIT that has the appopriate privileges. - user207421
can you tell me how to do it. - Sat
Why? when you can look it up for yourself in the documentation? - user207421
I am not that much good in LDAP, I am just using it now only... which doc I have to prefer, in net I am getting so many docs, none of them providing proper solution - Sat
Rubbish. Everything I know about LDAP and OpenLDAP came from the documentation, specifcally including how to create administrative accounts. If you can't deal with the official documentation you don't have much future in this business. - user207421

2 Answers

1
votes

You could try to set the domain name as 'dc=example' upon installation

in the LDAP backend setting step,

ldap setting
(source: userbooster.de)

otherwise you could change "uid=user3, dc=example" to "uid=user3,dc=maxcrc,dc=com" to add it .

Don't bother yourself adding a database with root "dc=example" while there is already a database with root "dc=maxrc,dc=com" in windows server.

Update:

Though you set domain to be "dc=maxcrc,dc=com",corresponding domain root entry is not added by default.

You need to add "dc=maxcrc,dc=com" before adding that sub context

    String name = "dc=maxcrc,dc=com";
    Attributes atrs = new BasicAttributes();
    Attribute atr1 = new BasicAttribute("objectClass");
    atr1.add("organization");
    atrs.put(atr1);
    Attribute atr2 = new BasicAttribute("objectClass");
    atr2.add("dcObject");
    atrs.put(atr2);
    Attribute atr3 = new BasicAttribute("dc");
    atr3.add("maxcrm");
    atrs.put(atr3);
    Attribute atr4 = new BasicAttribute("o");
    atr4.add("anyOrgYouLike");
    atrs.put(atr4);
    Context c = ctx.createSubcontext(name, atrs);
0
votes

What you're attempting amounts to creating a new database in OpenLDAP called dc=example. You can only do that via configuration.