I am trying to use WCF to work with remote users. I reuse the code that I had on the server 2003 and worked fine, but in the Windows 7 verification window, when I check if the user calling the function is an administrator, he says that this is not so.
[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))
{
{
lock (Watchdog.m_principalContext)
{
using (UserPrincipal up = UserPrincipal.FindByIdentity(Watchdog.m_principalContext, username))
{
string newpassword = CreateRandomPassword();
up.SetPassword(newpassword);
up.Save();
return newpassword;
}
}
}
{
return null;
}
}
else
throw new System.Security.SecurityException("User not administrator");
}
principal.IsInRole(WindowsBuiltInRole.Administrator)returns false every time. And my current identity, and principle. Correctness is the right user to impersonate him. and this user is a member of the administrators user group.
I think this is due to UAC, which was implemented in Windows Vista and above. this will be a problem, because the production machine on which this will occur is a win2k8-r2 box.
Any suggestions on what to do?