【问题标题】:What permissions does user need to validate credentials in Active Directory?用户需要哪些权限来验证 Active Directory 中的凭据?
【发布时间】:2013-12-09 22:27:23
【问题描述】:

我有一些代码使用 PrincipalContext 对象,并将特定的用户名和密码传递到其构造函数中以绑定到 Active Directory。

然后调用 .ValidateCredentials() 为正在验证的用户传入不同的用户名和密码。

我的问题是,在 Active Directory 中需要什么权限才能让第一个用户在 Active Directory 中绑定?

【问题讨论】:

  • bind,你只需要传入任何当前处于活动状态的 AuthenticatablePrinciple 对象(你知道计算机有他们登录的密码吗?域也一样?它们每隔几周就会自动更改一次,it can wreak havoc on you if you are working with VM's and rolling back snapshots),但是我不知道它是否需要更多权限来验证凭据。 (总而言之:您的标题很好,但问题的主体不是)

标签: c# active-directory


【解决方案1】:

当我开始研究这个主题时,我发现一切都非常令人困惑,本教程是最好的入门教程之一,因为有很多首字母缩略词增加了难度。 https://hynek.me/articles/ldap-a-gentle-introduction/

我会向您推荐一个关于验证的类似问题,但不是专门针对凭据 因为有几个代码 sn-ps 与此类工作相关。

Validate a username and password against Active Directory?

我认为您要问的是身份验证功能

我认为发布我的整个代码只会让你感到困惑,所以我会解释它的结构并希望你能继续前进并给出一个 sn-p。

我做的方法很多,方法如下:

公共类 LdapAuthentication 使用方法 IsAuthenticated 其中方法被传递域、用户名和密码

然后我使用 目录条目 目录搜索器 查找和过滤 SAMAccountName 然后,这取决于您的应用程序以及您要查找的内容。

但其中大部分都在 System.DirectoryServices

            try
            {   //Bind to the native AdsObject to force authentication.         
                Object obj = entry.NativeObject;

                DirectorySearcher search = new DirectorySearcher(entry);

                search.Filter = "(SAMAccountName=" + username + ")";
                search.PropertiesToLoad.Add("cn");
                SearchResult result = search.FindOne();

                if (null == result)
                {
                    return false;
                }

                //Update the new path to the user in the directory.
                _path = result.Path;
                _filterAttribute = (String)result.Properties["cn"][0];
            }
            catch (Exception ex)
            {
                throw new Exception("Error authenticating user. " + ex.Message);
            }

这应该足以让您开始搜索并获得所需的内容。祝你好运!

【讨论】:

    【解决方案2】:

    在内部,PrincipalContext.ValidateCredentials 方法将使用提供的网络凭据简单地调用LdapConnection.Bind 方法以检查它们是否有效。如果绑定成功ValidateCredentials返回true,否则返回false。

    由于LdapConnection.Bind 方法被以下属性修饰:

    [DirectoryServicesPermissionAttribute(SecurityAction.LinkDemand, Unrestricted = true)]
    

    您的应用程序的身份(运行进程和/或当前模拟的用户帐户)必须通过此权限检查才能使PrincipalContext.ValidateCredentials 方法工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-15
      • 1970-01-01
      • 2011-01-01
      • 2011-10-14
      • 2012-09-11
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      相关资源
      最近更新 更多