Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Before running this script, set the LDAP_PASSWORD environment variable in
- // the shell. You can do this without echoing the password by running:
- //
- // read -s LDAP_PASSWORD && export LDAP_PASSWORD
- //
- // You'll also need to modify the variable definitions at the top of this file.
- // == BEGIN configuration variables ===============
- var url = "ldap://adtest.rstudio.com/dc=adtest,dc=rstudio,dc=com";
- var username = "john";
- var suffix = "adtest.rstudio.com";
- var search_base = "cn=Users,dc=adtest,dc=rstudio,dc=com";
- var search_filter = "(member:1.2.840.113556.1.4.1941:=CN=John Doe,CN=Users,DC=adtest,DC=rstudio,DC=com)";
- // == END configuration variables =================
- var username = username + "@" + suffix;
- var password = process.env.LDAP_PASSWORD;
- if (!password) {
- console.error("LDAP_PASSWORD not set. Set it by calling 'read -s LDAP_PASSWORD && export LDAP_PASSWORD' from the shell.");
- process.exit(1);
- }
- var ldapjs = require("ldapjs");
- var client = ldapjs.createClient({url: url});
- client.bind(username, password, function(err) {
- if (!err) {
- console.error("Successful bind.");
- var opts = {
- scope: "sub",
- filter: search_filter,
- attributes: ["dn"]
- };
- client.search(search_base, opts, function(err, res) {
- if (err) {
- console.error("Error performing search:");
- console.error(err);
- process.exit(1);
- }
- res.on('searchEntry', function(entry) {
- console.log('entry: ' + JSON.stringify(entry.object));
- });
- res.on('searchReference', function(referral) {
- console.log('referral: ' + referral.uris.join());
- });
- res.on('error', function(err) {
- console.error('error: ' + err.message);
- });
- res.on('end', function(result) {
- console.log('status: ' + result.status);
- client.unbind();
- });
- });
- } else {
- console.error(err);
- process.exit(1);
- }
- });
Add Comment
Please, Sign In to add comment