【问题标题】:Jersey Restful API ValidationJersey Restful API 验证
【发布时间】:2013-09-22 12:45:06
【问题描述】:

如何使用 jersey restful API 验证用户名和密码。

下面是代码:

我尝试使用 HttpRequest 和 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;
}

【问题讨论】:

  • 看起来您需要与设计您的身份验证系统的人交谈。

标签: java jersey restful-authentication


【解决方案1】:

最好将安全性作为独立于 REST 资源的一个方面来处理。

我建议让您的托管容器或上下文处理此问题。您的资源可以访问容器提供的这些信息。

有关如何使用 JavaEE 领域配置应用程序的信息,请参阅https://jersey.java.net/documentation/latest/security.html

关于使用 Spring 作为安全解决方案,请参阅 http://projects.spring.io/spring-security/

【讨论】:

    猜你喜欢
    • 2014-07-04
    • 2014-12-08
    • 1970-01-01
    • 2011-11-28
    • 2013-07-25
    • 2013-08-21
    • 1970-01-01
    • 2012-04-17
    • 2011-10-02
    相关资源
    最近更新 更多