permissionEvaluator

时间:2017-05-11 21:15:13

标签: spring-boot spring-security spring-data spring-data-rest spring-el

我有一个来自Spring Data this example的CRUD存储库。我尝试添加自定义权限评估,但在PermissionEvalutor的实施中,targetDomainObject始终为null

ItemRepository

@PreAuthorize("hasRole('ROLE_USER')")
public interface ItemRepository extends CrudRepository<Item, Long> {
  @PreAuthorize("hasPermission(#entity, 'DELETE')")
  <S extends Item> S save(S entity);

  @PreAuthorize("hasRole('ROLE_ADMIN')")
  void delete(Long id);
}

根据this question的答案中的建议,使界面和实施参数名称匹配,我已尝试在表达式和entity中更改item方法参数。我不确定哪个实现应与此处的界面匹配,因此我猜测SimpleJpaRepositoryItemRepository / CrudRepositorytargetDomainObject。无论如何,它不起作用,targetId始终为空。对于另一种方法中的MethodSecurityEvaluationContext.lookupVariable也是如此。

调试args.length = 0会在方法addArgumentsAsVariables()中显示Unable to resolve method parameter names for method: public abstract xx.xxx.Item xx.xxx.ItemRepository.save(xx.xxx.Item). Debug symbol information is required if you are using parameter names in expressions.,然后会记录lookupVariable。在#,一切都为空。

调试符号不是<img width=40' src='{1}' alt='dot' />吗?我做错了什么?

1 个答案:

答案 0 :(得分:1)

没有看过实际的代码,但是根据你写的关于调试信息的内容判断,Spring无法找到参数名称,可能因为来自接口而且那些不包含在字节码中默认值。

尝试添加-parameters编译器标志。另请参阅此答案以了解可能类似的问题:https://stackoverflow.com/a/40787280