title: determine roles that have access to an item in Sitecore - in code
body: <p><strong>Sitecore 6.5</strong> system:
  In code, is there a way to determine which roles have access to a specific item?</p>
  
  <p>I have an extranet set up, some items are "protected" - meaning the anonymous account has had the inheritance broken, and certain roles have been granted read access.  I already have a custom pipeline built, so I can determine when user attempts to view a protected item, but I need to determine what role(s) has access to view the item so I can direct them appropriately.</p>
  
  <p>Thanks,
  Thad</p>
  
  <p><strong>edit:</strong></p>
  
  <p>Here is the relevant code - there may be a better way of doing this (I inherited the system &amp; code), but I am attempting to utilize what was already in place. The problem with the code below is that Sitecore.Context.Item is null when the user doesn't have permission.</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class NotFoundProcessor : Sitecore.Pipelines.HttpRequest.HttpRequestProcessor
  {
      public override void Process(Sitecore.Pipelines.HttpRequest.HttpRequestArgs args)
      {
          if (args.PermissionDenied)
          {
              //determine what role would give the user access
              foreach(Sitecore.Security.Accounts.Role role in Sitecore.Security.Accounts.RolesInRolesManager.GetAllRoles())
              {
                  bool roleCanRead = Sitecore.Context.Item.Security.CanRead(role);
  
                  //... do stuff here
  
              }
          }
      }
  }
  </code></pre>