Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java REST service using authentication token

On my web app using Java EE 6. I want to expose some of my functionality as a Json Rest Service. I want to use authentication tokens for login, User will send their username, password and server will send back a token, which will be used to authorize the user on their further requests for a given time..

A few questions bothering me so far;

  • When the server creates the token and sends to client, should server save it in a DB OR in a Bean using something like a hashtable as userid-token pairs?

  • Can I get some help using any Java EE specific API or this has to be all custom code?

like image 237
Spring Avatar asked Dec 21 '12 09:12

Spring


1 Answers

Heres my input:

  • I would save the token in DB, in case you need to restart the server you don't want to lose all your user's tokens. You could potentially save it in memory as well to speed up requests and only look it up in DB if it is not found in memory.

  • I would accept the token in the header. I would put the rest service on HTTPS so the request is encrypted and then you don't need to worry about encrypting the token manually in the request

  • I would probably look at JAX-RS and see what features it offers

like image 106
cowls Avatar answered Oct 20 '22 05:10

cowls