gpt4 book ai didi

spring-security - preAuthorize 注释似乎不起作用

转载 作者:行者123 更新时间:2023-12-02 05:23:24 26 4
gpt4 key购买 nike

我们正在尝试使用 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" />

这是方法本身:

@PreAuthorize("(hasRole('ROLE_ADMIN'))")
public Some doIt(Some Input) {
do something;
return some;
}

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

最佳答案

事实证明,您不能对从同一类中访问的方法进行注释,无论是私有(private)的还是公共(public)的。注释仅适用于外部人员访问的公共(public)方法。

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

关于spring-security - preAuthorize 注释似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9994467/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com