C# 4.0 ldap上的kerberos身份验证
我正在开发控制台应用程序,它使用ldap DirectoryServices.Protocols从active directory获取用户数据。目前,我能够通过SSL、TLS和简单连接(既不是SSL也不是TLS)使用基本身份验证获取数据。但是现在我想通过SSL、TLS和简单连接使用kerberos身份验证来获取数据。我目前正在为此使用以下代码C# 4.0 ldap上的kerberos身份验证,c#-4.0,authentication,active-directory,ldap,kerberos,C# 4.0,Authentication,Active Directory,Ldap,Kerberos,我正在开发控制台应用程序,它使用ldap DirectoryServices.Protocols从active directory获取用户数据。目前,我能够通过SSL、TLS和简单连接(既不是SSL也不是TLS)使用基本身份验证获取数据。但是现在我想通过SSL、TLS和简单连接使用kerberos身份验证来获取数据。我目前正在为此使用以下代码 LdapDirectoryIdentifier ldap_id = new LdapDirectoryIdentifier(
LdapDirectoryIdentifier ldap_id = new LdapDirectoryIdentifier(
host,
Int32.Parse(port),
true,
false);
LdapConnection con = new LdapConnection(ldap_id);
con.AuthType = AuthType.Kerberos;
con.SessionOptions.Sealing = true;
con.SessionOptions.Signing = true;
con.SessionOptions.ProtocolVersion = 3;
con.Bind();
这给了我一个错误,因为“ldap服务器不可用”。有人能告诉我上面的代码有什么问题吗?另外,如果需要在服务器和客户端上进行kerberos身份验证,请告知我。在我传递网络凭据进行基本身份验证时,是否需要传递如下所示的网络凭据
LdapDirectoryIdentifier ldapIdentifier = new LdapDirectoryIdentifier(
host,
Int32.Parse(port),
true,
false);
NetworkCredential credential = new NetworkCredential(username, password);
LdapConnection con = new LdapConnection(ldapIdentifier, credential, AuthType.Kerberos);
con.SessionOptions.Sealing = true;
con.SessionOptions.Signing = true;
con.SessionOptions.ProtocolVersion = 3;
con.Bind();
如果仔细阅读,您会发现使用了
协商
,并且它选择Kerberos
作为最佳选项(如果可用)。下面是通过SSL、TLS和LDAP进行基本Kerberos身份验证的代码
注意:传递给NetworkCredential的connectionAccountName应该是用户原则名称。您可以通过检查Active Directory用户的AttributeEditor部分中的属性userPrincipleName值来检查用户的原则名称,ssl端口为636,其他端口为389
var networkCredential = new NetworkCredential(connectionAccountName, connectionAccountPassword);
LdapDirectoryIdentifier ldapDirectoryIdentifier = null;
switch (connectionType)
{
case LDAPConnectionType.SSL:
ldapDirectoryIdentifier = new LdapDirectoryIdentifier(ldapServerName, Convert.ToInt16(LDAPPorts.SSL));
ldapConnection = new LdapConnection(ldapDirectoryIdentifier, networkCredential, authType);
ldapConnection.SessionOptions.ProtocolVersion = 3;
ldapConnection.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback(ServerCallback);
ldapConnection.SessionOptions.SecureSocketLayer = true;
break;
case LDAPConnectionType.TLS:
ldapDirectoryIdentifier = new LdapDirectoryIdentifier(ldapServerName, Convert.ToInt16(LDAPPorts.Default));
ldapConnection = new LdapConnection(ldapDirectoryIdentifier, networkCredential, authType);
ldapConnection.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback(ServerCallback);
ldapConnection.SessionOptions.StartTransportLayerSecurity(null);
break;
default:
ldapDirectoryIdentifier = new LdapDirectoryIdentifier(ldapServerName, Convert.ToInt16(LDAPPorts.Default));
ldapConnection = new LdapConnection(ldapDirectoryIdentifier, networkCredential, authType);
break;
}
ldapConnection.Bind();
谢谢
乌梅什塔亚德