簡體   English   中英

澤西島Restful API驗證

[英]Jersey Restful API Validation

我如何使用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;
}

最好將安全性視為獨立於REST資源的一個方面。

我建議讓您的托管容器或上下文處理此問題。 您的資源可以訪問容器提供的此信息。

有關如何使用JavaEE領域配置應用程序的信息,請參見https://jersey.java.net/documentation/latest/security.html

要將Spring用作安全解決方案,請參見http://projects.spring.io/spring-security/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM