开发者

Spring Security 3: @PostFilter not working

Hi I am new to Spring Security 3 and was trying out @PostFilter on a method declared in an Interface but the returned Collection is not getting filtered.

Here is the code:

public interface IProductService {

 @PostFilter("(!filterObject.customersOnly) 开发者_Python百科or (filterObject.customersOnly and hasRole('ROLE_USER'))")
 Collection<Category> getCategories();
}

customerOnly is a boolean attribute in a domain object Category.

I've added the following element on xyz-security.xml:

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

Could someone help me understand what am i missing?

Thanks


The typical causes for this are:

  1. AspectJ and/or CGLIB JARs are not in your classpath.
  2. You have the annotation on an interface OR on a class (review the Spring AOP docs to determine which is supported for which AOP implementation).
  3. You have added the Spring Security configuration to a different ApplicationContext than where you have declared your secured beans (for example, you are trying to secure a bean in your *-servlet.xml file, when your Spring Security configuration is declared by the ContextLoaderListener).
  4. You have removed or altered the declaration so that the annotated bean is not processed by the same ApplicationContext where Spring Security is configured.

If none of these suggestions applies, please enable DEBUG logging and watch application startup to see if the bean annotation is processed at all.

As an aside, I have had many readers report similar flavors of this problem - the source code for this sample does work, but in all cases it has been true that readers have subsequently changed one of the above 4 items, causing the sample code to "break" ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜