- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我目前正在尝试使用 PrincipalContext 类通过 Active Directory 服务进行身份验证。我想让我的应用程序使用密封和 SSL 上下文对域进行身份验证。为此,我必须使用 the following constructor of PrincipalContext (link to MSDN page) :
public PrincipalContext(
ContextType contextType,
string name,
string container,
ContextOptions options
)
具体来说,我是这样使用构造函数的:
PrincipalContext domainContext = new PrincipalContext(
ContextType.Domain,
domain,
container,
ContextOptions.Sealing | ContextOptions.SecureSocketLayer);
MSDN 关于“容器”的说法:
The container on the store to use as the root of the context. All queries are performed under this root, and all inserts are performed into this container. For Domain and ApplicationDirectory context types, this parameter is the distinguished name (DN) of a container object.
容器对象的 DN 是什么?我如何找出我的容器对象是什么?我可以为此查询 Active Directory(或 LDAP)服务器吗?
最佳答案
好吧,我设法弄清楚了问题:
PrincipalContext domainContext = new PrincipalContext(ContextType.Domain,domain);
domainContext.ValidateCredentials(userName, password,
ContextOptions.Negotiate | ContextOptions.SecureSocketLayer);
通过在 ValidateCredentials 方法中(而不是在构造函数中)指定 ContextOptions,这让我不必为容器对象指定 DN。
更新:
虽然我应该澄清的是,经过进一步的实验,我发现从这个 PrincipalContext 对象派生的任何查询都是未加密的。
显然,当在 ValidateCredentials 中设置 ContextOptions 时,这些选项仅用于特定的 ValidateCredentials 调用。但这就是它变得奇怪的地方......
因此,我希望对 AD 服务器的查询也进行加密。示例查询:
UserPrincipal p = UserPrincipal.FindByIdentity(
domainContext, IdentityType.SamAccountName, userName);
var groups = p.GetGroups();
foreach (GroupPrincipal g in groups) { /* do something */ }
上面的代码获取用户所属的所有组的列表,但它是明文(未加密)的。因此,经过多次摆弄后,我发现 DN 根本不需要设置。
PrincipalContext domainContext = new PrincipalContext(ContextType.Domain,domain,
null,ContextOptions.Negotiate | ContextOptions.SecureSocketLayer);
我发现我可以将容器对象 (DN) 设置为空。这很好用。将它设置为空字符串 ("") 会导致某种未知类型的异常,所以不要以为可以给它一个空字符串。
这是奇怪的部分。您可能认为在 PrincipalContext 中设置 SecureSocketLayer 选项意味着您在使用 VerifyCredentials 时不必显式设置它。但我发现,如果我没有在 VerifyCredentials 部分设置它,身份验证将失败,但查询(如在组的示例中)仍然是加密的。
也许我还没有完全理解 AD 身份验证和查询,但这对我来说似乎是一种奇怪的行为。
关于c# - 事件目录服务 : PrincipalContext -- What is the DN of a "container" object?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2538064/
我有一个带有 Windows 身份验证的 Web 应用程序。当我调试线路时 var domainContext = new PrincipalContext(ContextType.Domain, "
我正在开发一个 C# .NET Framework 库来访问事件目录。 我必须做的一件事是获取所有 AD 用户,我看到了: PrincipalContext principalContext =
我正在尝试使用 PrincipalContext 检查远程计算机上是否存在本地用户组。 我在使用 PrincipalContext 时遇到问题: PrincipalContext ctx = new
我正在尝试将 PrincipalContext 用于我正在开发的网络服务。我已经在不同应用程序的 Web 服务器上使用表单例份验证,并且工作正常。 我收到的错误是: System.DirectoryS
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, Domain, UserName, Password))
首先,我查看了关于 SO 的大多数问题,但似乎都不是完全相同的问题。 Here是一个类似的问题,但并不完全相同。在我的情况下,我正在创建一个 PrincipalContext : Dim pctx A
我正在尝试使用 PrincipalContext 通过 Active Directory 服务找出域组件。 我使用很少的参数创建了 PrincipalContext: PrincipalContext
我正在尝试使用 PrincipalContext 通过 Active Directory 服务找出域组件。 我使用很少的参数创建了 PrincipalContext: PrincipalContext
每当调用此方法时,我都会崩溃。 public bool findSAMAccountByName(string environmentUserName) { try
应用程序能否创建一次 PrincipalContext,然后在应用程序的整个生命周期内重复使用它?这将避免在每次调用 Active Directory 之前使用相同的详细信息重新创建 Principa
我们有一个应用程序使用 LDAP 通过 IP 地址通过 VPN 隧道对远程 AD 进行身份验证,使用以下代码: using (PrincipalContext pc = new PrincipalCo
我知道这有一个简单的解决方案,但我似乎无法让它工作... 使用其他 Stack Overflow answers和 Microsoft's Documentation ,我知道 PrincipalCo
我正在为 asp.net 创建一个自定义登录功能,它根据事件目录进行验证。用户必须能够仅使用他的用户名或他的用户名和域(以及两种情况下的密码)登录。 代码: AuthUser user = Authe
我有一个返回 PrincipalServer 的方法 CreateContextForGlobalCatalog连接到全局目录: PrincipalContext = new PrincipalCon
我有一个包含很多属性的 UserPrincipal 对象,但我找不到密码过期日期的属性。 如何做到这一点? 最佳答案 这是我能想到的最简单的方法... using System.DirectorySe
有没有办法强制 PrincipalContext 连接到特定的域 Controller ?我正在为我的应用程序枚举锁定帐户列表,我希望能够查询多个服务器并从所有 DC 返回列表。 目前我得到我的 Pr
我正在尝试将域帐户添加到远程计算机的管理员组。我遇到的问题是,当我尝试实际连接到远程机器 PrincipleContext 时,它给了我一条访问被拒绝的消息,但我是以远程机器本地管理员的身份连接的。当
我有以下两个使用 LDAP 和 LDAPS 对用户进行身份验证的实现,我想知道哪个更好/更正确。作为记录,这两种方法都适用于 SSL 和非 SSL 连接。 我也很好奇,因为在 Non-SSL Prin
我正在尝试通过 Active Directory 中的用户名查找用户。 这个有效: const string Domain = "SLO1.Foo.Bar.biz"; const string Use
我正在创建一个 PrincipalContext 对象,用于从我们的 AD 数据库中检索用户的组(然后我们使用这些对象对站点的各个部分进行身份验证)。 这过去是使用表单例份验证完成的,所以代码看起来像
我是一名优秀的程序员,十分优秀!