简体   繁体   English

如何在java中实现权限控制?

[英]How to implement permission control in java?

We developed a application, and need to implement permission control, which means someone can only search specific records in database: 我们开发了一个应用程序,需要实现权限控制,这意味着有人只能搜索数据库中的特定记录:

  1. staff can only search their own records. 员工只能搜索自己的记录。
  2. supervisor can search records of his subordinate. 主管可以搜索其下属的记录。
  3. supervisor can see the "approve" button to approve the application 主管可以看到“批准”按钮来批准申请
  4. while staff can only submit application. 工作人员只能提交申请。

I know spring security, but actually how can we use the spring security to implement the function above? 我知道spring安全性,但实际上我们如何使用spring security实现上面的功能呢?

We can implement the permission control with SQL, which means select his role first, and then select all his subordinate's records like this: 我们可以用SQL实现权限控制,这意味着首先选择他的角色,然后选择他所有的下属记录,如下所示:

select * from table where staffid in (.......)   

But this method seems just too raw, and hard to maintain. 但这种方法看起来太原始,难以维护。 So my question is: is there any framework and practice that we can use to implement a decent permission control mechanism? 所以我的问题是:我们可以使用任何框架和实践来实现一个体面的权限控制机制吗? How do you implement permission control in your application? 如何在应用程序中实现权限控制?

1) staff can only search their own records. 1)员工只能搜索自己的记录。 2) supervisor can search records of his subordinate. 2)主管可以搜索其下属的记录。

These seem like rules you'd have to implement at the DAO layer 这些似乎是您必须在DAO层实现的规则

3) supervisor can see the "approve" button to approve the application 3)主管可以看到“批准”按钮来批准申请

--This can be accomplished through UI Role-based rendering in JSF - 这可以通过JSF中基于UI角色的渲染来完成

4) while staff can only submit application. 4)工作人员只能提交申请。

Spring Security Method Interceptors can be used here: http://static.springsource.org/spring-security/site/docs/3.0.x/reference/secure-object-impls.html Spring安全方法拦截器可以在这里使用: http//static.springsource.org/spring-security/site/docs/3.0.x/reference/secure-object-impls.html

Using postgres databases, you can inherit tables from tables. 使用postgres数据库,您可以从表继承表。 ie: 即:

CREATE TABLE access{
  admin bool default false,
  supervisor bool default false,
  staff_user_id bigint default null,
   ...
}
CREATE TABLE flower(
  flower_id serial,
  name varchar(24)
)inherits (access)

And then you can create an update/delete trigger, and differend connection-users. 然后,您可以创建更新/删除触发器,并区分连接用户。

This may be an solution. 这可能是一个解决方案。

正如您所说,实体“角色”和“业务数据”必须在数据库中保持独立 - 您可以加入角色表并仅选择适当的数据,而不是多次调用数据库。

如果您尚未确定它太复杂,您应该查看Spring Security ACL

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

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