无需 SetSPN 即可查询/更改 Windows 域上的 SPN
有人在 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");
}
}
}
Has anyone had any luck with querying/changing SPNs on a Windows domain? Most of the hits on Google are SQL related: I can't find any information on how to do this myself. The most important things would be to query to SPN configuration and check for duplicates.
According to Arnout I made the following code:
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");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来此信息存储在
servicePrincipalName
AD 属性中。 有关详细信息,请参阅此页面 ,特别是“使用 LDIFDE 搜索”部分。It looks like this information is stored in the
servicePrincipalName
AD attribute. See this page for more info, in particular the "Search using LDIFDE" section.您可以使用支持工具中的 Search.VBS 来搜索重复的 SPN:
You can use Search.VBS in the support tools to search for duplicate SPNs: