title: Java Jax-RS (Jersey) Backend & jQuery Frontend -> Security + Session
body: <p>I am currently developing a lightweight web application using Jax-RS on the server side (deployed on a tomcat 7 container) and HTML5, CSS3 and jQuery in the frontend.</p>
  
  <p>The connection works fine. What I don't know is how to secure the application. My idea is that a user may register through the frontend and is assigned to a default role (e.g. users). </p>
  
  <p>From then on, the user may login to the website and is able to e.g. register for a course or something like that. </p>
  
  <p>How can achieve this on a secure way? Is it best to use tomcats authentication (DIGEST or FORM)? Or is there another way? Like e.g. transmitting user &amp; password as MD5 hash in every request?</p>
  
  <p>It would be great if I could use @RolesAllowed Annotation in Ressource Class to annotate methods which should only be accessible for specific groups.</p>
  
  <p>And how can I store the user-data on the client? So that the user doesnt needs to sign in after every request? Do I have to use cookies for that?</p>
  
  <p>Another thing I'm not sure is how to store data from a shopping cart. Would it be a good idea to use a DB table on the server where I store all the shopping cart contents for a specific user? How do I have to identify the user there? How would the mapping between logged-in user and shopping-cart entry in table look like?</p>
  
  <p>I hope that someone can help me :-).</p>
  
  <p>Thanks in advance</p>
  
  <p>Greets</p>