spring security - 用户有多个部门的多个角色。 - 如何指定角色?

时间:2014-01-13 02:40:10

标签: spring security role

我有用于身份验证的表格,如下所示,

雇员


id_employee,用户名,密码......


1,John,woefijlsdkjfu230rdfrfj
2,彼得,sdlautoerwjgosj120943820



employee_department


id_employee_department,employee_id,department_id,role ...


1,1,123123,ROLE_STAFF
2,1,123124,ROLE_MANAGER
...


John是123123部门的工作人员,同时他是123124的经理。

我编写了security-bean属性,

   <jdbc-user-service id="userService" data-source-ref="dataSource"
                users-by-username-query="select username, password, true from employee where username=?"
                authorities-by-username-query="select username, role from employee left join employee_department on id_employee = employee_id where username=?"/>

问题是,

John总是拥有ROLE_STAFF,ROLE_MANAGER。这意味着他可以访问123123部门的所有数据,并在访问123124时看到员工的无用信息。

...

避免这种情况的最佳做法是什么?

1 个答案:

答案 0 :(得分:0)

我解决了这个问题,将两个表与{department_id} _ {username}

这样的新列组合在一起

所以,

现在,只有一张关于员工的表。

employee
__
id_employee, username, password, role ...
__
1, 123123_John, woeurewoij12332, ROLE_STAFF ...
2, 123124_John, woeijfskdjfisahf2, ROLE_MANAGER ...
3, 123123_Peter, woieruweoriuo1231, ROLE_STAFF...
___

我还分离了Employee实体对象和dao服务来保护密码和角色。

无论如何,我解决了我的问题。有什么我无法想象的问题吗?