1

@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>
4

1 回答 1

2

如果 list1 方法与 listJson 位于同一类/实例上,则不会调用安全建议,因为您正在处理类中的方法。

但是,如果您要将 list1 方法移动到注入的服务类,您将拥有一个遵循注释的建议对象。

编辑我想让这一点更清楚 - 所以我包括一个图表,希望能更清楚地解释这一点

/mapping -> Project.listJson(HttpServletRequest, HttpServletResponse) |
                                                                      |
                                                                      |
                                                                      |
                                                            ---------------------
                                                            | listJson          |
                                                            |                   |---------|
                                                            |                   |         |
                                                            |                   |         | list1
                                                            |                   |         |
                                                            |                   |         |
                                                            |                   |         |
                                                            |                   |         |
                                                            |  list1            |<--------|
                                                            |                   |
                                                            |                   |
                                                            ---------------------

/mapping -> Project.listJson(HttpServletRequest, HttpServletResponse) |
                                                                      |
                                                                      |
                                                                      |
                                                            ---------------------
                                                            | listJson          |<--------------------------------|
                                                            | svc.list1         |--------->advised(Service)       | run @PostFilter
                                                            |                   |         |                       |
                                                            |                   |         | list1                 |
                                                            ---------------------         |                       |
                                                                                          |                       |
                                                            ---------------------         |                       |
                                                            | Service           |         |                       |
                                                            | list1             |<--------|                       |
                                                            |                   |                                 |
                                                            |                   |---------------------------------|
                                                            ---------------------
于 2013-02-19T11:48:48.720 回答