meteorJS LDAP 身份验证无法完成成功绑定

meteorJS LDAP authentication cannot complete a successful bind

您好,我正在尝试为我的 meteorJS 应用程序设置 LDAP 身份验证,我正在按照此处列出的步骤进行操作 https://janikvonrotz.ch/2017/02/08/meteor-register-ldap-login-request-handler/

我将搜索过滤器从邮件更改为用户名,并将所有内容推送到 Meteor.startup() 这是我的代码设置

UI代码写在/imports/ui/loginform.jsx

let loginUserWithLDAP = (username, password, callback) => {
        var loginRequest = {
          ldap: true,
          username: username,
          email: username+"@company.com",
          pass: password,
        }
        Accounts.callLoginMethod({
          methodArguments: [loginRequest],
          userCallback: callback
        })
      }

在我的 /server/ldap.js

Meteor.startup(() => {

    var ldapAuth = {
        url: 'ldap://company.com:389',
        searchOu: 'ou=Employees,ou=\'company Users\', dc=company,dc=com',
        searchQuery: (username) => {
        return {
            filter: '(&(objectclass=user)(samaccountname='+username+'))',
            scope: 'sub'
        }
        }
    }

    ldapAuth.checkAccount = (options) => {
        options = options || {}
        ldapAuth.client = ldap.createClient({
            url: ldapAuth.url
        })
        let dn = ['company', 'com']
        var future = new Future()

        ldapAuth.client.search(
            ldapAuth.searchOu, 
            ldapAuth.searchQuery(options.username),
            (error, result)=> {
                assert.ifError(error)

                result.on('searchEntry', (entry) => {
                    dn.push(entry.objectName)
                    return ldapAuth.profile = {
                        firstname: entry.object.cn,
                        lastname: entry.object.sn
                    }
                })
                
                result.on('error', function(error){
                    throw new Meteor.Error(500, "LDAP server error")
                })

                result.on('end', function(){
                    if (dn.length === 0) {
                        future['return'](false)
                        return false
                    }

                    return ldapAuth.client.bind(dn[0], options.pass, (error) =>{
                        if (error){
                            future['return'](false)
                            return false
                        }

                        return ldapAuth.client.unbind((error) => {
                            assert.ifError(error)
                            return future['return'](!error)

                        });
                    })
                })
            })
        return future.wait()
    }

    Accounts.registerLoginHandler('ldap', (loginRequest)=>{
        if (!loginRequest.ldap) {
            return undefined
        }
    
        if (ldapAuth.checkAccount(loginRequest)){
            var userId = null
            var user = Meteor.users.findOne({"username": loginRequest.username })
            if (!user) {
                userId = Accounts.createUser({
                    username: loginRequest.username,
                    password: loginRequest.pass,
                    profile: ldapAuth.profile,
                    roles: ['user'],
                })
                Meteor.users.update(userId, { $set: { 'emails.0.verified': true } })
            } else {
                userId = user._id
            }
    
            let stampedToken = Accounts._generateStampedLoginToken()
            let hashStampedToken = Accounts._hashStampedToken(stampedToken)
            Meteor.users.update(userId, 
                { $push: {'services.resume.loginTokens': hashStampedToken } }
            )
    
            return {
                userId: userId,
                token: stampedToken.token
            }
        }
    })
});


在我的调试中我发现它在

处出错
result.on('error', function(error){
                    throw new Meteor.Error(500, "LDAP server error")
                })

由于'000004DC: LdapErr: DSID-0C0907E9, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v2580'这是什么意思?

我的代码缺少什么?

简而言之,您需要定义一个与 LDAP 目录进行绑定的搜索用户。

post 已经过时了,我给你这个例子:https://github.com/janikvonrotz/Zenkom/blob/0583f01abca96847178a248ff446d84c754965e9/server/actions/ldap.js#L18

像这样设置搜索用户:

"searchUser": {
    "dn": "CN=username,OU=org,DC=company,DC=ch",
    "password": "password"
  }

绑定用户只是为了搜索目录。执行另一个绑定以验证找到的用户。