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

spring security-用户对多个部门具有多个角色。-如何指定角色?,spring,security,role,Spring,Security,Role,我有如下用于身份验证的表 雇员 id\u员工、用户名、密码 1,John,woefijlsdkjfu230rdfrfj 2,Peter,sdlautoerwjgosj120943820 员工服务部 id\员工\部门,员工\ id,部门\ id,角色 1、1、123123、角色和工作人员 2,1,123124,角色经理 约翰是123123部门的员工,同时也是123124部门的经理 我写了安全bean属性 <jdbc-user-service id="userServic

我有如下用于身份验证的表

雇员


id\u员工、用户名、密码


1,John,woefijlsdkjfu230rdfrfj
2,Peter,sdlautoerwjgosj120943820



员工服务部


id\员工\部门,员工\ id,部门\ id,角色


1、1、123123、角色和工作人员
2,1,123124,角色经理


约翰是123123部门的员工,同时也是123124部门的经理

我写了安全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=?"/>

问题是,

约翰总是有工作人员和经理。这意味着他可以访问123123部门的所有数据,在访问123124时也可以看到员工的无用信息


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

我解决了这个问题,将两个表与一个新列(如{department\u 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服务来保护密码和角色

不管怎样,我解决了我的问题。有什么我无法想象的问题吗