2010-02-03 7 views
2

"프록시 사용자"를 사용하여 LDAP 서버 (Active Directory, Novell 또는 기타)에 연결 한 다음 응용 프로그램에 로그인하려는 사용자가 입력했는지 확인하려고합니다 허용되는 사용자 이름과 암호로 나는 LDAP에 연결하는 코드를 얻었지만 사용자 이름과 암호를 확인하는 방법은별로 없다. LDAP 쿼리를 통해이 작업을 수행 할 수 있습니까?프록시 사용자를 사용하여 .NET에서 LDAP 인증

여기에 지금까지 내 코드의 배짱이다 : 나는 과거에 사용했던

Public Function Authenticate(ByVal UserName As String, ByVal Password As String) 

    Dim LDAPServer As String = ConfigurationManager.AppSettings("LDAPServer") 
    Dim proxyUsername As String = ConfigurationManager.AppSettings("LDAPProxyUser") 
    Dim proxyPassword As String = ConfigurationManager.AppSettings("LDAPProxyPassword") 

    Dim entry As DirectoryEntry 

    entry = New DirectoryEntry(LDAPServer, proxyUsername, proxyPassword) 

    'This performs the LDAP authentication' 
    Dim obj As Object = entry.NativeObject 

    Dim search As New DirectorySearcher(entry) 
    search.Filter = String.Format("(SAMAccountName={0})", UserName) 

    'How do I check the password now?' 

    Dim result As SearchResult = search.FindOne() 

    If result Is Nothing Then Throw New Exception("Unable to find SAMAccountName") 

답변

0

이 같은 인증을 시도했다하여 사용자에게 또 다른하여 DirectoryEntry 만들어 결국 :

Dim authEntry As DirectoryEntry 

authEntry = New DirectoryEntry(LDAPServer, UserName, Password) 

Dim authObj = authEntry.NativeObject 

을 바인딩 할 호출이 예외를 throw하는 경우에, 당신은 유효한 사용자가 없습니다 예외가 발생하면 사용자가 인증에 실패했습니다.

1

코드는 제공된 자격 증명을 사용하여 LDAP 바인딩을 시도합니다.

Dim servers() As String = New String(0) {"mylap.domain.com"} 
Dim con As New LdapConnection(New LdapDirectoryIdentifier(servers, True, False)) 
con.SessionOptions.SecureSocketLayer = True 
con.Credential = New Net.NetworkCredential("cn=" & userName, password) 
con.AuthType = AuthType.Basic 

Using con 
    con.Bind() 
End Using