0

how can i validate user name and password using jersey restful API.

Here is the code Below:

I tried using the HttpRequest and HttpResponse

@POST
@Path("/login")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public String postLoginJson(@FormParam("userName") String userName,
        @FormParam("password") String password) {

    String user = null;
    try {
        user = userObjectJson();
    } catch (JSONException e) {

        e.printStackTrace();
    }

    System.out.println("User Name = " + userName);
    System.out.println("Password = " + password);

    return user;
}
Fouad Fodail
  • 2,653
  • 1
  • 16
  • 16
  • Looks like you'll need to speak with whomever is designing your authentication system. – Will Sep 17 '13 at 22:13

1 Answers1

1

Security is best handled as an aspect independent of your REST resources.

I suggest letting your hosting container or context handle this. Your resources can access this information, as provided by the container.

For information on how to configure your application using JavaEE realms, see https://jersey.java.net/documentation/latest/security.html

For using Spring as a security solution, see http://projects.spring.io/spring-security/

cmonkey
  • 4,256
  • 1
  • 26
  • 46