gpt4 book ai didi

c# - 在没有 SetSPN 的情况下查询/更改 Windows 域上的 SPN

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

有没有人有幸在 Windows 域上查询/更改 SPN? Google 上的大多数点击都与 SQL 相关:我自己找不到任何关于如何执行此操作的信息。最重要的事情是查询 SPN 配置并检查重复项。

根据 Arnout 的说法,我编写了以下代码:

static void Main(string[] args) {
ValidateSPN("K2Server/jonathand-vpc:5252");
}

static void ValidateSPN(string spn) {
const string queryFormat = "(ServicePrincipalName={0})";
using (Domain localDomain = Domain.GetCurrentDomain()) {
using (DirectorySearcher search = new DirectorySearcher(localDomain.GetDirectoryEntry())) {
search.Filter = string.Format(queryFormat, spn);
search.SearchScope = SearchScope.Subtree;
SearchResultCollection collection = search.FindAll();
if (collection.Count > 1)
throw new Exception("Duplicate SPNs found.");
else if (collection.Count == 0)
throw new Exception("No such SPN");
}
}
}

最佳答案

看起来此信息存储在 servicePrincipalName AD 属性中。参见 this page了解更多信息,特别是“使用 LDIFDE 搜索”部分。

关于c# - 在没有 SetSPN 的情况下查询/更改 Windows 域上的 SPN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/416241/

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