9

我目前正在评估身份验证/授权框架。

Apache Shiro 似乎非常好,但我缺少行级安全功能。

例如,数据库中可能有一些特殊的行,只有具有特殊权限的用户才能看到和访问。为了避免不必要的往返,我们目前修改 SQL 查询以加入我们的授权数据,以仅获取当前用户的可见行。

但是这个概念对我来说并不“正确”,因为我们将业务代码与安全相关的代码混合在一起,这些代码应该是正交且相互独立的。

  • 有哪些可用/可能的解决方案?
  • 您如何实现行级安全性(尤其是与 jpa 结合使用)

更新:

目标数据库主要是 Oracle 10g/11g
- 但如果没有大的缺点,最好使用独立于数据库的解决方案

4

3 回答 3

9

行级安全性最好在数据库本身中完成。当您获取连接时,必须告诉数据库您的用户上下文是什么。该用户与一个或多个安全组相关联。然后,数据库会自动将过滤器附加到用户提供的查询中,以过滤掉从安全组中看不到的内容。这当然意味着这是针对每个数据库类型的解决方案。

Oracle 有很好的行级安全支持, 例如http://www.orafusion.com/art_fgac.htm 。

于 2011-04-19T12:30:48.077 回答
2

我们将它实现为 JDBC 包装器。这个包装器只是解析和转换 SQL。Hibernate 过滤器也是个好主意,但是我们有很多报告和临时查询,Hibernate 并不是在我们的应用程序中访问数据的唯一工具。jsqlparser 是一个优秀的开源 SQL 解析器,但我们必须分叉它来解决一些问题并添加对一些高级 SQL 功能的支持,例如用于报告目的的 ROLLUP https://github.com/jbaliuka/sql-analytic 这个报告工具也是在 github 上可用,但不依赖于行级安全基础架构https://github.com/jbaliuka/x4j-analytic

于 2013-10-24T12:13:44.683 回答
0

There is a helpful article: http://mattfleming.com/node/243

The idea is that you can implement row level functionality in two ways: directly setting restrictions in your repository or binding the restrictions via AOP. The latter is preferred because security layer should be separated from business logic (orthogonal concerns).

In Hibernate you can use the concept of filters which are applied transparently and repository doesn't know about them. You can add such filters via AOP. The other way is intercepting session.createCriteria() and adding Restrictions to the Criteria transparently using AOP.

于 2011-06-05T08:18:56.617 回答