gpt4 book ai didi

c# - 使用 PrincipalContext 和 ADLDS 时 LDAP 服务器不可用

转载 作者:行者123 更新时间:2023-11-30 12:08:57 24 4
gpt4 key购买 nike

我们正在使用 ADLDS 进行用户管理和身份验证。我们可以毫无问题地成功查询实例。但是,尝试执行诸如 SetPassword 之类的操作将失败,或者如果未设置密码,甚至尝试创建新用户也会失败。只要不是我尝试更新的密码,我就可以成功更新用户。我一直在阅读很多与此相关的不同文章,但没有找到解决方案。发帖看看我是否可以对这个问题有一些新的看法,感谢您的任何意见。

示例

ContextType ctxType = ContextType.ApplicationDirectory; 
string server = "myadldsserver.com";
string usersCN = "CN=Users,..."; // container where users reside
ContextOptions ctxOpts = ContextOptions.SimpleBind;
string uname = "myuser";
string pswrd = "mypass";

using(var ctx = new PrincipalContext(ctxType, server, usersCN, ctxOpts, uname, pswrd)
using(var newUser = new UserPrincipal(ctx)) {
newUser.Name = "newusername";
newUser.Enabled = true;
newUser.UserPrincipalName = "newusername";
newUser.Save();

newUser.SetPassword("newuserpassword");
}

错误 1

我遇到的第一个问题是,如果我尝试创建一个新的 UserPrincipal 并在没有设置密码的情况下调用 Save,就像上面的示例一样,我得到异常 A constraint violation occurred. with InnerException extend message of 0000052D:AtrErr:DSID-033807D7,#1:0:0000052D:DSID-033807D7,问题 1005 (CONSTRAINT_ATT_TYPE),数据 2246,Att 9005a (unicodePwd)

由于这个错误,我尝试在调用 Save 之前移动 SetPassword 以及我在网上找到的其他方法,例如从 UserPrincipal 获取 DirectoryEntry 并尝试调用 SetPassword 但遇到了不同的错误。

错误 2

在调用 UserPrincipal.Save 之前调用 SetPassword,调用 save 时会导致错误 The directory property cannot be found in the cache.

请注意,如果我尝试调用 ResetPassword 或获取 DirectoryEntry 并同时调用 Invoke("SetPassword"...

,则会发生相同的错误

错误 3

根据我的研究,大多数情况似乎表明这可能与需要使用安全连接访问 AD LDS 有关。因此,我更改了我的服务器以包含 636 端口 string server = "myadldsserver.com:636" 并将 ContextOptions 更改为 ContextOptions.SimpleBind | ContextOptions.SecureSocketLayer

在构造 PrincipalContext 时进行这些更改我得到以下异常 无法联系服务器。 内部异常为 The LDAP server is unavailable., HResult为-2146233087

JAVA与LDP

为了对此添加一些背景知识,我们确实在旧的 Java 应用程序中编写了类似的代码。我们正在尝试将其中一些逻辑移植到 C# 中的 .NET 端。 Java 中的代码使用 Java keystore ,其中包含在 AD LDS 服务器上生成的证书。 Java 应用程序使用 SSL 端口当然没有问题。我们知道服务器似乎配置正确,这只是如何从 .NET 端访问它的问题。

在 .NET 方面是否有等效项,例如 Java 中的 keystore?我们知道可以与服务器建立 SSL 连接。我们也使用 LDP 验证了这一点。

目标

  • 能够创建新用户并在创建过程中设置他们的密码
  • 能够为用户重置密码或更改密码
  • 从 .NET 安全地连接到我们的 AD LDS 实例

最佳答案

您是否尝试过使用 Microsoft 管理控制台导入证书?

安装证书的两种方式

要么

  1. Open a cmd.exe console and type "MMC"
  2. File > Add/Remove Snap-In...
  3. Select Certificates, click Add
  4. Choose Computer Account and Local Computer when prompted, then OK...
  5. Certificates should now be showing under Console Root
  6. Certificates > Trusted Root Certification Authorities > Certificates > (right-click) > All Tasks > Import Certificate...
  7. Find the certificate you want to import, click Next and choose defaults (Trusted Root Certification Authorities should already be selected)
  8. Click Next, Finish

(或)

Simply double-click on the .cer file for the certificate in Windows Explorer, click Install Certificate... > Next > select the option to "Place all certificates in following store" > Browse... > Select Trusted Root Certification Authorities. Continue with next until done.


此时您的证书已安装,您应该能够与您的 ADLDS 服务器安全通信。

关于c# - 使用 PrincipalContext 和 ADLDS 时 LDAP 服务器不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43897497/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com