【发布时间】:2010-10-07 16:54:50
【问题描述】:
我正在尝试使用 WCF 来做一些远程用户管理的事情。我并重用了我在服务器 2003 机器上的一些代码并且工作正常,但是在我的 Windows 7 测试机器上,当我检查调用该函数的用户是否是管理员时,它说不是。
[OperationBehavior(Impersonation=ImpersonationOption.Required)]
public string SetPassword(string username)
{
WindowsPrincipal principal = new WindowsPrincipal(OperationContext.Current.ServiceSecurityContext.WindowsIdentity);
System.Diagnostics.Debug.Print(WindowsIdentity.GetCurrent().Name);
System.Diagnostics.Debug.Print(principal.Identity.Name);
if (principal.IsInRole(WindowsBuiltInRole.Administrator))
{
//try
{
lock (Watchdog.m_principalContext)
{
using (UserPrincipal up = UserPrincipal.FindByIdentity(Watchdog.m_principalContext, username))
{
string newpassword = CreateRandomPassword();
up.SetPassword(newpassword);
up.Save();
return newpassword;
}
}
}
//catch
{
return null;
}
}
else
throw new System.Security.SecurityException("User not administrator");
}
principal.IsInRole(WindowsBuiltInRole.Administrator) 每次都返回 false。我当前的身份和 principal.identity 都是要模拟的正确用户。并且该用户是管理员用户组的成员。
我认为这与在 windows vista 及更高版本中实现的 UAC 有关。这将是一个问题,因为这将要运行的生产机器是一个 win2k8-r2 机器。
有什么建议吗?
【问题讨论】:
标签: c# wcf uac impersonation