Java EE 服务器上的动态角色

发布于 2024-08-20 23:52:26 字数 235 浏览 3 评论 0原文

我想在专用应用程序中管理用户和角色。例如,此应用程序的用户(“customerX 老板”)可以创建新角色“customerX 员工”。如果员工访问 Java EE 应用程序服务器 (GlassFish 3),他应该获得“customerX 员工”角色。

听起来很简单,但 Java EE 不支持它,因为组在启动时映射到角色,而应用程序中的角色是静态的。

在 Java EE (6) 环境中运行时管理用户角色的最佳方法是什么?

I want to manage user and roles in a dedicated application. For example a user of this application ("customerX boss") can create a new role "customerX employee". If an employee accesses the Java EE application server (GlassFish 3) he should get the role "customerX employee".

It sounds simple, but it is not supported by Java EE, because groups are mapped to roles at start-up time and the roles within the application are static.

What is the best way to manage user roles at runtime in a Java EE (6) environment?

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

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

发布评论

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

评论(1

‘画卷フ 2024-08-27 23:52:26

Java EE 中的声明式安全性确实不适合此类需求。安全问题可以分为两部分:

  • 身份验证
  • 授权

我曾经有过类似的要求。我们使用内置身份验证来设置主体,然后依赖默认的 Java EE 登录机制。但我们最终在应用程序级别手动管理授权部分。

事实上,即使是要加载并与主体关联的角色(对于 Web 来说是 isUserInRole ,对于 EJB 来说是 isCallerInRole )也需要在 web.xml 中指定ejb.xml 无法提供足够的灵活性。然后,我们必须从 LDAP 或 ActiveDirectory 手动加载角色(根据主体)。然后我们使用 EJB3 拦截器和 Servlet 过滤器自行执行安全检查。

然而,我强烈建议坚持基于角色的访问控制(RBAC),而不是实现更奇特的东西。有几个框架可以帮助处理自制的 RBAC。

我们还查看了 JSecurityAcegi Security 他们看起来很有趣。

The declarative security in Java EE is indeed no suited for such requirements. The problem of security can be split in two:

  • authentication
  • authorization

I had similar requirement once. We used the built-in authentication to have the principal set and relied then on the default Java EE login mechanisms. But we ended up managing the authorization part manually at the applicative-level.

Indeed, even the roles that will be loaded and associated with the principal (isUserInRole for the web and isCallerInRole for the EJB) need to be specified in web.xml or ejb.xml which doesn't provide enough flexibility. We had then to load the roles manually (according to the principal) from LDAP or ActiveDirectory. We then used EJB3 interceptors and Servlet filter to perform the security checks ourselves.

I would however strongly suggest to stick to a Role-based access control (RBAC) and not implement something more fancy. There are several frameworks that can help to deal with home-made RBAC.

We also had a look at JSecurity and Acegi Security and they seemed interesting.

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