title: What's the difference between retrieving WindowsPrincipal from WindowsIdentity and Thread.CurrentPrincipal?
body: <p>I am trying to work out why attribute based security isn't working as I'd expect in WCF and I suspect it might have something to do with the following:</p>
  
  <pre><code>AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
  
  var identity = new WindowsIdentity("ksarfo");
  var principal = new WindowsPrincipal(identity);
  Console.WriteLine("\nChecking whether current user [" + identity.Name + "] is member of [" + groupName + "]");
  Console.WriteLine(principal.IsInRole(groupName)); // returns true
  
  principal = (WindowsPrincipal)Thread.CurrentPrincipal;
  identity = (WindowsIdentity) principal.Identity;
  Console.WriteLine("\nChecking whether current user [" + identity.Name + "] is member of [" + groupName + "]");
  Console.WriteLine(principal.IsInRole(groupName)); // returns false
  </code></pre>
  
  <p>I don't understand why the results differ for the function call:</p>
  
  <pre><code>principal.IsInRole(groupName)
  </code></pre>
  
  <p>For the sake of completeness the point at which the code actually fails is here:</p>
  
  <pre><code>PrincipalPermission(SecurityAction.Demand, Role = "PortfolioManager")]
  </code></pre>
  
  <p>Help appreciated.</p>