Guest User

Untitled

a guest
Sep 26th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. LdapDirectoryIdentifier ldap_id = new LdapDirectoryIdentifier(
  2. host,
  3. Int32.Parse(port),
  4. true,
  5. false);
  6. LdapConnection con = new LdapConnection(ldap_id);
  7.  
  8. con.AuthType = AuthType.Kerberos;
  9. con.SessionOptions.Sealing = true;
  10. con.SessionOptions.Signing = true;
  11. con.SessionOptions.ProtocolVersion = 3;
  12.  
  13. con.Bind();
  14.  
  15. LdapDirectoryIdentifier ldapIdentifier = new LdapDirectoryIdentifier(
  16. host,
  17. Int32.Parse(port),
  18. true,
  19. false);
  20. NetworkCredential credential = new NetworkCredential(username, password);
  21. LdapConnection con = new LdapConnection(ldapIdentifier, credential, AuthType.Kerberos);
  22. con.SessionOptions.Sealing = true;
  23. con.SessionOptions.Signing = true;
  24. con.SessionOptions.ProtocolVersion = 3;
  25. con.Bind();
  26.  
  27. var networkCredential = new NetworkCredential(connectionAccountName, connectionAccountPassword);
  28. LdapDirectoryIdentifier ldapDirectoryIdentifier = null;
  29.  
  30. switch (connectionType)
  31. {
  32. case LDAPConnectionType.SSL:
  33. ldapDirectoryIdentifier = new LdapDirectoryIdentifier(ldapServerName, Convert.ToInt16(LDAPPorts.SSL));
  34. ldapConnection = new LdapConnection(ldapDirectoryIdentifier, networkCredential, authType);
  35. ldapConnection.SessionOptions.ProtocolVersion = 3;
  36. ldapConnection.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback(ServerCallback);
  37. ldapConnection.SessionOptions.SecureSocketLayer = true;
  38.  
  39. break;
  40.  
  41. case LDAPConnectionType.TLS:
  42. ldapDirectoryIdentifier = new LdapDirectoryIdentifier(ldapServerName, Convert.ToInt16(LDAPPorts.Default));
  43. ldapConnection = new LdapConnection(ldapDirectoryIdentifier, networkCredential, authType);
  44. ldapConnection.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback(ServerCallback);
  45. ldapConnection.SessionOptions.StartTransportLayerSecurity(null);
  46.  
  47. break;
  48.  
  49. default:
  50. ldapDirectoryIdentifier = new LdapDirectoryIdentifier(ldapServerName, Convert.ToInt16(LDAPPorts.Default));
  51. ldapConnection = new LdapConnection(ldapDirectoryIdentifier, networkCredential, authType);
  52.  
  53. break;
  54. }
  55.  
  56. ldapConnection.Bind();
Add Comment
Please, Sign In to add comment