配置
适用于 ❌ 开源版 ✅ Express 版 ✅ 专业版 ✅ 企业版
org.jooq.Policy 是一个配置,包含:
-
Policy.table():它应用到的表 -
Policy.condition():应用于使用该表的查询的条件 -
Policy.inherited():父表的策略是否被子表继承
策略通过通常的 SPI 配置点 Configuration 提供给 jOOQ。与所有 jOOQ SPI 一样,这意味着可以并行存在多个 Configurations,具体取决于您的数据库交互用例。例如
- 超级用户可能能够访问所有数据
- 员工用户可能只能访问 1-2 个租户
- 客户用户可能只能访问他们自己的客户数据
在这种设置中,您将已经拥有具有不同权限的不同数据库用户(另请参见 安全注意事项),因此您可以将一组策略附加到每个数据库用户。
创建策略的一种方法是使用 org.jooq.impl.DefaultPolicyProvider
Configuration configuration = ...;
configuration.set(new DefaultPolicyProvider()
// Append a Policy to the PolicyProvider
.append(
// The table on which to apply a policy
TENANT,
// The condition to apply to queries against the table
TENANT.TENANT_ID.eq(42))
// Append another Policy to the PolicyProvider
.append(CUSTOMER, CUSTOMER.CUSTOMER_ID.eq(40183))
);
反馈
您对此页面有任何反馈吗? 我们很乐意听到!