I need to do an authentication system (login password) on my web service.
Could you give me an example in java please ? I haven't find how I can do that.
Thanks a lot.
I need to do an authentication system (login password) on my web service.
Could you give me an example in java please ? I haven't find how I can do that.
Thanks a lot.
You can do the authentication in REST web services through different ways. The simplest is the BASIC authentication. When the server wants the user agent to authenticate itself towards the server, it can send a request for authentication. This request should be sent using the HTTP 401 Not Authorized response code containing a WWW-Authenticate HTTP header. The WWW-Authenticate header for basic authentication (used most often) is constructed as following:
WWW-Authenticate: Basic realm="insert realm"
From the web server/application perspective, you need to intercept the request using filters. In your filter class you can inspect for the request's HTTP headers and then do the validation. If validated you can forward the request to the actual web service otherwise simply send a 401 response.
Follow this SO post to learn more about doing this: