我試圖讓我的應用程序來驗證存儲在OpenLDAP上的用戶。據我所知,沒有.NET的API,只有Java可用的庫。NET與OpenLDAP
我試過DirectorySetry與DirectorySearcher沒有成功,LDAPConnection也沒有工作。
有沒有人在類似的工作?
我試圖讓我的應用程序來驗證存儲在OpenLDAP上的用戶。據我所知,沒有.NET的API,只有Java可用的庫。NET與OpenLDAP
我試過DirectorySetry與DirectorySearcher沒有成功,LDAPConnection也沒有工作。
有沒有人在類似的工作?
// Search for a user
DirectoryEntry entry = new DirectoryEntry(
"LDAP://127.0.0.1/ou=People,dc=maxcrc,dc=com",
"cn=Manager, dc=maxcrc, dc=com ",
"secret",
AuthenticationTypes.FastBind
);
object obj = entry.NativeObject;
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(cn=agent001)";
searcher.PropertiesToLoad.Add("cn");
SearchResult result = searcher.FindOne();
if (result != null)
Console.WriteLine("Found");
else
Console.WriteLine("Not found");
這個怎麼樣了VB.NET中:
' for networkcredential
Imports System.Net
Imports System.DirectoryServices.Protocols.DirectoryConnection
Imports System.DirectoryServices.Protocols.LdapConnection
Imports System.DirectoryServices.Protocols.LdapDirectoryIdentifier
Public Function IsAuthenticated(ByVal username As String, ByVal pwd As String) As Boolean
' against OpenLDAP
Dim strLDAPServer As String = String.Empty
'users full DistinguishedName in OpenLDAP
Dim uid As String = "UID=" & username & _
",ou=People,dc=example,dc=com"
strLDAPServer = "my.openldapserver.com"
Dim ldapDirectoryIdentifier As New System.DirectoryServices.Protocols.LdapDirectoryIdentifier(strLDAPServer, 389, True, False)
Dim networkCredential As New NetworkCredential(uid, pwd)
Try
Dim ldap As New System.DirectoryServices.Protocols.LdapConnection(ldapDirectoryIdentifier, networkCredential)
ldap.SessionOptions.SecureSocketLayer = False
ldap.SessionOptions.ProtocolVersion = 3
ldap.AuthType = ldap.AuthType.Basic
ldap.Bind()
Catch lex As Exception
'Authentication fails - bad username or password
Return False
End Try
Return True
End Function
謝謝,我會試一試,讓你知道。 – Ted
如果指定了語言標記它會幫助,讓更多的人可以看到你的問題,並希望提供適當的答案。 –
我以爲.net就夠了。我的目標是獲得更具體的答案,而不是粘貼他們在Google上找到的內容的人...... :) – Ted
是的,但我必須添加.NET標記:) –