【问题标题】:Spring Security 3: @PostFilter not workingSpring Security 3:@PostFilter 不起作用
【发布时间】:2011-03-21 22:41:10
【问题描述】:

嗨 我是 Spring Security 3 的新手,正在尝试在接口中声明的方法上使用 @PostFilter,但返回的 Collection 没有被过滤。

代码如下:

public interface IProductService {

 @PostFilter("(!filterObject.customersOnly) or (filterObject.customersOnly and hasRole('ROLE_USER'))")
 Collection<Category> getCategories();
}

customerOnly 是域对象类别中的布尔属性。

我在 xyz-security.xml 中添加了以下元素:

<global-method-security pre-post-annotations="enabled" />

有人可以帮助我了解我缺少什么吗?

谢谢

【问题讨论】:

  • 不知何故未检测到@PostFilter,有人可以帮我理解它可能发生的原因吗?它是 Peter Mularien 所著的 Spring Security 3 一书的示例代码。谢谢

标签: spring-security


【解决方案1】:

造成这种情况的典型原因是:

  1. AspectJ 和/或 CGLIB JAR 不在您的类路径中。
  2. 您在接口或类上有注释(查看Spring AOP docs 以确定哪个AOP 实现支持哪个)。
  3. 您已将 Spring Security 配置添加到与声明受保护 bean 的位置不同的 ApplicationContext(例如,当您声明 Spring Security 配置时,您试图保护 *-servlet.xml 文件中的 bean ContextLoaderListener)。
  4. 您已删除或更改了声明,因此带注释的 bean 不会由配置 Spring Security 的同一 ApplicationContext 处理。

如果这些建议都不适用,请启用 DEBUG 日志记录并观察应用程序启动以查看是否处理了 bean 注释。

顺便说一句,我有很多读者报告了类似的问题 - 此示例的源代码确实有效,但在所有情况下,读者随后都更改了上述 4 项中的一项,导致“中断”的示例代码;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-10
    • 2011-10-05
    • 2015-04-23
    • 1970-01-01
    • 2022-12-15
    • 2017-02-13
    • 2012-01-02
    相关资源
    最近更新 更多