JAX-RS访问控制

发布于 2024-07-26 17:00:32 字数 114 浏览 2 评论 0原文

有人可以为我提供一些有关 JAX-R Web 服务中的访问控制的指示吗? 例如,根据用户凭证、姓名或任何其他标准限制访问。 在sun手册中找不到任何有用的信息。

提前致谢, 阿迪尔

Can some one provide me some pointers about access control in JAX-Rs web services. e.g. limiting access on the basis of user credentials, or name or any other criteria. Could not find any useful information in the sun manuals.

Thanks in advance,
Adhir

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十秒萌定你 2024-08-02 17:00:32

我个人使用 Spring security 来完成此任务。 Spring security 允许轻松使用各种身份验证和授权方案(例如,通过针对数据库或 LDAP 服务器检查 HTTP 请求中的基本/摘要标头)。 使用 JAX-RS 设置并不难,并且还有一个基于方面的漂亮权限系统,您可以在其中执行以下操作

@PreAuthorize("hasRole('ROLE_ADMIN') 或 order.customer.username == user.username)
删除订单(订单订单);

这确保经过身份验证的用户必须位于ROLE_ADMIN组中或者是订单的所有者才能删除它。

配置完成后,您在 JAX-RS 资源中要做的就是处理来自 spring 的安全异常并采取适当的操作(fx. 通过抛出 WebApplicationException 作为此处描述

I personally use Spring security to accomplish this. Spring security allows for easy use of various authentication and authorizations schemes (E.g. by checking the basic/digest headers from the HTTP request against a database or LDAP server). It's not to hard to set up with JAX-RS and also has a nifty aspect based rights system where you can do stuff like

@PreAuthorize("hasRole('ROLE_ADMIN') or order.customer.username == user.username)
deleteOrder(Order order);

which ensures that a authenticated user must either be in the ROLE_ADMIN group or be the owner of the order to be allowed to delete it.

When this is configured all you have to do in your JAX-RS resource is to handle the Security exception from spring and take the appropriate action (fx. by throwing a WebApplicationException as described here)

风月客 2024-08-02 17:00:32

人们可以通过多种方法来实现这一目标,并且本网站上有许多关于该主题的精彩主题(请参阅保护 REST API/Web 服务的最佳实践

我个人使用 OAuth 来完成此任务。 有关 OAuth 的更多信息,请参阅OAuth 初学者指南

There are many ways that people have accomplished this and there are a number of great threads on the topic on this site (see Best Practices for securing a REST API / web service)

I personally use OAuth to accomplish this task. For more information on OAuth check out Beginner’s Guide to OAuth

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文