@Postfilter 没有被触发。
我的控制器中有两种方法。listJson 方法调用 list1 方法获取所有项目并以 json 格式返回。我在 list1 方法上有一个 @Postfilter 来过滤项目,并且没有触发过滤器。
问题不在于配置。由于出于测试目的,我尝试将 @Postfilter 放在 listJson 方法上,它确实触发了。你能帮我解决这件事吗?我会很感激。
@RequestMapping(produces = "application/json")
@ResponseBody
public String listJson(HttpServletRequest request, HttpServletResponse response) {
List<Project> items = list1(request, response, Project.class);
return JsonHelper.toJsonArray(items, request.getContextPath());
}
@PostFilter("hasPermission(filterObject, 'read')")
private List<Project> list1(HttpServletRequest request, HttpServletResponse response, Class<Project> clazz) {
Integer[] ia = WebHelper.getDojoGridPaginationInfo(request);
Integer firstResult = ia[0];
Integer lastResult = ia[1];
Entry<String, String> orderBy = WebHelper.getDojoJsonRestStoreOrderBy(request.getP arameterNames());
Where where = WebHelper.FromJsonToFilterClass(request.getParamet er("filter"));
List<Project> items = JpaHelper.findEntries(firstResult, lastResult - firstResult + 1, orderBy, where, clazz);
Integer totalCount = JpaHelper.countEntries(where, clazz).intValue();
WebHelper.setDojoGridPaginationInfo(firstResult, lastResult, totalCount, response);
return items;
}
webmvc-config.xml
<security:global-method-security pre-post-annotations="enabled" proxy-target-class="true">
<security:expression-handler ref="expressionHandler"/>
</security:global-method-security>
<bean id="myPermissionEvaluator" class="org.springframework.security.acls.AclPermis sionEvaluator">
<constructor-arg ref="aclService" />
</bean>
<bean id="expressionHandler" class="org.springframework.security.access.express ion.method.DefaultMethodSecurityExpressionHandler" >
<property name="permissionEvaluator" ref="myPermissionEvaluator"/>
</bean>