简体   繁体   English

Java EE服务器上的动态角色

[英]dynamic roles on a Java EE server

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". 例如,该应用程序的用户(“customerX boss”)可以创建新角色“customerX employee”。 If an employee accesses the Java EE application server (GlassFish 3) he should get the role "customerX employee". 如果员工访问Java EE应用程序服务器(GlassFish 3),他应该获得角色“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. 这听起来很简单,但Java EE不支持它,因为组在启动时映射到角色,应用程序中的角色是静态的。

What is the best way to manage user roles at runtime in a Java EE (6) environment? 在Java EE(6)环境中在运行时管理用户角色的最佳方法是什么?

The declarative security in Java EE is indeed no suited for such requirements. Java EE中的声明性安全性确实不适合这样的要求。 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. 我们使用内置身份验证来设置主体,然后依赖于默认的Java EE登录机制。 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. 事实上,即使是将被载入且与主体(关联的角色isUserInRole网页和isCallerInRole对于EJB)需要到指定web.xmlejb.xml不提供足够的灵活性。 We had then to load the roles manually (according to the principal) from LDAP or ActiveDirectory. 然后我们从LDAP或ActiveDirectory手动加载角色(根据主体)。 We then used EJB3 interceptors and Servlet filter to perform the security checks ourselves. 然后我们使用EJB3拦截器和Servlet过滤器来自己执行安全检查。

I would however strongly suggest to stick to a Role-based access control (RBAC) and not implement something more fancy. 但是,我强烈建议坚持使用基于角色的访问控制(RBAC),而不是实现更加花哨的东西。 There are several frameworks that can help to deal with home-made RBAC. 有几个框架可以帮助处理自制的RBAC。

We also had a look at JSecurity and Acegi Security and they seemed interesting. 我们还看了一下JSecurityAcegi Security ,看起来很有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM