English 中文(简体)
春季前/后方法安全说明无效
原标题:Spring Pre/Post method security annotations not working

我似乎无法让春季前/后方法安全说明起作用。我读过关于这个议题的每一个相关的堆积流问题,主要的建议是确保全球方法安全与您想要获得的豆类一样。 我的调度员-服务器.xml有以下信息:

  <context:component-scan base-package="com.package.path" />
  <context:annotation-config />
  <security:global-method-security pre-post-annotations="enabled" />

有关豆类在“com.package.path”中, 我知道春天正正确地创造出它们的例子, 因为注射效果很好,

下面是“com. package. path”中的一个服务类示例:

@Controller
@RequestMapping("/article")
public class ArticleServiceImpl extends GWTController implements ArticleService {
    @Autowired
    public ArticleServiceImpl(DataSource ds) {

    }

    @Override
    @PreAuthorize("hasRole( ROLE_BASIC_USER )")
    public Article save(Article article) {

    }

}

保存方法的说明无效。

  • I m using GWT, though from what I ve read, that shouldn t matter much.
  • I have method security working perfectly well in another, similar project. The only difference is that there is a DAO layer in the other project, which is not present in this one. It s in this layer that I have annotation security working. However, it shouldn t matter what "layer" this is, as long as Spring is responsible for creation of the beans, right?
  • The interface "ArticleService" above is a GWT service interface. I ve tried putting the annotation there, but that doesn t work either.

以下是我GWT总经理的班级,如果需要的话,请参考上面提到的班级:

package com.areahomeschoolers.baconbits.server.spring;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.ServletConfigAware;
import org.springframework.web.context.ServletContextAware;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.areahomeschoolers.baconbits.server.util.ServerContext;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * Spring controller class that handles all requests and passes them on to GWT. Also initializes server context.
 */
public class GWTController extends RemoteServiceServlet implements ServletConfigAware, ServletContextAware, Controller, RemoteService {

    private static final long serialVersionUID = 1L;

    protected ServletContext servletContext;

    @Override
    public ServletContext getServletContext() {
        return servletContext;
    }

    // Call GWT s RemoteService doPost() method and return null.
    @Override
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // load our ServerContext with current request, response, session, user, appContext, etc.
        ServerContext.loadContext(request, response, servletContext);
        try {
            doPost(request, response);
        } finally {
            ServerContext.unloadContext();
        }
        return null; // response handled by GWT RPC over XmlHttpRequest
    }

    @Override
    public void setServletConfig(ServletConfig conf) {
        try {
            super.init(conf);
        } catch (ServletException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }

    @Override
    protected void checkPermutationStrongName() throws SecurityException {
        return;
    }

    @Override
    protected void doUnexpectedFailure(Throwable e) {
        e.printStackTrace();
        super.doUnexpectedFailure(e);
    }

}
最佳回答

由 Spring Security 提供的安保方面继承了 Spring Framew Framew 代理支持 AOP 的所有限制。 特别是, 某些方面不适用于“ 内部” 对象的调用( 除非您使用 AspectJ 编织), 见 < a href=" http://static. springsource.org/spring/docs/3. 0. x/spring- framework- reference/html/ aop. html #aop- adop- underide- aop- proxies" rel="nofol" >7. 6.1 理解 AOP 代理 。

因此,如果你想以这种方式使用安全方面,你就需要使用GWT整合机制,从外部呼唤你提供服务,即不需要你的服务来扩展 remoteService Servicelet 的机制。

例如"http://code.google.com/p/spring4gwt/wiki/SupreRPCExample" rel = "no follow" >spring4gwt 等。

问题回答

暂无回答




相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签