preAuthorize注释似乎不起作用

Mud*_*sir 2 spring-security spring-aop

我们正在尝试使用Spring的@preAuthorize标记来提高方法级别的安全性.一切都编译好并且运行良好,但限制不会发生.这是一种仅限管理员的方法,但即使是非管理员也可以访问.以下是我们在上下文中配置它的方式:

<http use-expressions="true" create-session="never"  entry-point-ref="oauthAuthenticationEntryPoint" xmlns="http://www.springframework.org/schema/security" authentication-manager-ref="authManager">
    <intercept-url pattern="/mocks/some-service" access="hasRole('ROLE_OTHER')" />
    <form-login authentication-failure-url="/login.jsp" default-target-url="/login.jsp" login-page="/login.jsp"></form-login>
    <custom-filter ref="resourceServerFilter" after="EXCEPTION_TRANSLATION_FILTER" />

  </http>

<security:global-method-security pre-post-annotations="enabled" />
Run Code Online (Sandbox Code Playgroud)

以下是方法本身:

@PreAuthorize("(hasRole('ROLE_ADMIN'))")
public Some doIt(Some Input) {
            do something;
    return some;
}
Run Code Online (Sandbox Code Playgroud)

但每个人都可以拥有一些东西.我错过了什么?任何帮助将不胜感激.

Mud*_*sir 16

事实证明,您无法对同一类中访问的方法进行注释,无论是私有还是公共.注释仅适用于外人访问的公共方法.

希望能帮助某人犯同样的错误.


Dan*_*ani 6

请看一下:http://static.springsource.org/spring-security/site/faq/faq.html#faq-method-security-in-web-context

总结一下:

"您需要将声明移动到Web上下文或将您想要保护的bean移动到主应用程序上下文中."