Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Problems binding to LDAP

Thread view: 
kevin wright - 06 Nov 2006 22:44 GMT
Hi Guys,

I am having problems trying to bind an object to an OpenLdap server (Fedora Linux). I
connect to the server ok but when I try and bind my object I get the following
error message:

javax.naming.OperationNotSupportedException: [LDAP: error code 53 - no global
superior knowledge]; remaining name 'cn=Current'
Naming exception thrown

Having searched on Google I feel that the problem might be that I
am not telling Ldap where to place my entry, but I'm not sure.

Source code is below:

Any thoughts?

Kevin Wright.

import java.util.*;
import java.io.*;
import javax.naming.*;
import javax.naming.directory.*;

class Robot implements Serializable{

}

public class TestLdap{

   
    public static void main(String[] args){
        System.out.println("start");
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL,
                "ldap://localhost:389");
        env.put(Context.SECURITY_AUTHENTICATION,"simple");
       
        try{
        DirContext ctx = new InitialDirContext(env);
        // Try to bind something to the name.
        //Attributes attrs = new BasicAttributes(true);
        //Attribute objclass = new BasicAttribute("objectclass");
        //objclass.add("top");
        //objclass.add("extensibleobject");
        //attrs.put(objclass);
        //attrs.put("hobby", "computing");
           System.out.println("try and do the bind");       
        Robot r = new Robot();
        ctx.bind("cn=Current", r );

        }
        catch(NamingException ne){
            System.err.println( ne );
            System.err.println("Naming exception thrown");
        }

       
       
       
       
    }
   
   
}
kevin wright - 07 Nov 2006 12:38 GMT
Hi Guys,

My problem has moved on:

I am now following the tutorial:

http://www.cris.com/~adhawan/tutorial/

The first step to using openLDAP is apparently to create a root
context in the LDAP naming services. I have modified the slapd.conf
accordingly and now have this:

#
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#
include        /etc/openldap/schema/core.schema
include        /etc/openldap/schema/cosine.schema
include         /etc/openldap/schema/java.schema
include        /etc/openldap/schema/inetorgperson.schema
include        /etc/openldap/schema/nis.schema

# Allow LDAPv2 client connections.  This is NOT the default.
allow bind_v2

# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#referral    ldap://root.openldap.org

pidfile        /var/run/openldap/slapd.pid
argsfile    /var/run/openldap/slapd.args

# Load dynamic backend modules:
# modulepath    /usr/lib/openldap
# moduleload    back_bdb.la
# moduleload    back_ldap.la
# moduleload    back_ldbm.la
# moduleload    back_passwd.la
# moduleload    back_shell.la

# The next three lines allow use of TLS for encrypting connections using a
# dummy test certificate which you can generate by changing to
# /etc/pki/tls/certs, running "make slapd.pem", and fixing permissions on
# slapd.pem so that the ldap user or group can read it.  Your client software
# may balk at self-signed certificates, however.
# TLSCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
# TLSCertificateFile /etc/pki/tls/certs/slapd.pem
# TLSCertificateKeyFile /etc/pki/tls/certs/slapd.pem

# Sample security restrictions
#    Require integrity protection (prevent hijacking)
#    Require 112-bit (3DES or better) encryption for updates
#    Require 63-bit encryption for simple bind
# security ssf=1 update_ssf=112 simple_bind=64

# Sample access control policy:
#    Root DSE: allow anyone to read it
#    Subschema (sub)entry DSE: allow anyone to read it
#    Other DSEs:
#        Allow self write access
#        Allow authenticated users read access
#        Allow anonymous users to authenticate
#    Directives needed to implement policy:
# access to dn.base="" by * read
# access to dn.base="cn=Subschema" by * read
# access to *
#    by self write
#    by users read
#    by anonymous auth
#
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn.  (e.g., "access to * by * read")
#
# rootdn can always read and write EVERYTHING!

#######################################################################
# ldbm and/or bdb database definitions
#######################################################################

database        bdb       
#suffix        "dc=my-domain,dc=com"
suffix          "o=jndiTest"
rootdn        "cn=Manager,o=jndiTest"
#rootdn        "cn=Manager,dc=my-domain,dc=com"
# Cleartext passwords, especially for the rootdn, should
# be avoided.  See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw        secret
# rootpw        {crypt}ijFYNcSNctBYg

# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory    /var/lib/ldap

schemacheck     off

# Indices to maintain for this database
index objectClass                       eq,pres
index ou,cn,mail,surname,givenname      eq,pres,sub
index uidNumber,gidNumber,loginShell    eq,pres
index uid,memberUid                     eq,pres,sub
index nisMapName,nisMapEntry            eq,pres,sub

# Replicas of this database
#replogfile /var/lib/ldap/openldap-master-replog
#replica host=ldap-1.example.com:389 starttls=critical
#     bindmethod=sasl saslmech=GSSAPI
#     authcId=host/ldap-master.example.com@EXAMPLE.COM

Having restarted the Ldap service the following code
should create a new context.

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.NameAlreadyBoundException;
import javax.naming.directory.*;
import java.util.*;

public class MakeRoot {
       final static String ldapServerName = "localhost";
       final static String rootdn = "cn=Manager, o=jndiTest";
       final static String rootpass = "secret";
       final static String rootContext = "o=jndiTest";
       
       public static void main( String[] args ) {
               // set up environment to access the server
               
               Properties env = new Properties();
               
               env.put( Context.INITIAL_CONTEXT_FACTORY,
                        "com.sun.jndi.ldap.LdapCtxFactory" );
               env.put( Context.PROVIDER_URL, "ldap://" + ldapServerName + "/" );
               env.put( Context.SECURITY_PRINCIPAL, rootdn );
               env.put( Context.SECURITY_CREDENTIALS, rootpass );
               
               try {
                       // obtain initial directory context using the environment
                       DirContext ctx = new InitialDirContext( env );
                       
                       // now, create the root context, which is just a subcontext
                       // of this initial directory context.
                       ctx.createSubcontext( rootContext );
               } catch ( NameAlreadyBoundException nabe ) {
                       System.err.println( rootContext + " has already been bound!" );
               } catch ( Exception e ) {
                       System.err.println( e );
               }
       }
}

// end MakeRoot.java

The code compiles but at runtime:

javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - object class 'javaContainer' requires attribute 'cn']; remaining name 'o=jndiTest'

Any takers?

Kevin Wright
kevin wright - 07 Nov 2006 15:31 GMT
All fixed by modifying the java.schema file with the
following change:

objectclass ( 1.3.6.1.4.1.42.2.27.4.2.1
    NAME 'javaContainer'
    DESC 'Container for a Java object'
    SUP top
    STRUCTURAL
       MAY ( o $  cn)  )

#    MUST cn )

I have continued with the tutorial and I am now successfully
binding Java objects to the LDAP service!

Kevin Wright

> Hi Guys,
>
[quoted text clipped - 158 lines]
>
> Kevin Wright
kevin wright - 07 Nov 2006 15:35 GMT
After making the following change to the java.schema file

objectclass ( 1.3.6.1.4.1.42.2.27.4.2.1
    NAME 'javaContainer'
    DESC 'Container for a Java object'
    SUP top
    STRUCTURAL
       MAY ( o $  cn)  )

#    MUST cn )

I have been able to complete the tutorial and am now able to
bind Java Objects to the openLDAP server.

Kevin Wright.
Brandon McCombs - 10 Nov 2006 04:46 GMT
> Hi Guys,
>
[quoted text clipped - 12 lines]
>
> Any thoughts?

I was annoyed that OpenLDAP did not come with any GUI tools and cryptic
CLI tools, not to mention it doesn't do any pre-population of data so
you are left flying blind for the most part. In order to do anything
with the CLI tools you have to know LDIF syntax to add top-level entries.

To fix this I've created a Java LDAP GUI ( my senior project) to help
with administering and creating an OpenLDAP installation (it also works
with ADS and Sun Directory Server). I've continued to update it but
don't plan on releasing it for a while. I can send you screenshots if
you are interested. It's not a professional app but I have been working
on the interface as well as the design for the last year (and got an A
for the project too). I'm planning on taking another year of development
time before I'm satisfied enough to release it to the public.

brandon


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.