REST 中的安全性,以编程方式将用户添加到组

发布于 2024-12-25 10:35:53 字数 686 浏览 1 评论 0原文

嗯,我是 Java Web 服务的新手,我需要开发一个具有一些基本安全性的快速应用程序。我正在用JAVA开发一些REST服务,比方说: http://www.example.com/customer (是带有 POST、GET、PUT 的 CRUD 的 URL , 删除), http://www.example.com/product (是带有 POST、GET、PUT 的 CRUD 的 URL 、删除),现在我希望管理员用户对产品执行所有 CRUD 操作。另外,我希望客户只对产品执行 GET,并且我想让他们能够在 DB 中注册。即客户可以注册,然后可以查看产品并可以购买。问题是,当我尝试实现安全性时,我需要从 glassfish 管理控制台手动添加客户(用户)。我如何实现这样的功能:

1)未经身份验证的用户尝试通过../product查看产品

2)应用程序返回401请求。

3) 用户在应用程序中注册为客户(假设通过 POST ../customer)

4) 用户尝试再次查看产品(作为经过身份验证的客户),应用程序返回产品。

5) 用户尝试创建产品并收到 401 错误代码。

先感谢您, 埃尔维斯。

Well I am new to Java web services and I need to develop a quick application with some basic security. I am developing some REST services with JAVA, let say:
http://www.example.com/customer (is the URL for CRUD with POST, GET, PUT, DELETE),
http://www.example.com/product (is the URL for CRUD with POST, GET, PUT, DELETE), now I want admin users to perform all CRUD operations over products. Also I want customers to perform only GET on products, and I want to give them the possibility to register in DB. i.e. the customer can register and than can see products and can buy. The problem is that when I try to implement security I need to manually add a customer (a user) from glassfish admin console. How can I implement such functionality:

1) An non authenticated user try to see products through ../product

2) The application return a 401 request.

3) The user register as a customer to application (let say through POST ../customer)

4) The user try to see products again (as an authenticated customer) and the application return the products.

5) The user try to create products and it receives a 401 error code.

Thank you in advance,
Elvis.

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

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

发布评论

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

评论(1

所谓喜欢 2025-01-01 10:35:53

您可以使用容器提供的会话管理,也可以自己实现。会话是必需的,因为 HTTP(它构建于其之上的 REST)是无状态的。

有许多 Jersey + Jackson 教程,可以为您提供宠物店风格的功能(如果您用 Google 搜索)。

使用 Spring Security 的 Jersey REST 服务的用户身份验证详细信息如下:
Jersey REST 服务上的用户身份验证

You can either use session management as provided by the container, or implement it yourself. Sessions are required because HTTP (which REST it built on top of) is stateless.

There's a number of Jersey + Jackson tutorials out there which give you pet-store style functionality (if you Google).

User Authentication a Jersey REST service using Spring Security is detailed here:
User authentication on a Jersey REST service

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