Tag: active directory

已经与其基础RCW分离的COM对象无法使用 – 为什么会发生?

我有时会遇到以下exception:无法使用已与其基础RCW分离的COM对象 示例代码: using (AdOrganizationalUnit organizationalUnit = new AdOrganizationalUnit(ADHelper.GetDirectoryEntry(ouAdDn))) { using (AdUser user = organizationalUnit.AddUser(commonName)) { //set some properties user.Properties[key].Add(value); user.CommitChanges(); user.SetPassword(password); //it is set using Invoke //must be set after creating user user.Properties[“UserAccountControl”].Value = 512; user.CommitChanges(); } } AdUser看起来像这样: public class AdUser : DirectoryEntry { public AdUser(DirectoryEntry entry) : base(entry.NativeObject) { } public bool SetPassword(string […]

C#ADAL AcquireTokenAsync()没有弹出框

我们正在编写一个WCF服务,该服务必须与Dynamics CRM 2016 Online集成。 我正在尝试使用方法AcquireTokenAsync()使用ADAL进行身份validation。 问题是,它会显示一个弹出框,提示用户输入凭据。 当然,我们的应用程序是一项服务,这不是我们想要的。 我们一直在寻找一种无需此弹出框即可进行身份validation的方法。 有一个名为AuthenticationContextIntegratedAuthExtensions的类,它应该有助于“用户名/密码流”。 它有单个方法AcquireTokenAsync ,它会禁止弹出框,但我们没有找到任何方法将密码传递给它。 当仅使用用户名运行时,它会引发基本上说“没有提供密码”的exception。 有谁知道如何解决这个问题? 甚至不必是ADAL。 只是获取OAuth令牌的东西。

从本地计算机关闭网络确定用户Active Directory组

我当前的项目要求我针对Active Directory组validation用户。 问题是,计算机可能并不总是连接到域,但用户可能仍需要运行该工具。 我知道我没有连接时无法查询Active Directory,而是在尝试查询机器SAM(MSAM)。 我在断开网络连接时无法确定当前用户。 这是我正在使用的: PrincipalContext principalctx = new PrincipalContext(ContextType.Machine); UserPrincipal uprincipal = new UserPrincipal(principalctx); 从这一点开始,我如何询问当前登录本地计算机的用户。 当连接到域时,我可以使用UserPrincipal.Current进行查询。 如果我没有连接到域,它将无法说”The server could not be contacted” 。 注意:使用上面的代码不能使用此方法,而是可以放弃PrincipalContext并直接查询当前用户。 在识别出当前用户的情况下,我可以查询GetGroups()并确定它们是否在所需的组中。 此外,有人可以描述三个ContextType选项ApplicationDirectory, Domain, Machine 。 我担心我不完全理解每个选项,因此可能使用不正确。

C# – 跨多个Active Directory域搜索用户

我正在使用System.DirectoryServices.AccountManagement来提供用户查找function。 该业务有几个特定地区的AD域:AMR,EUR,JPN等。 以下适用于EUR域,但不会返回其他域中的用户(自然): var context = new PrincipalContext(ContextType.Domain, “mycorp.com”, “DC=eur,DC=mycorp,DC=com”); var query = new UserPrincipal(GetContext()); query.Name = “*Bloggs*”; var users = new PrincipalSearcher(query).FindAll().ToList(); 但是,如果我定位整个目录,它不会从任何特定于区域的域返回用户: var context = new PrincipalContext(ContextType.Domain, “mycorp.com”, “DC=mycorp,DC=com”); 如何搜索整个目录? 更新 阅读“Active Directory搜索的工作原理”: http://technet.microsoft.com/en-us/library/cc755809(v=ws.10).aspx 如果我使用端口3268后缀服务器名称,则会搜索全局编录: var context = new PrincipalContext(ContextType.Domain, “mycorp.com:3268”, “DC=mycorp,DC=com”); 然而,它非常非常慢。 有关如何提高性能的任何建议?

Active Directory嵌套组

我有一个C#4.0程序,可以检索特定AD组的所有成员。 在此AD组中,包含其他成员的其他AD组。 我需要我的程序来识别它是一个组并检索该组中的成员。 我知道我需要写一个递归程序,但我希望有人可能已经完成了它。 如果没有,有人可以告诉我AD属性属性,以确定该成员是实际的组吗?

GroupPrincipal.GetMembers在组(或子组,如果递归)包含ForeignSecurityPrincipal时失败

对于遇到同样问题的人来说,这不是一个问题。 发生以下错误: System.DirectoryServices.AccountManagement.PrincipalOperationException: An error (87) occurred while enumerating the groups. The group’s SID could not be resolved. at System.DirectoryServices.AccountManagement.SidList.TranslateSids(String target, IntPtr[] pSids) at System.DirectoryServices.AccountManagement.SidList.ctor(List`1 sidListByteFormat, String target, NetCred credentials) at System.DirectoryServices.AccountManagement.ADDNLinkedAttrSet.TranslateForeignMembers() 运行以下代码并且组或子组包含ForeignSecurityPrincipal时: private static void GetUsersFromGroup() { var groupDistinguishedName = “CN=IIS_IUSRS,CN=Builtin,DC=Domain,DC=com”; //NB: Exception thrown during iteration of members rather than call to GetMembers. using […]

检测使用ASP.NET应用程序登录计算机的用户

我想开发一个ASP.NET应用程序,可以检测登录Window Domain的用户。 这些凭据将用于登录ASP.NET应用程序。 我怎样才能做到这一点? 谢谢!

GetAuthorizationGroups()抛出exception

PrincipalContext context = new PrincipalContext(ContextType.Domain, “ipofmachine”, “DC=xyz,DC=org”, “username”, “Password”); UserPrincipal userPrinciple = UserPrincipal.FindByIdentity(context, “User0”); var groups = userPrinciple.GetAuthorizationGroups(); if (userPrinciple != null) { foreach (GroupPrincipal gp in groups) { //some thing } } 我需要给予任何许可吗? 在一些博客中,我了解到,如果没有设置为包含SID历史记录的用户,那么这将正常工作(但我认为您无法编辑组的sid值)

Active Directory PrincipalContext.ValidateCredentials域消除歧义

我正在处理两个域 – 一个是可信域。 一个域上可能有JohnSmith,另一个域上可能有另一个JohnSmith。 这两个人都需要登录我的应用程序。 我的问题:我传入哪个域无关紧要 – 此代码返回true! 我怎么知道JohnSmith正在登录哪个? static public bool CheckCredentials( string userName, string password, string domain) { using (var context = new PrincipalContext(ContextType.Domain, domain)) { return context.ValidateCredentials(userName, password); } }

使用Azure AD时,将用户重定向到自定义登录页面

我正在使用以下代码示例将Azure AD登录插入我的应用程序( https://github.com/AzureADSamples/WebApp-OpenIDConnect-DotNet )。 我发现代码工作得很好,但是如果用户还没有登录或者他们的会话已经过期,我希望能够将用户重定向到自定义登录页面。 然而,我正在努力让这个工作,并想知道这是否确实可行? 是否按设计将用户始终重定向到Azure AD的Microsoft登录页面而不是您自己的自定义页面,或者是否有我错过的设置? 我修改了FilterConfig.cs提供的代码以启用Authorizefilter属性: filters.Add(new AuthorizeAttribute()); 我还在web.config添加了以下内容,但没有效果: 在Startup.Auth.cs文件中,我看不到app.UseOpenIdConnectAuthentication可以进行的任何更改,以允许我设置通用登录页面,因为我可能使用基于cookie的身份validation。