WCF authentication does not impersonate administrator

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))
    {
        //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)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?

+3
2

( RandomNoob), , , , . , WCFUsers, , , . System.DirectoryServices.AccountManagement .

[OperationBehavior(Impersonation=ImpersonationOption.NotAllowed)]
public string SetPassword(string username)
{
    WindowsPrincipal principal = new WindowsPrincipal(OperationContext.Current.ServiceSecurityContext.WindowsIdentity);
    if (principal.IsInRole("WCFUsers"))
    {
        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
        return null;
}
0

article " Windows Vista", UAC Admin privs .

+3

Source: https://habr.com/ru/post/1768467/


All Articles