全局方法安全性对某些bean有效,但对其他使用spring安全性的bean无效

全局方法安全性对某些bean有效,但对其他使用spring安全性的bean无效,spring,annotations,spring-security,Spring,Annotations,Spring Security,我有一个服务 <bean id="myservicie" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"> <property name="service" ref="aService"/> <property name="serviceInterface" value="com.statestr.oms.fx

我有一个服务

   <bean id="myservicie" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
            <property name="service" ref="aService"/>
            <property name="serviceInterface" value="com.statestr.oms.fx.ws.service.IService"/>
   </bean>  
但它不起作用

但是,如果我将这个方法移动到另一个bean,比如说mybean,那么安全注释就可以工作了

我已经在下面的配置中启用了这两个选项,有人能帮忙吗?thx

   <global-method-security   secured-annotations="enabled" access-decision-manager-ref="accessDecisionManager">
        <protect-pointcut expression="execution(* *..com.statestr.oms.service.impl.*Mybean*.*(..))" access="ROLE_USER"/>
        <protect-pointcut expression="execution(* *..com.statestr.oms.service.impl.*Service*.*(..))" access="ROLE_USER"/>
   </global-method-security>

我想这是因为您的应用程序使用Spring代理AOP。如果直接(从同一个bean)调用该方法,则此AOP样式没有影响。我认为这就是你要做的,因为你提到的方法是私有方法

因此,您可以做的是:

  • 使用AspectJ(我强烈推荐)
  • 将@Secured注释放到从bean外部调用的方法中

无论如何,您的配置看起来有点奇怪-为什么要使用
@Secured

   <global-method-security   secured-annotations="enabled" access-decision-manager-ref="accessDecisionManager">
        <protect-pointcut expression="execution(* *..com.statestr.oms.service.impl.*Mybean*.*(..))" access="ROLE_USER"/>
        <protect-pointcut expression="execution(* *..com.statestr.oms.service.impl.*Service*.*(..))" access="ROLE_USER"/>
   </global-method-security>