问题标签 [userprincipal]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
wcf - 从 Windows 服务调用 UserPrincipal.GetGroups 的超时异常
当我运行调用 UserPrincipal.GetGroups 的简单控制台应用程序时,它会毫无问题地枚举用户组。但是,当我在同一服务器上但从托管 WCF 的 Windows 服务运行与同一用户相同的代码时,我得到以下错误链:
这可能与 WCF 线程模拟有关吗? WindowsIdentity.GetCurrent().Name
返回相同的用户,但Thread.CurrentPrincipal.Identity.Name
不同 - 在控制台应用程序的情况下为空字符串,但在 Windoes 服务的情况下是模拟的 WCF 用户。
spring - Spring Security:手动设置用户主体
在具有 Spring MVC 和 Spring Security 的 Web 应用程序中。
有没有办法手动设置 UserPrincipal?
我需要通过我的 web 应用程序的管理部分切换到另一个用户。在我的控制器中,是否可以在请求中设置用户主体?就像我是其他人一样连接。
像这样:request.setUserPrincipal().getName()
.net - 如果存在与 SQL 相关的调用,则 UserPrincipal.FindByIdentity 返回 null,否则返回正确的 Principal 对象
我有这个奇怪的问题。我正在尝试创建一项服务,将数据库中的用户与 Active Directory(AD)中的电子邮件组中的用户同步。因此,如果 A、B、C 在数据库中并且活动目录电子邮件组有 A 和 E,我将同步 AD。所以我将添加“E”并删除“B”和“C”。
为了从数据库中获取用户,我执行 SQL 调用。之后,如果我尝试添加用户,我会得到 UserPrincipal.FindByIdentity 为空。这是我提出的测试代码。
这件作品完美无缺,我正确获取了“用户”对象,并且可以成功地将其添加到 AD 电子邮件组。问题是当我有 SQL 调用从数据库中获取 userId 而不是硬编码时。
所以有问题的代码是:
因此,在从数据库中获取用户之后,如果我调用:
我的“用户”返回为空。
有没有其他人遇到过同样的问题。DB调用和AD调用有什么问题。我的意思是,我关闭了我的数据库调用中的所有连接,然后尝试访问 Active Directory(AD)。
任何帮助表示赞赏。
谢谢, 迪克沙
.net - 获取结果类型为自定义派生 UserPrincipal 的 AD 组的成员
我创建了自己的派生 UserPrincipal 类型,用于获取一些扩展的 AD 属性。这工作正常。
现在我正在寻找一种方法来使用 groupprincipal 对象的 GetMembers() 方法来返回我的自定义 UserPrincipal 类型的列表。
FindByIdentityWithType 在 UserPrincipal 上的工作方式有点相同,其中有一个重载,您可以在其上指定自己的 PrincipalType。
有没有办法在 GetMembers 方法上做到这一点?
c# - 获取给定 UserPrincipal 的组列表
我想获取用户所在的组列表。
这是我的代码:
当我运行时,我在该行收到以下错误Response.Write(p.Name);
System.Runtime.InteropServices.COMException:指定的目录服务属性或值不存在。
当我检查结果的计数时,它返回 9 并且第一组是DomainUsers
.
如何迭代列表中的所有 9 个组?谢谢。
以下是我得到的用户列表:
c# - 使用 UserPrincipal 更改 AD 用户帐户属性
我正在尝试使用 UserPrincipal 更改 Active Directory 中的用户帐户属性。
我已经读到我们必须使用对 Active Directory 具有写访问权限的特殊帐户,而不是当前登录用户。所以,我创建了一个特殊的类来使用特殊帐户来模拟。但我仍然有
System.UnauthorizedAccessException: General access denied error
在 user.Save(ctx); 线。
我怎样才能达到这个要求?谢谢。
c# - ASP.NET MVC Windows Authentiaction 和 DirectoryServices - 获取当前用户的邮件地址会引发 InvalidCastException
我正在使用 ASP.NET MVC 4 和 Windows 身份验证。当我使用 VisualStudio 时,一切正常,但是当我部署我的站点时,会引发异常。
抛出:
无法将“System.DirectoryServices.AccountManagement.GroupPrincipal”类型的对象转换为“System.DirectoryServices.AccountManagement.UserPrincipal”类型。
其余的工作正常。用户可以进行身份验证,我可以获取用户名等。
编辑:
我在 IIS 上启用了模拟。现在我得到以下异常:
[DirectoryServicesCOMException (0x80072020):发生操作错误。] System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +781 System.DirectoryServices.DirectoryEntry.Bind() +44 System.DirectoryServices.DirectoryEntry.get_AdsObject() +42 System.DirectoryServices.PropertyValueCollection.PopulateList() +29
System.DirectoryServices .PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) +119
System.DirectoryServices.PropertyCollection.get_Item(String propertyName) +163
System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer() +535649 System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() +51 System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() +141 System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() +42 System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate) +27
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType,字符串标识值)+146
System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue) +44
System.DirectoryServices.AccountManagement.UserPrincipal.get_Current() +390 Jericho.MVC.HtmlHelperExtensions.GetUser(HtmlHelper htmlHelper) 在 C:\Development \Jericho\Jericho.MVC\HtmlHelperExtensions.cs:48
我能做些什么?
c# - 使用 PrincipalSearcher.FindAll() 时的内存泄漏
我也有使用插件和应用程序域的长期运行服务,并且由于使用目录服务而出现内存泄漏。请注意,我使用的是 system.directoryservices.accountmanagement,但据我了解,它使用相同的底层 ADSI API,因此容易出现相同的内存泄漏。
我查看了所有的 CLR 内存计数器,内存没有泄漏,并且在强制 GC 或卸载 appdomain 时全部返回。泄漏是在不断增长的私有字节中。我在这里搜索并看到了一些与使用 ADSI API 时内存泄漏相关的问题,但它们似乎表明只需遍历 directorysearcher 即可解决问题。但正如您在下面的代码中看到的那样,我在 foreach 块中执行此操作,但内存仍在泄漏。有什么建议么?这是我的方法:
我对 foreach 循环进行了以下更改,它更好,但私有字节仍在增长并且永远不会被回收。
asp.net - System.DirectoryServices.AccountManagement.UserPrincipal - localhost 但不是 iis
为什么下面的代码在我运行我的 Web 应用程序 localhost 时可以正常工作,但在我将其安装到 IIS 服务器时却不行?
请不要建议我坚持,HttpContext.Current.User
因为它不提供对 SID 或 UPN 的访问,而无需额外调用 Active Directory。
Web 应用程序将由来自三个独立域的 Windows 身份验证用户使用,Web 服务器托管在第四个域中。应用程序池配置为在NetworkService
身份下运行,并且 Web 应用配置将身份模拟设置为 true。
在 IIS 上运行时的错误消息是:
Page_Load() 中的错误:UserPrincipal.Current。
System.InvalidCastException:无法将“System.DirectoryServices.AccountManagement.GroupPrincipal”类型的对象转换为“System.DirectoryServices.AccountManagement.UserPrincipal”类型。
在 System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue)
在 System.DirectoryServices.AccountManagement.UserPrincipal.get_Current()
在 webapp.Details.Default.Page_Load(Object sender, EventArgs e)
编辑:尝试了以下两种方法,不幸的是得到了同样的错误。
c# - 使用 UserPrincipal 检查本地管理员是否
我正在尝试使用一种方法来接收用户名,如果该用户是本地管理员(不是在整个域上,只是在本地机器上),则返回 true,否则返回 false。我试图改变In .NET/C# test if process has administrator permissions to work 中发现的技术,但它没有。我曾尝试使用 NetUserGetInfo 方式,但无法使其正常工作。现在我正在尝试使用 UserPrincipal。下面的代码就是我所拥有的...主要只是测试基础知识是否有效并且它们确实有效。
看起来我应该可以使用 isMemberOf 方法,但是如何为本地管理员创建一个组?还是有比 isMemberOf 方法更好的方法?