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

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

我知道“52e”代码是当用户名是有效的,但密码是无效的。我在我的 apache 工作室使用相同的用户名和密码,我能够成功地建立到 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);

我不知道到底是什么导致了这个错误。

502123 次浏览

资料52e-当用户名有效但密码/凭据无效时返回。

你可能需要

String dn = "cn=" + userName + "," + "CN=Users," + base;

当用户名有效但密码/凭据无效时返回。将防止大多数其他错误按照指示显示。

Http://ldapwiki.com/wiki/common%20active%20directory%20bind%20errors

对我来说,当我像这样设置主体部分时,问题就解决了:

env.put(Context.SECURITY_PRINCIPAL, userId@domainWithoutProtocolAndPortNo);

LDAP 试图在将事务发送到另一个服务器 DB 时使用 AD 进行身份验证。此身份验证失败,因为用户最近更改了密码,尽管此事务是使用以前的凭据生成的。除非将事务状态更改为“完成”或“取消”,否则此身份验证将一直失败,直到... 为止,在这种情况下,LDAP 将停止发送这些事务。

我在 CAS 上使用 AD 时遇到了类似的问题,即52e 错误,在我的例子中,应用程序接受 CN = 而不是实际用户名形式的全名。

例如,如果有一个用户的全名是 Ross Butler,而他们的登录用户名是 rbutler,那么通常会输入这样的内容: cn = rbutler,ou = Users,dc = domain,dc = com,但是我们每次都会失败。通过将其更改为 cn = Ross Butler,ou = Users,dc = domain,dc = com,它通过了! !

在我的例子中,我必须使用类似 <username>@<domain>的东西才能成功登录。

sample_user@sample_domain

当使用 Context.SECURITY _ AUTHENTATION 作为“ simple”时,需要提供 userPrincipalName 属性值(user@domain _ base)。

对我来说,这个问题是通过在用户名中添加域名来解决的,如下所示:

string userName="yourUserName";
string password="passowrd";
string hostName="LdapServerHostName";
string domain="yourDomain";
System.DirectoryServices.AuthenticationTypes option = System.DirectoryServices.AuthenticationTypes.SecureSocketsLayer;
string userNameWithDomain = string.Format("{0}@{1}",userName , domain);
DirectoryEntry directoryOU = new DirectoryEntry("LDAP://" + hostName, userNameWithDomain, password, option);

如果您调试并查看 ctx = null,可能您的用户名有问题,您应该这样写 “ ac 管理员”(双)或“管理员@ac”

对我来说,这个问题可以通过这样的改变来解决:

 env.put("LDAP_BASEDN", base)
env.put(Context.SECURITY_PRINCIPAL,"user@domain")

使用域名可以解决这个问题(使用 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();
}

对我来说,问题的原因是用户名的格式不正确。它早先被指定为“ mydomain 用户”。我删除了域部分,错误消失了。

另外,我正在使用 ServerBind 身份验证。

我测试了三种不同的方法,它们都奏效了:

env.put(Context.SECURITY_PRINCIPAL, "user");
env.put(Context.SECURITY_PRINCIPAL, "user@domain.com");
env.put(Context.SECURITY_PRINCIPAL, "CN=user,OU=one,OU=two,DC=domain,DC=com");

如果使用最后一个,不要忘记将所有 OU 设置为用户所属的位置。否则就没用了。

在我的情况下,我错误配置了电子邮件凭证,然后我纠正

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);
});
}));
};

请从用户名“ mydomain user”中删除域名。请只输入“ user”。不要输入域名和反斜杠。

您不使用 ldaps://examplehost: 8080(不要与 ldaps 一起使用 s,因为需要证书) ,然后使用 使用 ldap://examplehost: 8080