Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Problems binding to LDAP

Reply
Thread Tools

Problems binding to LDAP

 
 
kevin wright
Guest
Posts: n/a
 
      11-06-2006

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");
}





}


}


 
Reply With Quote
 
 
 
 
kevin wright
Guest
Posts: n/a
 
      11-07-2006
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( 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/(E-Mail Removed)


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

 
Reply With Quote
 
 
 
 
kevin wright
Guest
Posts: n/a
 
      11-07-2006
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




On Tue, 07 Nov 2006 12:39:57 +0000, kevin wright wrote:

> 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( 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/(E-Mail Removed)
>
>
> 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


 
Reply With Quote
 
kevin wright
Guest
Posts: n/a
 
      11-07-2006
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.
 
Reply With Quote
 
Brandon McCombs
Guest
Posts: n/a
 
      11-10-2006
kevin wright wrote:
> 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?
>


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python-ldap/win32 or python/ldap/win32 rcmn Python 1 11-06-2006 11:47 PM
Need to wrtie LDAP class to *answer* LDAP queries. junk1@davidbevan.co.uk Java 1 02-21-2006 09:59 PM
ruby-ldap: uninitialized constant LDAP::LDAP_CONTROL_PAGEDRESULTS James Hughes Ruby 4 12-13-2005 11:46 PM
[ANN] Ruby/LDAP 0.9.1: LDAP API (RFC1823) library. Ian Macdonald Ruby 0 03-15-2005 11:23 PM
using LDAP Controls in ruby-ldap Jason Wold Ruby 5 11-07-2004 03:35 AM



Advertisments