如何使用 JavaScript 执行 LDAP 查询?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3319249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I do an LDAP query with JavaScript?
提问by jake
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.
我正在尝试制作一个具有 LDAP 查询功能的侧边栏小工具,但无法找到非常好的或任何有用的文档。我对 Javascript 的经验并不丰富,对 LDAP 查询的功能知之甚少,因此任何信息都是有用的。
info:
信息:
- host: a.b.c.d.e
- port: 389
- ou: people
- o: x_y_z
- c: us
- 主持人:abc
- 端口:389
- 欧:人
- o: x_y_z
- 丙:我们
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
);
回答by selfawaresoup
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.
只要您想在 Web 浏览器中运行 JavaScript,您就受限于 HTTP 协议和最初加载脚本的域。
So, talking to an LDAP server will not be possible from a web browsers JavaScript engine.
因此,无法从 Web 浏览器的 JavaScript 引擎与 LDAP 服务器通信。
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.
有一些限制较少的 JavaScript 运行时环境,您可以在其中实现套接字服务器和客户端。对于 LDAP 连接性,您必须编写自己的库或找到一些现有的库。
回答by Ingmar Hupp
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.
您可以编写一个代理 Web 服务,将您的 HTTP 请求转换为 LDAP 查询,将它们转发到 LDAP 服务器并将结果返回给您。当然,这对安全性和可扩展性都有影响,而且绝非易事。
回答by Beavatron Prime
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.
正如 Selfawaresoup 已经提到的那样,单独在客户端执行此操作是有限制的,但是,如果您能够在 nodejs 上托管您的应用程序/页面,您可以使用 LDAP 插件。
Links to nodejs are as follows: https://nodejs.org/en/https://nodejs.org/en/download/
nodejs链接如下:https ://nodejs.org/en/ https://nodejs.org/en/download/
Nodejs LDAP plugin: http://ldapjs.org/
Nodejs LDAP 插件: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/
设置 nodejs 服务 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
虽然它是针对特定应用程序的,但这里有一个手册,演示了通过 nodejs 集成 LDAP 查询:https://www.ibm.com/developerworks/library/se-use-ldap-authentication-authorization-node.js-bluemix-application/ 索引.html
Here's a working demo of it (note this is for querying public facing LDAP servers): https://login-using-ldap.mybluemix.net/
这是它的一个工作演示(请注意,这是用于查询面向公众的 LDAP 服务器):https: //login-using-ldap.mybluemix.net/
Best of luck to you however you resolve this.
祝你好运,但你解决了这个问题。
回答by TOwen
I am not sure answer 1 is correct. Domain would be limited to client's domain for an active directoryldap 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.
我不确定答案 1 是否正确。对于活动目录ldap 查询,域将被限制为客户端的域。但是,LDAP://server 不仅限于本地域。它仅限于“可访问”域。如果您可以 ping 它,您应该能够查询它,并提供适当的凭据。

