【问题标题】:How to get DN and password with UnboundID如何使用 UnboundID 获取 DN 和密码
【发布时间】:2012-09-26 07:30:28
【问题描述】:

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

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

    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 文档,但找不到任何我需要的简单示例。

另外,我不太确定 CannedResponseRequestHandler 的实用性。满足我的需要,够吗?

另一个问题:我不确定,但我感觉我的服务器没有在监听或者我什么都没有(当我连接到 ldap 浏览器时,什么都没有发生)。有什么想法/建议吗?

谢谢,祝你有美好的一天!

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

公共类 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的子类:

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

}

再次感谢!

【问题讨论】:

  • 试图嗅出人们的密码?
  • 不,我只需要用户名和密码就可以将它们放到一个网络服务上,看看人们是否被授权。
  • 但这就是 LDAP 服务器的用途!你的问题还没有意义。
  • 我不太了解@EJP。我只需要获取用户名和密码。有了它,我可以与我的 Web 服务进行交互。我不能做别的事,这是我老板的决定:)

标签: java ldap openldap unboundid-ldap-sdk


【解决方案1】:

许多 LDAP 服务器实现不会返回密码,并且许多不会返回您可以使用的密码。 (即它可能是一个哈希)。

我会很好奇为什么有理由返回密码。

-吉姆

【讨论】:

    【解决方案2】:

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

    如果request 是您的BindRequestProtocolOp 实例,那么您可以通过以下方式获取信息:

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

    【讨论】:

    • 非常感谢@xhochy,我今天会检查一下! :)
    • CannedResponseRequestHandler 不能被子类化(它是最终的)。所以我尝试了 LDAPListenerRequestHandler 并且它可以。我重写以显示绑定,但似乎缺少一些东西,我的 ldap 浏览器不与服务器通信。
    • 另一个尝试:您可以直接继承 LDAPListenerRequestHandler 并为所有其他抽象方法添加空实现。
    • 好的,所以我重写了 LDAPListenerRequestHandler 以显示密码和用户名,它可以正常工作(与 Softerra 不完美,但仍然如此)。我花了很长时间才理解的是我需要重写 newInstance() 并返回它。我将在我的问题中发布代码。非常感谢 xhochy!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-08
    • 2010-11-11
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    相关资源
    最近更新 更多