August 2018
Intermediate to advanced
314 pages
8h 9m
English
AuthenticationResource is a JAX-RS resource, which makes it possible to log in and validates the authentication of an application. In the following code, we have its implementation:
import javax.inject.Inject;import javax.ws.rs.*;import javax.ws.rs.core.Response;import java.util.Date;import java.util.Optional;@Path("auth")public class AuthenticationResource { @Inject private AuthSession authSession; @POST @Consumes("application/x-www-form-urlencoded") public Response login(@FormParam("login") String login, @FormParam("password") String password ) { //If user already logged, then get it token Optional<String> key = authSession.getToken(login, password); if ( key.isPresent() ){ return Response. ...
Read now
Unlock full access