Tag: ldap

“用户必须在下次登录时更改密码”时LDAPvalidation失败。 有解决方案吗

当设置“用户必须在下次登录时更改密码”时,我在用户validation时遇到问题。 以下是我validation用户的方法: Boolean ValidateUser(String userName, String password) { try { var userOk = new DirectoryEntry(“LDAP://”, userName, password, AuthenticationTypes.Secure | AuthenticationTypes.ServerBind); return true; } catch (COMException ex) { if (ex.ErrorCode == -2147023570) // 0x8007052E — Wrong user or password return false; else throw; } } 设置“必须更改密码”时,将按预期捕获COMException,但是, ErrorCode与密码错误时相同。 有谁知道如何解决这一问题? 我需要一个返回代码,告诉密码是正确的,并且用户必须更改密码。 我不想在C#中实现Kerberos只是为了在用户必须更改密码时检查该死的标志。

Active Directory:DirectoryEntry成员列表 GroupPrincipal.GetMembers()

我有一个小组,我们称之为GotRocks。 我试图获得所有成员,但我在DirectoryEntry和AccountManagement之间的计数结果却截然不同。 以下是按成员检索方法计数: Method 1: DirectoryEntry.PropertyName.member = 350 Method 2: AccountManagement.GroupPrincipal.GetMembers(false) = 6500 Method 2: AccountManagement.GroupPrincipal.GetMembers(true) = 6500 作为一个完整性检查,我进入ADUC并从该组中删除了成员列表,默认情况下限制为2,000。 这里重要的是ADUC似乎validation了AccountManagement的结果。 我也检查了儿童财产,但它是空白的。 此外,DirectoryEntry中列出的所有成员都不属于SchemaName组 – 它们都是用户。 我不认为这是一个代码问题,但可能缺乏对DirectoryEntry和GetMembers方法如何检索组成员的理解。 任何人都可以解释为什么DirectoryEntry成员列表会产生与GetMembers递归函数不同的结果? 我需要注意某种方法或属性吗? 注意:我已经构建了一个函数,它将通过“member; range = {0} – {1}”查询DirectoryEntry,其中循环以1,500的块为单位获取成员。 我在这里完全失败了。 DirectoryEntry返回如此少的结果的事实是有问题的,因为我想使用DirectoryEntry这个简单的事实,即这条路线至少比AccountManagement快两个数量级(即,秒表时间为1100毫秒而不是250,000毫秒) 。 更新1:方法: 方法1:DirectoryEntry private List GetGroupMemberList(string strPropertyValue, string strActiveDirectoryHost, int intActiveDirectoryPageSize) { // Variable declaration(s). List listGroupMemberDn = new List(); […]

使用C#,如何检查活动目录中是否禁用了计算机帐户?

如何使用C#/ .NET检查Active Directory中是否禁用了计算机帐户

C#LDAP查询以检索组织单位中的所有用户

我正在尝试运行一个LDAP查询,该查询将返回属于组织单位的所有用户OU=Employees和OU=FormerEmployees ,我无法到达任何地方。 我尝试使用distinguishedName搜索,但似乎不支持通配符。 我知道必须有一个更简单的方法,但我的搜索努力没有产生任何结果

从.NET连接到LDAP服务器

我建议使用System.DirectoryServices.Protocols ,以支持连接到Active Directoy以外的LDAP服务器。 不幸的是,我无法正确搜索目录。 我希望能够为用户获得某个属性(例如mail )。 通过使用DirectorySearcher类,可以在System.DirectoryServices命名空间中轻松完成此操作。 如何在System.DirectoryServices.Protocols命名空间中实现相同的function。 这是我到目前为止所拥有的: var domainParts = domain.Split(‘.’); string targetOu = string.Format(“cn=builtin,dc={0},dc={1}”, domainParts[0], domainParts[1]); string ldapSearchFilter = string.Format(“(&(ObjectClass={0})(sAMAccountName={1}))”, “person”, username); // establish a connection to the directory LdapConnection connection = new LdapConnection( new LdapDirectoryIdentifier(domain), new NetworkCredential() { UserName = username, Password = “MyPassword” }); SearchRequest searchRequest = new SearchRequest( targetOu, […]

LdapConnection SearchRequest抛出“超出大小限制”的exception

由于我们需要使用LDAPS连接到LDAP服务器,因此我们必须使用LdapConnection而不是DirectoryEntry。 这是源代码: SearchResponse response; using (LdapConnection con = new LdapConnection(new LdapDirectoryIdentifier(Host, Port))) { if (IsSSL) { con.SessionOptions.SecureSocketLayer = true; con.SessionOptions.VerifyServerCertificate = (connection, certificate) => true; } con.Credential = new NetworkCredential(_username, _password); con.AuthType = AuthType.Basic; con.Bind(); if (logMessage != null) logMessage(“Connected to LDAP”); string sFilter = String.Format( “(&(objectcategory=person)(objectclass=user){0}(!(userAccountControl:1.2.840.113556.1.4.803:=2)))”, filter ); SearchRequest request = new SearchRequest(“OU=Corp,DC=mydc,DC=com”, sFilter, […]

如何在.NET中validationLDAP

我想在Windows操作系统上使用任何目录服务validation我的应用程序的用户名和密码。 例如,它可以是microsoft active directory,Novell eDirecotry或SunOne。 我已经知道如何使用c#本地为Microsoft Active Direcotry执行此代码。 (我完全放弃使用ADSI并创建一个低级别的com组件) 尝试使用Novel eDirecotory进行身份validation的方式是我安装了Mono项目。 在单声道项目中,他们为您提供Novell.Directory.ldap.dll代码看起来与Microsoft Active Directory相同。( http://www.novell.com/coolsolutions/feature/11204.html ) 对于SunOne,我被告知使用与活动目录相同的代码,但是ldap connecton字符串有点不同。( http://forums.asp.net/t/354314.aspx )( http:// technet。 microsoft.com/en-us/library/cc720649.aspx ) 为了使我的项目复杂化,大多数客户使用“服务帐户:”,这意味着我需要使用管理用户名和密码绑定,然后才能validation常规用户名和密码。 我的问题分为两部分。 1)根据我上面所解释的,这是我应该针对每个单独的服务进行身份validation的正确方向吗? 2)我觉得我根本不需要做任何这些代码。 我也觉得使用服务帐户的规定并不重要。 如果我关心的是在Windows机器上validation用户名和密码,为什么我甚至需要使用ldap? 我想说的是,考虑一下。 当您在早上登录计算机时,您无需提供服务帐户即可登录。 我可以通过使用runasfunction在DOS提示符下轻松validation用户名和密码,我将被拒绝或无法解析文本文件。 我确定还有其他方法可以将用户名和密码传递给我所在的Windows操作系统,并告诉我用户名和密码是否对其所在的域有效。 我对吗? 如果是这样,你们有什么建议方法? Michael Evanchik www.MikeEvanchik.com

从Active Directory获取所有直接报告

我试图通过递归方式通过Active Directory获取用户的所有直接报告。 因此,给定一个用户,我将得到一个列表,其中列出了所有将此人作为经理或者有一个人作为经理的人,他有一个人作为经理…最终将输入用户作为经理。 我目前的尝试相当缓慢: private static Collection GetDirectReportsInternal(string userDN, out long elapsedTime) { Collection result = new Collection(); Collection reports = new Collection(); Stopwatch sw = new Stopwatch(); sw.Start(); long allSubElapsed = 0; string principalname = string.Empty; using (DirectoryEntry directoryEntry = new DirectoryEntry(string.Format(“LDAP://{0}”,userDN))) { using (DirectorySearcher ds = new DirectorySearcher(directoryEntry)) { ds.SearchScope = SearchScope.Subtree; ds.PropertiesToLoad.Clear(); […]

检索用户的自定义Active Directory属性

我一直在尝试检索在Active Directory用户上设置的两个自定义属性,但似乎我一直在获取一个常量的属性列表(在2个不同的AD服务器上测试) 假设我试图获取的属性是prop1和prop2 ,我在下面的代码中做错了什么: List nProps = new List(); DirectoryEntry directoryEntry = new DirectoryEntry(“WinNT://DOM”); foreach (DirectoryEntry child in directoryEntry.Children) { // No filtering; ignore schemes that are not User schemes if (child.SchemaClassName == “User”) { foreach (var sVar in child.Properties.PropertyNames) nProps.Add(sVar.ToString()); break; } } nProps不包含任何我的自定义属性(不是prop1也不是prop2 ) (它确实包含其他属性,如BadPasswordAttempts,用户名等) 有任何想法吗?

如何知道我的DirectoryEntry是否真的连接到我的LDAP目录?

我正在连接到C#中的LDAP目录,所以我使用了DirectoryEntry类。 使用地址,登录名和密码执行“new DirectoryEntry”时,应该连接到LDAP目录。 但是,即使连接不起作用,它也会毫无问题地返回,并且设置了directoryentry变量。 所以我知道我的连接真的开了吗? 现在,我正在使用一个非常非常丑陋的黑客:我放了一个“if(mydirectory.SchemaEntry)”,如果没有建立连接会产生exception,因为DirectoryEntry的某些成员,例如SchemaEntry,不是如果连接失败,则设置。 但是1:在丑陋的等级2上需要11/10:在失败之前需要花费很多时间。 那么这样做的好方法是什么? 当然,微软必须提供一些东西(即使我使用的是LDAP目录而不是Active Directory)来了解我是否真的已经连接了?