java - InMemoryDirectoryServer, processing requests (bind,modify,etc.) -
i'm using inmemorydirectoryserver unboundid sdk. how process ldap requests ldap client?
here's code found (at how dn , password unboundid):
public class myldaplistenerrequesthandler extends ldaplistenerrequesthandler { @override public ldaplistenerrequesthandler newinstance( ldaplistenerclientconnection arg0) throws ldapexception { system.out.println("new instance."); ldapconnectionoptions alternative = new ldapconnectionoptions(); ldapconnection connection = new ldapconnection(option, "youripadress", yourport); system.out.println("connected : " + connection.getconnectedaddress()+ " " + connection.getconnectedport()); homecoming this; } @override public ldapmessage processbindrequest(int arg0, bindrequestprotocolop arg1, list<control> arg2) { system.out.println(arg1.getbinddn()); system.out.println(arg1.getsimplepassword()); homecoming null; }
is proper way capture bind reqest , process under
public ldapmessage processbindrequest(int arg0, bindrequestprotocolop arg1, list<control> arg2) {
function? after processing, have manually send bind inmemorydirectoryserver instance?
hi again,
based on: http://sourceforge.net/p/ldap-sdk/discussion/1001257/thread/796c129d
it looks me possible modify inmemoryrequesthandler source , alter how replies ldap requests (search,modify,...).
for alias dereferencing, modified
for (final searchresultentry e : entrylist)
loop in function:
public synchronized ldapmessage processsearchrequest(final int messageid, final searchrequestprotocolop request, final list controls) {
with code:
for (final searchresultentry e : entrylist) { // flag set if loop finds alias entry. boolean aliasentryfound = false; // aliasedobjectname reference real entry. string aliasedobjectname = null; // check dereferencing turned on. if (aliasderef) { // check if entry alias entry. (string objectclass : e.getattributevalues("objectclass")) { if (objectclass.equalsignorecase("alias")) { // set on flag. aliasentryfound = true; // real entry path. aliasedobjectname = e.getattributevalue("aliasedobjectname"); } } } // if entry e alias entry, ... if (aliasentryfound && aliasedobjectname != null) { // build new searchrequest query aliasedobjectname real dn. final searchrequestprotocolop newrequest = new searchrequestprotocolop( aliasedobjectname, request.getscope(), request.getderefpolicy(), request.getsizelimit(), request.gettimelimit(), false, request.getfilter(), request.getattributes()); // phone call recursively processsearchrequest() new request value. processsearchrequest(messageid, newrequest, controls); } else { seek { connection.sendsearchresultentry(messageid, e, e.getcontrols()); } grab (final ldapexception le) { debug.debugexception(le); homecoming new ldapmessage(messageid, new searchresultdoneprotocolop(le.getresultcode().intvalue(), le.getmatcheddn(), le.getdiagnosticmessage(), staticutils.tolist(le.getreferralurls())), le.getresponsecontrols()); } } } ... }
somewhere @ origin of inmemoryrequesthandler class, added:
private boolean aliasderef = true;
which utilize flag command if want alias dereferencing or not.
my code illustration how alias dereferencing on search request. custom request handler, possible alert ldap requests, not ldap replies or results.
let me know if there improve way of doing this. thanks
the unboundid ldap sdk java provides ldaplistener framework allows create own code accepts ldap requests clients , can provide responses them. when ldaplistener receives request, uses ldaplistenerrequesthandler process request , generate result.
the in-memory directory server uses inmemoryrequesthandler perform processing, can create own request handler implementation whatever want (e.g., cannedresponserequesthandler bindly returns fixed response request), , can have request handler processing before delegating request handler (e.g., accesslogrequesthandler , ldapdebuggerrequesthandler implementations intercept requests , write info them log file before forwarding them on request handler, , intercepts , logs info response before returning client; conversely, proxyrequesthandler processing directory server on ldap).
if want provide custom processing, should create own ldaplistenerrequesthandler subclass (and assumed, processbindrequest method can used perform processing bind operation). if request handler processing operation, can create , homecoming response yourself. if need intercept request , capture info before forwarding on else perform processing, should delegate request handler. there examples of both of in ldap sdk, can utilize them model create need.
java ldap unboundid-ldap-sdk
No comments:
Post a Comment