问题描述
我需要一些关于 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, listarg2) { 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();