【发布时间】:2014-08-21 23:36:26
【问题描述】:
我在一个项目中使用 JPA 和 Maven。编写执行此操作的代码是可能的,但在语义上是错误的:
entityManager.find(EntityWithRestrictedData.class, key);
或
entityManager.findAll(EntityWithRestrictedData.class);
该项目已经有应该使用的代码:
getEntityWithRestrictedDataONLYIfYouHaveAccess(key, user);
如果有人使用实体管理器直接查找受限数据,有什么方法会导致构建失败?
请记住,在我的项目中,使用find 和findAll 有其他完全正当的理由,只是不使用EntityWithRestrictedData。
编辑:这个问题可能与此重复,How to make a maven build fail if source code contains a keyword / regex
【问题讨论】:
-
将 EntityWithRestrictedData 放入受保护的包中,使其构造函数受到保护并将其包装在 Builder 或 Factory 周围。
-
@AlexandreSantos 我感觉 JPA 会适应这种情况
-
我不确定是否通过 Maven,但您可能需要自定义 FindBugs 或 Sonar 规则。
-
我什至不确定您将如何定义禁止调用的外观。这是 AOP 通常更可取的事情,和/或您不应该直接在安全边界之外的代码中使用
EntityManager。