我阅读了这篇 stackoverflow 帖子 What's the difference between @Secured and @PreAuthorize in spring security 3? 但是,我仍然不清楚两者在安全性方面的最大区别是什么?与@Secured相比,在什么情况下我们应该使用@PreAuthorize?
最佳答案
@PreAuthorize
允许您对规则进行更细粒度的控制以确保 o 方法。您可以在其中使用 SpEL 表达式。
使用@Secured
保护方法给你的结果与@PreAuthorize
相同,但是@Secured
是有限的,你不会得到尽可能多的选项来调整规则(一个粗略的简化是规则是“静态的”)。
Spring Security 3.0 introduced the ability to use Spring EL expressions as an authorization mechanism in addition to the simple use of configuration attributes and access-decision voters which have seen before. Expression-based access control is built on the same architecture but allows complicated boolean logic to be encapsulated in a single expression.
关于java - 我们什么时候应该使用@PreAuthorize 和@Secured,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28648576/