作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我发现了很多类似的问题,但都没有解决我的问题我的问题是:PreAuthorize("isAuthenticated()") 在我的 RestController 上不起作用。
我的配置安全性是:
<global-method-security pre-post-annotations="enabled"/>
<authentication-manager alias="authenticationManager">
<authentication-provider>
<password-encoder ref="passwordEncoder" />
<jdbc-user-service
data-source-ref="dataSource"
users-by-username-query="
select login,password,1
from test tst where tst.login=?"
authorities-by-username-query="
select login,'ROLE_SAVE' from test tst where tst.login=?"
/>
</authentication-provider>
</authentication-manager>
在我的 RestController 上我添加了这个注解:@PreAuthorize("isAuthenticated()")
@RestController
@PreAuthorize("isAuthenticated()")
@RequestMapping("/api/test")
public class PrinterController{
@RequestMapping(value = "", method = RequestMethod.GET)
public ResponseStatus test() {
System.out.println("test");
}
但不工作任何用户都可以使用此资源。
最佳答案
您需要将以下注释添加到您的安全配置类:
@EnableGlobalMethodSecurity(prePostEnabled = true)
感谢这篇文章:
https://nixmash.com/post/spring-mvc-method-security-with-preauthorize-and-sp-el
关于java - PreAuthorize ("isAuthenticated()") 不适用于 RestController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44543236/
我是一名优秀的程序员,十分优秀!