title: How to authenticate users in Jersey
body: <p>I am writing a RESTful application in Java using Jersey, and i need to authenticate users. I know i can specify the roles in the resource using the annotations @RolesAllowed, but i can't understand how a user is associated to a specific role. The client sends username and password in this way</p>
  
  <pre><code>    HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(user, password);
      Client client = ClientBuilder.newClient();
      client.register(feature);
      WebTarget target = client.target(baseUrl).path(urlString);
      Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON);
      Response response = invocationBuilder.get();
  </code></pre>
  
  <p>Supposing that some methods can be used only by superusers and others by any user, how can i distinguish them when the username and the password are sent by the client?</p>