REST HTTP 身份验证 - 如何进行?
因此,我正在使用 RESTeasy 和 Google App Engine 开发 REST Web 服务。我的问题与 GAE 无关,但我提到它只是为了以防万一。碰巧我自然需要保护我的资源和我自己的用户(而不是谷歌的)。
确保 REST Web 服务的安全似乎是一个非常有争议的主题,或者至少是一个非常“自由”的主题。 REST 并没有在这个问题上强加任何标准。根据我对网络和文献的研究,我认为至少有 3 种方法可能适合我的应用程序:
- HTTP Basic(使用 SSL)
- HTTP Digest(使用 SSL)
- OAuth
OAuth 似乎是最完整的方法。但我认为不需要如此复杂,因为我不需要授权任何第三方应用程序。它是一个仅由我自己的客户端应用程序使用的 Web 服务。
HTTP Basic 和 HTTP Digest 在网络上看起来是最简单的,但事实是我从未使用 RESTeasy 找到它们的具体实现。 我找到了此页面 和这个在 RESTeasy 的文档中。它们确实非常有趣,但是它们在这个主题上几乎没有提及任何内容(HTTP Basic 或 Digest)。
所以,我在这里问:
如何在 RESTeasy 中使用 HTTP Basic 或 Digest 来保护我的 WebService 的安全?
也许它是如此简单,以至于不值得在文档或其他任何地方提及? 另外,如果有人可以向我提供一些有关保护 RESTful Web 服务的见解,这可能会有所帮助。
我选择了正确的方法吗?
So, I'm developing a REST webservice using RESTeasy and Google App Engine. My question isn't related to GAE, but I mentioned it just in case it matters. It happens that naturally I need to secure my resources and my own users (not Google's).
Securing a REST webservice seems like a very controversial subject, or at least a very 'liberal' one. REST doesn't impose any standard on this matter. From what I've researched on the web and literature, there are at least 3 approaches that I think might fit in my application:
- HTTP Basic (with SSL)
- HTTP Digest (with SSL)
- OAuth
OAuth seems like the most complete approach. But I don't think that such a complexity is needed because I will not need to authorize any 3rd party applications. It is a webservice to be consumed by my own client applications only.
HTTP Basic and HTTP Digest appear as the most simple ones on the web, but the fact is that I've never found a concrete implementation of them using RESTeasy, for example.
I've found this page and this one in RESTeasy's documentation. They are indeed very interesting, but they tell little or nothing on this subject (HTTP Basic or Digest).
So, here I am asking:
How do I secure my WebService using HTTP Basic or Digest in RESTeasy?
Perhaps it is so simple that it isn't worth mentioning in the documentation or anywhere else?
Also, if anyone can provide me some insight on the matter of securing RESTful webservices, it could be helpful.
Am I choosing the right approaches?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
保护 REST API 安全的最简单方法是使用基于 SSL 的 HTTP 基本身份验证。由于标头已加密,因此使用摘要没有多大意义。只要您能够保证客户端上密码的安全,这应该会很有用。
The simplest way to secure a REST API is to use HTTP Basic authentication over SSL. Since the headers are encrypted there is not much point of using Digest. This should work great as long as you can keep the password secure on the client(s).
我已经通过使用 RESTeasy 的拦截器成功地实现了这一点。
基本上,请求是通过使用类似侦听器的类来拦截的。在此类中,我检查请求的 HTTP 标头,然后继续正常的基本身份验证过程。
有用的链接:
http://en.wikipedia.org/wiki/Basic_access_authentication
使用 REST API 在消息标头中传递参数
http://www.alemoi.com/dev/httpaccess/ (Servlet 部分)
我希望这对任何人都有帮助。
谢谢。
I've managed to accomplish this by using RESTeasy's Interceptors.
Basically the requests are intercepted by using a listener like class. In this class I inspect for the request's HTTP headers and then the normal Basic-Auth process goes on.
Useful links:
http://en.wikipedia.org/wiki/Basic_access_authentication
Passing parameters in the message header with a REST API
http://www.alemoi.com/dev/httpaccess/ (the Servlet part)
I hope this helps anyone.
Thanks.
使用任何没有 SSL 的身份验证方法时,您肯定会面临安全风险。
但如果您确实使用了 SSL,通常会遇到性能不佳的问题。
Oauth 实际上是一个允许第三方访问您的 Web 服务的解决方案。
由于选择有限,我对当前需要身份验证的Web服务的解决方案使用了SSL+basic的组合
you will definitely face a security risk when using any authentication method without SSL.
but if you did use SSL, you will usually suffer from a poor performance.
Oauth is actually a solution to allow 3rd party to obtain access to your webservices.
due to the limited selection, my solution to a current webservices that require authentication used the combination of SSL+basic
您可能会考虑使用 OAuth 2。它比 OAuth 1 简单得多,并且 Facebook 和 Google 正在积极将其用于大型 REST API。
You might look at using OAuth 2. It is significantly simpler then OAuth 1 and is actively being used on large REST API by Facebook and Google.