Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 ldap上的kerberos身份验证_C# 4.0_Authentication_Active Directory_Ldap_Kerberos - Fatal编程技术网

C# 4.0 ldap上的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(

我正在开发控制台应用程序,它使用ldap DirectoryServices.Protocols从active directory获取用户数据。目前,我能够通过SSL、TLS和简单连接(既不是SSL也不是TLS)使用基本身份验证获取数据。但是现在我想通过SSL、TLS和简单连接使用kerberos身份验证来获取数据。我目前正在为此使用以下代码

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();
谢谢

乌梅什塔亚德