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

标签 c# configuration kerberos

有没有人有幸在 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/

相关文章:

c# - 如何设计像 Google Chrome 标签页一样的标签页?

c# - VS 扩展 : TextPoint. 大于/小于大文件非常慢

php - 与数据库连接的 parameters.yml 和 config_(dev|stage|prod).yml 混淆

security - 在所有节点上使用相同主体的Hadoop安全性

linux - Spring Kerberos 扩展、SSO 和域外机器

windows - MIT Kerberos 无法在 MSLSA 缓存中找到 TGT

c# - 使用 Razor 在javascript中调用带有参数的C#代码方法

c# - web-api POST 正文对象始终为 null

configuration - 通过 appsettings.json 为 Application Insights 配置 Serilog

c# - ASP.NET 核心 : JSON Configuration GetSection returns null