In my opinion, it is better to use basic or digest authentication via SSL for RESTful services. Other options include credentials as part of the payload or the creation of a special login service that accepts credentials and returns a token. There are various reasons why formal authentication is less suitable for the RESTful service: it requires a session, it does not use existing HTTP authorization, etc.
If you need to call RESTful using AJAX, then using an authentication cookie may be a valid solution. They should only affect whether the user can make a call, but not how the server responds.
If you want to use forms-based authentication for your application, I would suggest adding an additional JAAS authentication provider that will handle RESTful service authentication. You can read about it here .
Another option, which should be simpler than JAAS, would be to use Spring Security or Apache Shiro instead of container based validation. Here's an example of setting up form-based validation using Spring Security. This post shows an example of how to secure RESTful services with Spring Security.
source share