How to get DN and password with UnboundID

China☆狼群 提交于 2019-12-08 02:15:43

问题


I need some help concerning UnboundID. I heard it was a great choice but I'm not really used to it.

So I need to make a LDAP listener. On this listener, i should be able to catch bind request (from a ldap browser for example). I wonder how to get the DN and the password. Here is my code for the LDAP listener:

    public ResultCode CreateLdapServer () throws LDAPException {
       CannedResponseRequestHandler requestHandler = new CannedResponseRequestHandler();
    LDAPListenerConfig config =
             new LDAPListenerConfig(4243, requestHandler);
      try
      {
        config.setListenAddress(
             InetAddress.getByName("localhost"));
      }
      catch (final Exception e)
      {
        System.err.println("Unable to create the listen server.");
        return ResultCode.PARAM_ERROR;
      }

    listener = new LDAPListener(config);

    try
    {
      listener.startListening();
      System.out.println("Serveur is listening ...");
    }
    catch (final Exception e)
    {
        System.err.println("Unable to start listening.");
      return ResultCode.LOCAL_ERROR;
    }
    return ResultCode.SUCCESS;
}

public static void main(String[] args) throws LDAPException {
    MyConnection connect = new MyConnection();
    connect.CreateLdapServer();
}

I read a lot of UnboundID documentation, but i can't find any simple example of what I need.

Also, i'm not really sure of the utility of CannedResponseRequestHandler. For what i need, is it enough ?

An other question: I'm not sure, but I have the feeling that my server is not listening OR i don't catch anything (when I connect with a ldap Browser, nothing happened). Any Idea / Suggestion ?

Thanks and have a nice day !

EDIT : Thanks to xhochy, I was able to catch the password and the username. As he said, I subclassed LDAPListenerRequestyHandler to override, first, newInstance then ProcessBindRequest. Here is the code (it's absolutely not perfect and it's still a beginning).

public class MyConnection {

private LDAPListener listener;

public MyConnection(){
}

public ResultCode CreateLdapServer() throws LDAPException {
    MyLDAPListenerRequestHandler requestHandler = new MyLDAPListenerRequestHandler();
    LDAPListenerConfig config =
             new LDAPListenerConfig(4243, requestHandler);
      try
      {
        config.setListenAddress(
             InetAddress.getByName("localhost"));
      }
      catch (final Exception e)
      {
        System.err.println("Unable to create the listen server.");
        return ResultCode.PARAM_ERROR;
      }

    listener = new LDAPListener(config);

    try
    {
      listener.startListening();
      System.out.println("Serveur is listening ...");
    }
    catch (IOException e)
    {
        System.err.println("Unable to start listening.");
      return ResultCode.LOCAL_ERROR;
    }


    return ResultCode.SUCCESS;
}

public static void main(String[] args) throws LDAPException {
    MyConnection connect = new MyConnection();
    connect.CreateLdapServer();
}

}

Then the subclass of LDAPListenerRequestHandler:

public class MyLDAPListenerRequestHandler extends LDAPListenerRequestHandler {

@Override
public LDAPListenerRequestHandler newInstance(
        LDAPListenerClientConnection arg0) throws LDAPException {
        System.out.println("New Instance.");
        LDAPConnectionOptions option = new LDAPConnectionOptions();
        LDAPConnection connection = new LDAPConnection(option, "yourIPadress", yourport);
        System.out.println("Connected to : " + connection.getConnectedAddress()+ " " + connection.getConnectedPort());

    return this;
}

@Override
public LDAPMessage processBindRequest(int arg0, BindRequestProtocolOp arg1,
        List<Control> arg2) {
    System.out.println(arg1.getBindDN());
    System.out.println(arg1.getSimplePassword());
    return null;
}

}

Thanks again !


回答1:


You should subclass LDAPListenerRequestHandler and implement processBindRequest. All the information you are looking for is included in BindRequestProtocolOp (second argument of processBindRequest). Add an empty implementation for all other abstract methods.

If request is your BindRequestProtocolOp instance then you get your information via:

String username = request.getBindDN();
ByteString password = request.getSimplePassword();



回答2:


Many LDAP server implementations will not return a password and many will not return a password you can use. (ie it maybe a hash).

I would be very curious why there could be a reason to return the password.

-jim



来源:https://stackoverflow.com/questions/12596708/how-to-get-dn-and-password-with-unboundid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!