gpt4 book ai didi

java - 如何使用 UnboundID 获取 DN 和密码

转载 作者:行者123 更新时间:2023-11-30 06:28:24 26 4
gpt4 key购买 nike

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

所以我需要制作一个 LDAP 监听器。在这个监听器上,我应该能够捕获绑定(bind)请求(例如来自 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。这是代码(它绝对不完美,它仍然是一个开始)。

公共(public)类 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 服务器实现不会返回密码,许多也不会返回您可以使用的密码。 (即它可能是一个散列)。

我很好奇为什么要返回密码。

-吉姆

关于java - 如何使用 UnboundID 获取 DN 和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12596708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com