How is an LDAP query encoded?

Discussion in 'Java' started by junk1@davidbevan.co.uk, Jun 5, 2006.

  1. Guest

    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
    , Jun 5, 2006
    #1
    1. Advertising

  2. dimitar Guest

    1. Advertising

  3. Guest

    , Jun 6, 2006
    #3
  4. Chris Riesbeck, Jun 6, 2006
    #4
  5. Urs Baer Guest

    I wrote a small ldapserver to test an application of mine. It is
    available at http://nirgends.ch/fahrabdap/index.html. Currently only a
    beta version is available. But it should give you an idea how the
    ldapprotocol works, and how it can be parsed.

    Urs

    wrote:
    > 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
    >
    Urs Baer, Jun 8, 2006
    #5
  6. Guest

    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

    Urs Baer wrote:
    > I wrote a small ldapserver to test an application of mine. It is
    > available at http://nirgends.ch/fahrabdap/index.html. Currently only a
    > beta version is available. But it should give you an idea how the
    > ldapprotocol works, and how it can be parsed.
    >
    , Jun 9, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    514
    Raymond DeCampo
    Feb 21, 2006
  2. Jorolat
    Replies:
    1
    Views:
    2,555
    John Dunlop
    Nov 18, 2006
  3. rcmn
    Replies:
    1
    Views:
    327
    =?ISO-8859-1?Q?Michael_Str=F6der?=
    Nov 6, 2006
  4. Jason Wold

    using LDAP Controls in ruby-ldap

    Jason Wold, Nov 4, 2004, in forum: Ruby
    Replies:
    5
    Views:
    228
  5. Ian Macdonald
    Replies:
    0
    Views:
    206
    Ian Macdonald
    Mar 15, 2005
Loading...

Share This Page