【问题标题】:Spring Data JPA with Security EvaluationContextExtensionSupport not working具有 Security EvaluationContextExtensionSupport 的 Spring Data JPA 不起作用
【发布时间】:2015-07-30 17:37:34
【问题描述】:

我想使用 Spring Data JPA 的安全扩展支持来检查用户的权限并相应地获取一些值。我正在尝试按照here

的指示执行此操作

下面是我的代码sn-p

    @RepositoryRestResource(collectionResourceRel = "ProductStatus", path = "ProductStatus")
    public interface IProductStatusRepository extends CrudRepository<ProductStatusEntity, String> {
        @Query("SELECT p FROM ProductStatusEntity " +
                "?#{hasAuthority('ITManager') ? ' ' : ' WHERE ProductStatusCode NOT IN (\'VAL1\',\'VAL2\',\'VAL3\')'}")
        List<ProductStatusEntity> findStatusesByAuthority();
    }

我确实只通过复制粘贴代码来声明 SecurityEvaluationContextExtension 类和 securityExtension bean。但是,上面的代码仍然不起作用。

我总是得到一个

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ? 

我尝试了几个选项来玩弄 ?#、:#、hasRole、hasAuthority 等。似乎没有任何效果。

对此有什么想法吗?

【问题讨论】:

    标签: spring-security spring-data spring-data-jpa spring-el


    【解决方案1】:

    这个在经过多次试验和错误后奏效了

    @Query("select p from ProductStatusEntity p where p.productStatusCode NOT IN ( ?#{hasAuthority('ITManager') ? ' ' : @settings.productStatusExceptions})")
    List<ProductStatusEntity> findStatusesByAuthority();
    

    问题似乎是 SpEL 只有在指定了 WHERE 子句时才会被识别..可能这可以改进..不确定..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-20
      • 2017-06-09
      • 1970-01-01
      • 2017-09-21
      • 1970-01-01
      • 2014-07-02
      • 1970-01-01
      • 2021-12-19
      相关资源
      最近更新 更多