基于 DSL 的数据过滤
我们的产品是特定于域的产品。以下是一些典型的安全用例,
- 普通用户只能编辑他的个人资料数据或基于权限的任何数据
- 用户只能看到属于他部门的数据,而另一个用户可以数据来自所有部门
这些要求因客户而异,因此我们不能只是在应用程序代码中硬编码过滤逻辑或维护应用程序的多个版本。
我们使用基于 Hibernate 标准的过滤,并希望根据与权限关联的某些表达式添加额外的限制。上面提到的用例 1 的表达式可能如下所示,'userId=user.userId'
,其中“user”是关键字,表示当前经过身份验证的用户,“userId”是为其创建条件的对象。
我们想要定义一个 dsl,使用它我们可以导出条件限制以及 sql 的“where”子句。
是否有任何现有的框架可以让我们在不使用 dsl 的情况下做到这一点?基于上述用例,您认为可以通过不同的方式来实现吗?
附加信息:我们仅定义具有一些元信息的域对象来生成 UI。持久性、安全性等由我们的核心框架负责。
Our's is a product specific to a domain.Here are some of the typical security use cases,
- A normal User can edit only his profile data or anybody data based on permission
- A user can see only data that belongs to his department while another user can data from all departments
These requirements changes from customer to customer so we can not just hard code the filtering logic in our application code or maintain multiple versions of the application.
We use Hibernate criteria based filtering and like to add additional Restrictions based on some expressions associated with a Permission. An expression for use case 1, mentioned above, may look like this, 'userId=user.userId'
where 'user' is a keyword and represents current authenticated user and 'userId' is a property of the object for which criteria is created.
We want to define a dsl using which we can derive criteria restriction as well as 'where' clause for sql.
Are there any existing frameworks which will enable us to do it, without going for dsl? Based on the use cases mentioned above, do you think it can be achieved in different way?
Additional Info: We define only domain objects with some meta information to generate UI. Persistence, security etc are taken care by our core framework.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您测试过 Hibernate 过滤器吗?
它们是记录级别过滤的绝佳机制,您可以在每个实体上定义多个过滤器(例如针对您的案例的两个过滤器),并根据当前用户启用或禁用它们。
应提及过滤器可以接受参数(例如您当前的用户 ID)。
我们在一个大型项目中使用了 Hibernate 3 的这一出色功能,该项目具有分层组织单元并且运行良好。
顺便说一句,如果您使用 Oracle 作为数据库,请考虑 Oracle 的虚拟专用数据库功能。
Have you tested Hibernate filters?
They are great mechanism for record level filtering, you can define multiple filters (for example two filters for your case) on each entity and enable or disable them according to current user.
Shall mention that filters can accept parameters (for example your current user id).
We have used this great feature of Hibernate 3 on a large project, which had a hierarchical organization unit and that worked fine.
By the way if you use Oracle as your database, consider Oracle's virtual private database feature.
我们决定使用 Antlr 来使用我们自己的 DSL
We decided to go with our own dsl using antlr