2013-02-19 8 views
1

사용자의 고유 이름을 사용하여 사용자의 유효성을 검사하기 위해 찾은 사용자에게 리 바인드하는 작동중인 LDAP 코드가 있습니다. 효과적으로이 일어나고있는 것입니다 :OpenLdap 고유 이름의 이스케이프 된 문자로 된 C# 바인딩

  string userDn = @"cn=Feat Studentl+umanroleid=302432,ou=Faculty of Engineering & Physical Sciences Administration,ou=Faculty of Engineering & Physical Sciences,ou=People,o=University of TestSite,c=GB"; 
      string fullPath = @"LDAP://surinam.testsite.ac.uk:636/" + userDn; 

      DirectoryEntry authUser = new DirectoryEntry(fullPath, userDn, "mypassword", AuthenticationTypes.None); 

      authUser.RefreshCache(); 

그러나 이것은 내가 문제가 DN이있는 '+'와 '='고 수 있습니다 의심

DirectoryEntry.Bind()에서 오류 알 수없는 오류 80005000가 발생 CN 속성에. 따라서이 탈출 할 수있는 방법은 \와 문자의 16 진수 값으로해야한다는 찾은 후 나는이 시도 :

  string userDn = @"cn=Feat Studentl\2Bumanroleid\3D302432,ou=Faculty of Engineering & Physical Sciences Administration,ou=Faculty of Engineering & Physical Sciences,ou=People,o=University of TestSite,c=GB"; 

나는 오류 얻을 그러나 :

로그인 실패 : 알 수없는 사용자 이름 또는 잘못된을 암호

나는 이것이 요청에 만족하지만 사용자 DN과 일치하지 않는 이유로 간주합니다.

어딘가에 있습니까?

답변

1

내 경험 LDAP 서비스를 개발할 때 잘못된 자격 증명으로 인해 로그인이 실패 할 때마다 이 바인드 시도에 문제가되는 경향이 있습니다. DirectoryEntry가 DN의 이스케이프 된 문자를 구문 분석하지 않기 때문에 오류가 발생합니다 ... 그러나 처음부터 그렇게하지 않아도됩니다.

코드에서 AuthenticationTypes를 "None"으로 설정하면 항목에서 제공하는 DN을 기준으로 Simple bind를 만듭니다. 당신이 경로의 일부로 서버 이름을 포함하기 때문에,이 같은 대신 ServerBind의 인증 유형을 사용하려고 할 것입니다 : 당신이 보안 LDAP 포트에이 호출 (636 만들고있는 것처럼

string LdapPath = ("LDAP://" + ldapUrl + "/" + Domain); 

//Build the user and issue the Refresh bind 
var dirEntry = new DirectoryEntry 
        { 
         Path = LdapPath, 
         Username = _usernameToVerify, 
         Password = _passwordToVerify, 
         AuthenticationType = AuthenticationTypes.ServerBind 
        }; 

//This will load any available properties for the user 
dirEntry.RefreshCache(); 

또한, 보이는)이므로 ServerBind mechansim과 함께 AuthenticationTypes.SecureSocketsLayer도 포함시켜야합니다.

AuthenticationType = AuthenticationTypes.ServerBind | AuthenticationTypes.SecureSocketsLayer 

희망이 있습니다.

+0

감사합니다. Gregory. 난 당신의 예제를 시도하고 다른 사람을 도울 것이라고 확신하지만 나에게 그것은 여전히 ​​내부적으로 80005000 오류를 주었다. 나는 그럭저럭 일할 수있는 저수준의 DirectoryServices 예제를 게시했다. – user1444886

0

한 고객에 맞게 사용자 지정된 이전 DLL 프로젝트를 파고 들려고했습니다.

나는 그것을 작동시킬 수있었습니다. 이스케이프 문자가있는 DN이있는 경우이 낮은 수준의 디렉토리 서비스 루틴을 참조해야합니다. (실제 생활에서 DN은 DirectorySearcher를 설정하고 FindOne을 먼저 수행하여 초기 검색을 통해 얻습니다.)

string userDn = @"cn=Feat Studentl+umanroleid=302432,ou=Faculty of Engineering & Physical Sciences Administration,ou=Faculty of Engineering & Physical Sciences,ou=People,o=University of TestSite,c=GB"; 
string basicUrl = @"surinam.testsite.ac.uk:636"; 



    var ldapConnection = new LdapConnection(basicUrl); 
    ldapConnection.AuthType = AuthType.Basic; 
    LdapSessionOptions options = ldapConnection.SessionOptions; 
    options.ProtocolVersion = 3; 
    options.SecureSocketLayer = true; 

    NetworkCredential credential = new NetworkCredential(userDn, password);        
    ldapConnection.Credential = credential; 

    try 
    { 
     ldapConnection.Bind(); 
     Console.WriteLine("bind succeeded "); 
    } 
    catch (LdapException e) 
    { 
     if (e.ErrorCode == 49) 
     { 
      Console.WriteLine("bind failed "); 
     } 
     else 
     { 
      Console.WriteLine("unexpected result " + e.ErrorCode); 
     } 
    } 
    catch (DirectoryOperationException e) 
    { 
     Console.WriteLine("unexpected error " + e.Message); 
    }