ldap上的kerberos身份验证

时间:2014-04-27 08:49:56

标签: c#-4.0 authentication active-directory ldap kerberos

我正在使用控制台应用程序,它使用ldap DirectoryServices.Protocols从活动目录中获取用户数据。目前我能够使用基于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();

2 个答案:

答案 0 :(得分:0)

如果您仔细阅读this,则会看到Negotiate被使用,并选择Kerberos作为最佳选择。

答案 1 :(得分:0)

以下代码适用于LDAP上的基本,Kerberos身份验证,SSL,TLS和简单(既不是SSL也不是TLS连接)。

注意:传递给NetworkCredential的connectionAccountName应该是用户原则名称。您可以通过检查Active Directory用户的AttributeEditor部分中的Attribute 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();

由于

Umesh Tayade