Tag: active directory

Active Directory服务:PrincipalContext – “容器”对象的DN是什么?

我目前正在尝试使用PrincipalContext类通过Active Directory服务进行身份validation。 我想让我的应用程序使用密封和SSL上下文对域进行身份validation。 为了做到这一点,我必须使用PrincipalContext的以下构造函数(链接到MSDN页面) : public PrincipalContext( ContextType contextType, string name, string container, ContextOptions options ) 具体来说,我正在使用构造函数: PrincipalContext domainContext = new PrincipalContext( ContextType.Domain, domain, container, ContextOptions.Sealing | ContextOptions.SecureSocketLayer); MSDN说“容器”: 商店中的容器用作上下文的根。 所有查询都在此根下执行,并且所有插入都将在此容器中执行。 对于Domain和ApplicationDirectory上下文类型,此参数是容器对象的可分辨名称(DN)。 容器对象的DN是多少? 如何找出容器对象是什么? 我可以查询Active Directory(或LDAP)服务器吗?

如何查找当前用户具有WriteProperty访问权限的ActiveDirectory中的所有组?

目前,我想在Active Directory中查找当前用户具有正确WriteProperty的所有组。 问题是我可以找到直接插入用户的所有组,但是当用户在一个组内并且该组具有写访问权限时,它将不会显示。 我认为设置GetAccessRules()的布尔值会有所帮助,但事实并非如此。 所以这是我已经拥有的代码: var identity = WindowsIdentity.GetCurrent().User; var allDomains = Forest.GetCurrentForest().Domains.Cast(); var allSearcher = allDomains.Select(domain => { var searcher = new DirectorySearcher(new DirectoryEntry(“LDAP://” + domain.Name)); //Apply some filter to focus on only some specfic objects searcher.Filter = “(&(objectClass=group)(name=*part_of_group_name*))”; return searcher; }); var itemsFound = allSearcher .SelectMany(searcher => searcher.FindAll() .Cast() .Select(result => result.GetDirectoryEntry())); var […]

快速检索用户信息的方法Active Directory

如何从Active Directory查询用户信息? 我有适用的代码,但它确实很慢。 我正在使用C#。 这是我目前使用的代码: static void Main(string[] args) { SearchResultCollection sResults = null; try { //modify this line to include your domain name string path = “LDAP://EXTECH”; //init a directory entry DirectoryEntry dEntry = new DirectoryEntry(path); //init a directory searcher DirectorySearcher dSearcher = new DirectorySearcher(dEntry); //This line applies a filter to the search specifying […]

在.Net 4.5中检查Active Directory组成员身份

我有一个使用Windows身份validation的ASP.Net MVC应用程序,我正在检查组成员身份以确保控制器操作的安全性。 听起来很简单,我发现没有其他问题可以解决我遇到的问题。 第一次尝试:[授权] 经典的方法是简单地在控制器操作上打一个Authorize数据注释属性并转到城镇: [Authorize(Roles = @”domain\groupName1″)] 没有骰子。 我被提示输入凭据。 通常这意味着Windows身份validation配置有问题,但设置正常:(1) HttpContext.User是一个WindowsPrincipal对象,(2)我确认另一个已知的组名有效。 第二次尝试:IsInRole() 下一步是采用更老式的路线并使用IPrincipal.IsInRole() ,再次,一个返回false ,另一个返回true 。 var wp = (WindowsPrincipal)User; // false var inGroup1 = wp.IsInRole(@”domain\groupName1″); // true var inGroup2 = wp.IsInRole(@”domain\groupName2″); 难倒…所以我打了我的系统书呆子,我们仔细检查一切。 用户是群组成员? 是。 组名拼写正确吗? 是。 下一步是阻止SID。 第三次尝试:搜索身份的群集 在我的控制器中,我检查WindowsIdentity并查看组集合中的麻烦组的SID: var wi = (WindowsIdentity)wp.Identity; var group = wi.Groups.SingleOrDefault(g => g.Value == “group1-sidValue”); group变量是SecurityIdentifier对象。 因为它不是null,我们可以确定当前用户是[Authorize()]或IsInRole()尝试无法确认的组的成员。 […]

对于未知用户,ValidateCredentials返回true?

我在这里使用PrincipalContext.ValidateCredentials看到一些奇怪的行为。 设置是父/子设置中的两个Active Directory域(因此我们有主域company.com和子域development.company.com )。 当我针对主域validation凭据时, ValidateCredentials按预期运行,对于良好的用户/传递对返回true,对其他任何对返回false。 但是,如果我在子域中validation用户,则ValidateCredentials将为良好的用户名/密码和无效用户返回true。 如果我向有效用户提供无效密码,则会正确返回false。 现在我首先通过UserPrincipal.FindByIdentity()解决它,如果用户存在,那么调用ValidateCredentials – 但我想了解发生了什么。 我看过的另一个解决方法是将用户名作为domain\username传递给ValidateCredentials的MSDN条目 : 在此函数的每个版本中,userName字符串可以是各种不同格式之一。 有关可接受格式类型的完整列表,请参阅ADS_NAME_TYPE_ENUM文档。 …列出了这种forms的用户名。 但这会导致ValidateCredentials始终返回true,无论我传入的用户名和密码的组合如何。 相关代码是: bool authenticated = false; // Various options tried for ContextOptions, [etc] inc. explicit username/password to bind to AD with — no luck. using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain, null, ContextOptions.Negotiate, null, null)) { log(pc.ConnectedServer + ” […]

如何在Active Directory中获取/更新“联系人”?

有没有办法在Active Directory中查找和更新联系人? 我正在构建一个示例C#.NET应用程序来完成此任务。 我会很感激任何代码。

如何获取当前登录用户的AD显示名称

考虑在Active Directory中为用户设置的以下属性: 在我的winforms应用程序中,我想显示当前登录并使用该应用程序的用户的显示名称 。 我该如何检索这些信息?

ASP.NET如何获取Active Directory中的组列表

如何在Active Directory中获取完整的组列表?

从Active Directory中的组中获取所有用户

我正在尝试在AD中获取特定组的所有用户,然后将Employees列表返回到我的Employee类中的属性。 我有: 我的filter没有产生任何结果 – 应该是什么? 此外,我在这里尝试了第一个解决方案: 特定Active Directory通讯组中的用户列表 ,但我需要移动设备,扩展程序等详细信息,这是我无法使用该方法获得的。 public static List CreateEmployeeList(string department) { List employees = new List(); string filter = string.Format(“(&(ObjectClass=person)(memberOf=CN={0},OU=Users & Groups,OU=Blah,DC=Blah,DC=Blah,DC=Blah))”, department); DirectoryEntry adRoot = new DirectoryEntry(“LDAP://” + domain, null, null, AuthenticationTypes.Secure); DirectorySearcher searcher = new DirectorySearcher(adRoot); searcher.SearchScope = SearchScope.Subtree; searcher.ReferralChasing = ReferralChasingOption.All; searcher.Filter = filter; SearchResultCollection results = searcher.FindAll(); […]

UserPrincipal.FindByIdentity中的.NET 4.5错误(System.DirectoryServices.AccountManagement)

在.NET 4.5下测试我们的.NET 4.0应用程序时,我们遇到了FindByIdentity方法的UserPrincipal 。 以下代码在.NET 4.0运行时运行时有效,但在.NET 4.5下失败: [Test] public void TestIsAccountLockedOut() { const string activeDirectoryServer = “MyActiveDirectoryServer”; const string activeDirectoryLogin = “MyADAccount@MyDomain”; const string activeDirectoryPassword = “MyADAccountPassword”; const string userAccountToTest = “TestUser@MyDomain”; const string userPasswordToTest = “WRONGPASSWORD”; var principalContext = new PrincipalContext(ContextType.Domain, activeDirectoryServer, activeDirectoryLogin, activeDirectoryPassword); var isAccountLockedOut = false; var isAuthenticated = principalContext.ValidateCredentials(userAccountToTest, userPasswordToTest, principalContext.Options); […]