【发布时间】: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