LDAP: 错误代码49-80090308:LdapErr:DSID-0C0903A9,注释:AcceptSecurityContext错误,数据52e,v1db1。

93

LDAP:错误代码49-80090308:LdapErr:DSID-0C0903A9,注释:AcceptSecurityContext错误,数据52e,v1db1

我知道"52e"代码是指用户名有效,但密码无效。在我的Apache Studio中,我使用相同的用户名和密码成功地建立了与LDAP的连接。

这是我的Java代码

    String userName = "*******";
    String password = "********";
    String base ="DC=PSLTESTDOMAIN,DC=LOCAL";
    String dn = "cn=" + userName + "," + base;  
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://******");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, dn);
    env.put(Context.SECURITY_CREDENTIALS, password);
    LDAPAuthenticationService ldap = new LDAPAuthenticationService();
   // LdapContext ctx;
    DirContext ctx = null;
    try {
        ctx = new InitialDirContext(env);

错误出现在这一行ctx = new InitialDirContext(env);

我不知道具体是什么原因导致了这个错误。

15个回答

1
LDAP尝试在向另一台服务器DB发送事务时使用AD进行身份验证。由于用户最近更改了密码,因此此身份验证失败,尽管使用先前的凭据生成了此事务。除非您将事务状态更改为“完成”或“取消”,否则此身份验证将继续失败...在这种情况下,LDAP将停止发送这些交易。

1
对我来说,问题已通过更改环境解决,如下所示:
 env.put("LDAP_BASEDN", base)
 env.put(Context.SECURITY_PRINCIPAL,"user@domain")

4
欢迎来到SO!请简要解释您的解决方案并相应地编辑您的问题。如需更多提示,请参阅https://stackoverflow.com/help/how-to-ask。 - B--rian

1
使用域名可能解决问题(使用PowerShell获取域名:$env:userdomain):
    Hashtable<String, Object> env = new Hashtable<String, Object>();
    String principalName = "domainName\\userName";
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://URL:389/OU=ou-xx,DC=fr,DC=XXXXXX,DC=com");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, principalName);
    env.put(Context.SECURITY_CREDENTIALS, "Your Password");

    try {
        DirContext authContext = new InitialDirContext(env);
        // user is authenticated
        System.out.println("USER IS AUTHETICATED");
    } catch (AuthenticationException ex) {
        // Authentication failed
        System.out.println("AUTH FAILED : " + ex);

    } catch (NamingException ex) {
        ex.printStackTrace();
    }

1
能否解释一下为什么使用域名是解决方案? - Itération 122442
我认为有些LDAP需要域名。如果我们只传递用户名,服务器将不会接受。 - Praveen Gopal

0
在我的情况下,我错误地配置了电子邮件凭据,然后进行了更正。
var passport = require('passport'),
    WindowsStrategy = require('passport-windowsauth'),
    User = require('mongoose').model('User');

module.exports = function () {
    passport.use(new WindowsStrategy({ldap: {
        url:            'ldap://corp.company.com:389/DC=corp,DC=company,DC=com',
        base:           'DC=corp,DC=company,DC=com',
        bindDN:         'myid@corp.company.com',
        bindCredentials:'password',
        tlsOptions: {
            ca: [fs.readFileSync("./cert.pem")],
          },
    }, integrated: false},
    function(profile, done) {
        console.log('Windows');
        console.log(profile);
        User.findOrCreate({
            username: profile.id
        }, function(err, user) {
            if (err) {
                return done(err);
            }

            if (!user) {
                return done(null, false, {
                    message: 'Unknown user'
                });
            }

            if (!user.authenticate(password)) {
                return done(null, false, {
                    message: 'Invalid password'
                });
            }

            return done(null, user);
        });
    }));
};

-1
请从用户名"mydomain\user"中删除域名,只保留"user"。不要加上域名和反斜杠。
请勿使用ldaps://examplehost:8080(因为需要证书,请勿在ldaps后面加s),请使用ldap://examplehost:8080,然后使用非TLS端口号。这对我有效。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接