1

I have setup LDAP server in my local system by this link How To Install and Configure a Basic LDAP Server . I mange to get LDAP server run and able to add group, user, etc through phpldapadmin. I have added a user as shown in this imageenter image description here

To confirm the user in LDAP server I used below command

$ ldapsearch -x -W -D 'cn=thiru niren,cn=users,ou=group,dc=test,dc=com' -b "" -s base -H ldap://192.168.2.4

It asked me for password then I entered password and I get result

Enter LDAP Password: 
# extended LDIF
#
# LDAPv3
# base <> with scope baseObject
# filter: (objectclass=*)
# requesting: ALL
#

#
dn:
objectClass: top
objectClass: OpenLDAProotDSE

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

Then I tried to use passport-ldapauth module. Code I have written for this is

var LdapStrategy = require('passport-ldap').Strategy,
    passport = require('passport');

passport.use(new LdapStrategy({server: {
              url: 'ldap://192.168.2.4',
        adminDn:'cn=thiru niren,cn=users,ou=group,dc=test,dc=com',
        adminPassword: 'infra'
        }},
        function(user, done) {
            console.log("user authenticated or not");
            return done(null, user);
        }
));
console.log("check ldap");

After I execute this code, I see only check ldap and a keep on blinking cursor in terminal. Then I put up console.log("user authenticated or not"); to verify whether LdapStrategy is call callback function or not but I don't see user authenticated or not in console but check ldap. What would be the problem? why passport-ldapaut is don't get any response from ldap server?

I'm using ubuntu 14.04 LTS. node --version is v0.10.28.

Update: I tried with ldapauth module as well but no luck I get same result, check my modified code of above mentioned website

var connect = require('connect');
var LdapAuth = require('ldapauth');

// Config from a .json or .ini file or whatever.
var config = {
  ldap: {
    url: "ldap://192.168.2.4:389",
    adminDn: "cn=thiru niren,cn=users,ou=group,dc=test,dc=com",
    adminPassword: "infra",
    searchBase: "ou=group,dc=test,dc=com",
    searchFilter: "(uid=tniren)"
  }
};

var ldap = new LdapAuth({
  url: config.ldap.url,
  adminDn: config.ldap.adminDn,
  adminPassword: config.ldap.adminPassword,
  searchBase: config.ldap.searchBase,
  searchFilter: config.ldap.searchFilter,
  //log4js: require('log4js'),
  cache: true
});
//console.log("we here",ldap);
var basicAuthMiddleware = connect.basicAuth(function (username, password, callback) {
    console.log("we");
  ldap.authenticate(username, password, function (err, user) {
    console.log("we are");
    if (err) {
      console.log("LDAP auth error: %s", err);
    }
    callback(err, user)
  });
});

Here also I don't get any response from ldap server, is there any problem with server?

Mudassar
  • 3,135
  • 17
  • 22
niren
  • 2,693
  • 8
  • 34
  • 58

0 Answers0