如何使用UnboundID获取DN和密码 [英] How to get DN and password with UnboundID

查看:234
本文介绍了如何使用UnboundID获取DN和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些关于UnboundID的帮助。我听说这是一个很好的选择,但我并不习惯。

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

所以我需要建立一个LDAP监听器。在这个监听器上,我应该能够捕获绑定请求(例如来自ldap浏览器)。我想知道如何获取DN和密码。以下是我的LDAP侦听器代码:

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

我读了很多UnboundID文档,但我找不到任何简单的我需要的例子。

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

另外,我不太确定CannedResponseRequestHandler的实用程序。对于我需要的,这还够吗?

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

另一个问题:我不确定,但我觉得我的服务器没有听,或者我没有抓住任何东西(当我用ldap浏览器连接时,什么也没发生)。任何想法/建议?

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 !

编辑:感谢xhochy,我能够捕获密码和用户名。正如他所说,我将LDAPListenerRequestyHandler子类化为覆盖,首先是newInstance,然后是ProcessBindRequest。这是代码(它绝对不完美,它仍然是一个开始)。

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).

公共类MyConnection {

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

}

然后是LDAPListenerRequestHandler的子类:

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

}

再次感谢!

推荐答案

您应该继承 LDAPListenerRequestHandler 并实施 processBindRequest 。您要查找的所有信息都包含在 BindRequestProtocolOp 中( processBindRequest 的第二个参数)。为所有其他抽象方法添加一个空实现。

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.

如果 request 是你的 BindRequestProtocolOp 实例然后您通过以下方式获取您的信息:

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

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

这篇关于如何使用UnboundID获取DN和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆