Spring security Spring安全性/AspectJ切入点
是否可以使用切入点保护我的@Controller类?我试过:Spring security Spring安全性/AspectJ切入点,spring-security,aspectj,Spring Security,Aspectj,是否可以使用切入点保护我的@Controller类?我试过: <global-method-security pre-post-annotations="enabled"> <!-- Block anything ending with the word 'Controller'--> <protect-pointcut expression="execution(* my.pkg.*Controller.*(..))" access="NON_EX
<global-method-security pre-post-annotations="enabled">
<!-- Block anything ending with the word 'Controller'-->
<protect-pointcut expression="execution(* my.pkg.*Controller.*(..))" access="NON_EXISTANT_ROLE"/>
</global-method-security>
理论上,我永远不能点击控制器,因为这个角色对于任何用户都不存在。但是,控制器运行正常。请参阅(我的重点)
在SpringWeb应用程序中,保存
DispatcherServlet的SpringMVCbean通常与
主应用程序上下文。它通常在一个名为
myapp-servlet.xml,其中“myapp”是分配给Spring的名称
web.xml中的DispatcherServlet。一个应用程序可以有多个
DispatcherServlets,每个都有自己的独立应用程序上下文。
这些“子”上下文中的bean对其余部分不可见
应用“父”应用程序上下文由
您在web.xml中定义的ContextLoaderListener对所有人都可见
孩子们在不同的环境中成长。此父上下文通常是您定义的位置
您的安全配置,包括
元素)。因此,应用于中的方法的任何安全约束
由于无法看到这些bean,因此不会强制执行这些Webbean
从DispatcherServlet上下文。您需要移动
声明到web上下文或移动
您希望在主应用程序上下文中保护的bean
通常,我们建议在服务中应用方法安全性
层而不是单个web控制器上。
如果将切入点应用于服务层,则只需在应用程序的安全上下文中设置
。您使用的是哪个版本的spring security?我在3.0.5之前就遇到过这个问题。还要确保控制器上下文中存在全局方法安全性。