How is an LDAP query encoded?

J

junk1

I have got a propritry user directory based on DB2 which I am trying to
expose to LDAP - ie I want LDAP clients to be able to look up (simple)
user and group information directly from my DB2 tables.

I have got a simple test class which listens on the LDAP port and
displays the bytes that come in.(using ServerSocket ssock = new
ServerSocket(389) etc).

Inially what I got when I tried a dummy LDAP connection was garbage
until I read that I would need to use Apache commons to convert these
bytes to something meaningful. Unfortunatly what I now get out is
this...

[3, 0, 8, 4, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 1, 0, 1, 6, 0, 8, 4, 0,
0, 0, 0, 0, 0, 0, 7, 0, 2, 0, 1, 0, 3, 0, 4, 0, 0, 8, 0, 0, 0, 3, 0, 8,
4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 2, 0, 1, 0, 2, 4, 2, 0, 0]

....how do I get the input into something meaninful like the actual LDAP
query (ie (&(uid=dbevan) (o=jlp)))?

Heres the code so far...

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

import org.apache.commons.codec.binary.Hex;
public class tcpserver
{
public static void main(String args[]) throws Exception
{
String message;
String messageout;
ServerSocket ssock = new ServerSocket(389);
while(true)
{
Socket connsock = ssock.accept();
InputStreamReader instr =
new InputStreamReader(connsock.getInputStream());
DataOutputStream outstr =
new DataOutputStream(connsock.getOutputStream());
BufferedReader innet = new BufferedReader(instr);
message = innet.readLine();
char charArray[] = Hex.encodeHex(message.getBytes());
messageout = message.toUpperCase() + "\n";
System.out.println("SERVER:- " + messageout);
outstr.writeBytes(messageout);
}
}
}



Thanks

David Bevan
http://www.davidbevan.co.uk
 
J

junk1

Thanks, this looks like exactly what I need to get me started.

I have downloaded the source and got the server running, however im not
sure that I understand the backend you have written. I have created the
following file\dir structure.

c:\misc\060608\dir\o=configuration\ou=aaa\cn

(Having changed the config to point at the c:\misc\060608\dir
directory)

....but cant seem to find the entry when I search for it. the search I
am doing (although I have tried may other permutations) is...

NamingEnumeration results = ctx.search("", "ou=aaa,o=configuration",
searchControls);

I was expecting to get back a NamingEmumeration which would contain an
element with an ID of 'cn' and a value of 'David Bevan' (as this is the
contents of the cn file)

Have I misunderstood the way the server works?

Any help would be much appreciated.

Thanks

David Bevan

http://www.davidbevan.co.uk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top