title: Having a problem with RequiresRole attribute on RIA Domain service
body: <p>My question is similar to this <a href="https://stackoverflow.com/questions/3694277/problem-with-wcf-ria-services-requiresrole-attribute">question</a>.  I hope I can provide some more detail and context to get it answered.</p>
  
  <p>So here's some context: I have a simple in-house silverlight (ver 4) app with WCF Ria services that I'm building for our small support team.  It uses authentication against a third-party vended database, but all other user information, e.g. FriendlyName and Roles (only 1 role per user) comes from our own database.  I'm trying to keep this simple and don't want to implement custom membership and role providers.</p>
  
  <p>I have few domain service operations that I want to restrict to certain roles, so I tried using the <code>RequiresRole</code> attribute like so:</p>
  
  <pre><code>[RequiresRole("Admin", "HelpDesk", "Billing" )]
  public RisStudyInfo GetStudyInfo(string accession) {
      return ris.GetStudyInfo(accession);
  }
  </code></pre>
  
  <p>On the client side <code>WebContext.Current.User.IsInRole("Admin")</code> returns true, but I always get access denied when calling the service.  The <code>RequiresAuthentication</code> attribute works as expected.</p>
  
  <p>Below is the implementation of my <code>AuthenticationService</code>. The <code>User</code> class simply inherits from <code>UserBase</code> and adds the FriendlyName property. Any ideas what I'm doing wrong?</p>
  
  <pre><code>[EnableClientAccess]
  public class AuthenticationService : AuthenticationBase&lt;User&gt; {
  
      UserDataService userData = new UserDataService();
  
      protected override bool ValidateUser(string userName, string password) {
          var auth = new DatabaseAuthenticator();
          return auth.Authenticate(userName, password);
      }
  
      protected override User GetAuthenticatedUser(IPrincipal principal) {
          User user = null;
          if (principal.Identity.IsAuthenticated) {
              user = new User();
              user.FriendlyName = userData.GetFriendlyName(principal.Identity.Name);
              user.Name = principal.Identity.Name;
              user.Roles = GetRolesFor(user.Name);
          }
          return user;
      }
  
      private IEnumerable&lt;string&gt; GetRolesFor(string username) {
  
          IList&lt;string&gt; roles = new List&lt;string&gt;();
  
          string role = userData.GetRolesFor(username);
          if (role != null)
              roles.Add(role);
  
          return roles;
      }
  </code></pre>