簡體   English   中英

在 Apache Jersey 中進行身份驗證而不使用 Http 身份驗證?

[英]Authentication in Apache Jersey without using Http-Authentication?

我正在使用 Apache Jersey 構建一個 RESTful Web 服務。 現在我希望您需要對某些請求進行身份驗證。 使用典型的 REST 方法,身份驗證應該通過 HTTP 身份驗證完成。 但是這里的一篇文章提到,更好的方法是使用 cookies。 我認為討論中有一些有效的觀點。 (如何)我可以使我的 Jersey 身份驗證與 Cookies 一起使用嗎? 我需要另一個框架嗎?

Jersey uses the authentication mechanism declared in the enclosing web application's web.xml, practically either HTTP Authentication (over SSL) or Form-based Cookie authentication.

如果要使用基於 cookie 的 session 身份驗證,用戶必須先使用 web 服務進行身份驗證,以創建 session 來檢查他們的身份。 The servlet spec provides a standardized way to authenticate using cookies and session using a web form, which however, is not compatible to a web service type of application. 因此,您可能想要制定一些自定義解決方案,讓用戶通過發布 XML 或 JSON 文檔來提交他們的憑據。 這種方法的一個問題是,如果用戶在沒有首先進行身份驗證的情況下或在 session 過期之后執行對資源的調用,他們將需要重定向或接收某種類型的錯誤代碼。 並非不可能,但它會增加 web 服務的復雜性。

此時您不得不懷疑使用 HTTP Auth 是否不是 web 服務風格應用程序的更好選擇。 我們最近使用 Jersey 和 HTTP Auth 作為身份驗證機制構建了 web 服務。 然后我們在其上構建一個 Javascript 前端。 The Javascript client always submits the Authentication headers to the web service so that the user is never confronted with the HTTP Auth authentication window from the browser. 也許是兩全其美。

暫無
暫無

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

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