【问题标题】:spring security - user have multiple roles for multiple departments. - how to specify the role?spring security - 用户拥有多个部门的多个角色。 - 如何指定角色?
【发布时间】:2014-01-31 17:06:23
【问题描述】:

我有如下认证表格,

员工


id_employee、用户名、密码...


1,约翰,woefijlsdkjfu230rdfrfj
2、彼得,sdlautoerwjgosj120943820



员工部门


id_employee_department、employee_id、department_id、角色...


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也可以看到对员工无用的信息。

..

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

【问题讨论】:

    标签: spring security role


    【解决方案1】:

    我解决了这个问题,将两个表与 {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服务来保护密码和角色。

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

    【讨论】:

      猜你喜欢
      • 2011-08-02
      • 2011-01-07
      • 2019-12-19
      • 2016-10-14
      • 2018-09-22
      • 2015-08-15
      • 2011-07-21
      • 1970-01-01
      • 2017-01-24
      相关资源
      最近更新 更多