简体   繁体   中英

How do I do an LDAP query with JavaScript?

I'm trying to make a sidebar gadget that has an LDAP query function but haven't been able to find very good, or any, useful documentation on the matter. I'm not hugely experienced with Javascript and know little to nothing about how LDAP queries function, so any information at all would be useful.

info:

  • host: abcde
  • port: 389
  • ou: people
  • o: x_y_z
  • c: us

first snippet:

var sSearchURL = "ldap://a.b.c.d.e:389/o=x_y_z,c=us";
var URLsuffix = "dc=" + form.SearchData.value;
document.location = sSearchURL URLsuffix;

other snippet:

var ldap = GetObject('LDAP:');
var ad = ldap.OpenDSObject(
  'LDAP://a.b.c.d.e:389/o=x_y_z',
  'cn=Administrator,ou=People,o=rootname',
  'password',
  0
);

As long as you want to run your JavaScript in a web browser, you are limited to the HTTP protocol and to the domain from which your script was loaded in the first place.

So, talking to an LDAP server will not be possible from a web browsers JavaScript engine.

There are JavaScript runtime environments that have less limitations where you can implement socket servers and clients. For LDAP conenctivity you'd have to write your own library or find some existing one.

You could write a proxy web service that translates your HTTP requests into LDAP queries, forwards them to an LDAP server and returns the results back to you. Of course that'd have both security and scalability implications and is far from trivial.

As Selfawaresoup already mentioned there are limitations to perfoming this on client side alone, however, if you're able to host your application/page on nodejs you can utilise an LDAP plugin with it.

Links to nodejs are as follows: https://nodejs.org/en/ https://nodejs.org/en/download/

Nodejs LDAP plugin: http://ldapjs.org/

Instruction on setting up nodejs to serve http: https://www.sitepoint.com/build-a-simple-web-server-with-node-js/ https://blog.risingstack.com/your-first-node-js-http-server/

Although it's for a specific application here's a manual demonstrating the integration of LDAP query via nodejs: https://www.ibm.com/developerworks/library/se-use-ldap-authentication-authorization-node.js-bluemix-application/index.html

Here's a working demo of it (note this is for querying public facing LDAP servers): https://login-using-ldap.mybluemix.net/

Best of luck to you however you resolve this.

I am not sure answer 1 is correct. Domain would be limited to client's domain for an active directory ldap query. However, LDAP://server is not limited to just local domain. Its limited to 'reachable' domains. If you can ping it you should be able to query it, given proper credentials.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM