Spring security Spring数据JPA repo中的辅助保存方法?

Spring security Spring数据JPA repo中的辅助保存方法?,spring-security,spring-data-jpa,spring-data-rest,Spring Security,Spring Data Jpa,Spring Data Rest,我有一个通过SpringDataREST导出的SpringDataJPA回购,并使用SpringSecurity进行保护。我还需要将数据从不安全的端点保存到此表,但我的save()方法是安全的 我无法创建第二个存储库,因为 我知道的唯一方法是每次调用securedsave()方法之前手动操作安全上下文 有更好的方法吗?如果您只保护了保存方法,您可以尝试使用不安全的方法 另一种方法-。首先-实施定制回购,例如: 公共接口CustomRepo{ MyEntity(MyEntity实体); } @存储

我有一个通过SpringDataREST导出的SpringDataJPA回购,并使用SpringSecurity进行保护。我还需要将数据从不安全的端点保存到此表,但我的
save()
方法是安全的

我无法创建第二个存储库,因为

我知道的唯一方法是每次调用secured
save()
方法之前手动操作安全上下文


有更好的方法吗?

如果您只保护了
保存方法,您可以尝试使用不安全的方法

另一种方法-。首先-实施定制回购,例如:

公共接口CustomRepo{
MyEntity(MyEntity实体);
}
@存储库
公共类CustomRepoImpl实现CustomRepo{
私人最终实体经理em;
公共CustomRepoImpl(实体管理器em){
this.em=em;
}
@交易的
@凌驾
公共MyEntity(MyEntity实体){
if(entity.getId()==null){
em.persist(实体);
返回实体;
}否则{
返回em.merge(实体);
}
}
}
然后从自定义回购扩展您的回购:

公共接口MyEntityRepo扩展了JpaRepository、CustomRepo{
//...
}