這是我第一次使用LDAP和Active Directory。我必須用.NetCore製作一個必須使用ActiveDirectory(Windows Server 2008 R2)進行身份驗證的web api,我正在關注Novell.Directory.Ldap.NETStandard中的示例,但我無法理解必須設置參數的方式。 這是我在ActiveDirectory中Server創建的用戶:使用Novell.Directory.Ldap.NETStandard庫的C#netcore ldap認證
在Novell的樣品
if (args.Length != 5)
{
System.Console.Out.WriteLine("Usage: mono VerifyPassword <host name>" + " <login dn> <password> <object dn>\n" + " <test password>");
System.Console.Out.WriteLine("Example: mono VerifyPassword Acme.com " + "\"cn=Admin,o=Acme\" secret\n" + " \"cn=JSmith,ou=Sales,o=Acme\" testPassword");
System.Environment.Exit(0);
}
int ldapPort = LdapConnection.DEFAULT_PORT;
int ldapVersion = LdapConnection.Ldap_V3;
System.String ldapHost = args[0];
System.String loginDN = args[1];
System.String password = args[2];
System.String objectDN = args[3];
System.String testPassword = args[4];
LdapConnection conn = new LdapConnection();
try
{
// connect to the server
conn.Connect(ldapHost, ldapPort);
// authenticate to the server
conn.Bind(ldapVersion, loginDN, password);
LdapAttribute attr = new LdapAttribute("userPassword", testPassword);
bool correct = conn.Compare(objectDN, attr);
System.Console.Out.WriteLine(correct?"The password is correct.":"The password is incorrect.\n");
// disconnect with the server
conn.Disconnect();
}
在Novell的樣本 「用戶」 的參數看起來是這樣的「OU =銷售額,O = Acme的」所以我想:
int ldapPort = LdapConnection.DEFAULT_PORT;
int ldapVersion = LdapConnection.Ldap_V3;
bool compareResults = false;
String ldapHost = "192.168.58.251";
String loginDN = @"cn=jperez";
String password1 = "Jperez123";
String dn = "mydn";
LdapConnection lc = new LdapConnection();
LdapAttribute attr = null;
try
{
// connect to the server
lc.Connect(ldapHost, ldapPort);
var sdn = lc.GetSchemaDN();
// authenticate to the server
lc.Bind(ldapVersion, loginDN, password1);
...
}
catch (LdapException e)
{
Console.WriteLine("Error: " + e.ToString());
}
但我得到這個錯誤: LDAP:
LdapException: Invalid Credentials (49) Invalid Credentials LdapException: Server Message: 80090308: LdapErr: DSID-0C0903A8, comment: AcceptSecurityContext error, data 52e, v1db1\u0000 LdapException: Matched DN:
我也有這個功能可按得到schemaDn:lc.GetSchemaDN()
,返回結果如下:CN=Aggregate,CN=Schema,CN=Configuration,DC=mydn,DC=local
谷歌搜索有一個與.Netcore
比Novell's samples
沒有太多的信息後,請我需要你的幫助。