spring框架安全性@preauthorize注释在osgi中不起作用

时间:2012-08-28 11:33:51

标签: spring-security osgi eclipse-virgo

我正在使用osgi和基于spring annotations的配置。 (使用处女座来部署应用程序)
对方法impl的@preauthorize注释不起作用。
尽管没有这个角色,它允许用户访问它。

如果我在接口上添加相同的注释,它会为所有用户抛出AccessDenied异常。 例外:

org.springframework.security.access.AccessDeniedException: Access is denied 
 252881 [http-bio-8080-exec-3] ERROR c.w.HomeController  - handleAccessDeniedException####Access is denied 
    at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:71) 
    at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:203
    at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:64) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
    at $Proxy421.save(Unknown Source) 
    at c.w.controllers.HomeController.home(HomeController.java:125) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) 
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapte
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414) 

这是我的配置:

  <bean id="expressionHandler"
      class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
        <property name="permissionEvaluator" ref="aclPermissionEvaluator"/>
  </bean>
  <global-method-security pre-post-annotations="enabled" run-as-manager-ref="runAsManager"
    secured-annotations="enabled">
    <expression-handler ref="expressionHandler" />
  </global-method-security> 

我正在使用spring-security 3.0.4.RELEASE

1 个答案:

答案 0 :(得分:1)

我在一个包中使用了@Preauthorize注释,并在另一个包中定义了global-method-security 将其移至同一捆绑后,问题得到解决。