Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: a.b.c.d.e
  • 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
);
like image 902
jake Avatar asked Jul 23 '10 14:07

jake


People also ask

How do you create a query in LDAP?

To create an LDAP queryBrowse the Directory manager tree and select an object in the LDAP directory. The query that you're creating will return results from this point in the tree down. Click the New LDAP query toolbar button. Type a descriptive name for the query.

How do I query an LDAP server?

The easiest way to search LDAP is to use ldapsearch with the “-x” option for simple authentication and specify the search base with “-b”. If you are not running the search directly on the LDAP server, you will have to specify the host with the “-H” option.

How does LDAP query work?

An LDAP server, also called a Directory System Agent (DSA), runs on Windows OS and Unix/Linux. It stores usernames, passwords, and other core user identities. It uses this data to authenticate users when it receives requests or queries and shares the requests with other DSAs.

Does LDAP have an API?

The LDAP APIs are designed to provide a suite of functions that can be used to develop directory enabled applications. Directory-enabled applications typically connect to one or more directories and perform various directory-related operations, such as: Adding entries.


2 Answers

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.

like image 167
selfawaresoup Avatar answered Sep 27 '22 16:09

selfawaresoup


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.

like image 37
Ingmar Hupp Avatar answered Sep 27 '22 17:09

Ingmar Hupp