java - 我们什么时候应该使用@PreAuthorize 和@Secured

标签 java spring spring-security annotations spring-annotations

我阅读了这篇 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/

相关文章:

Spring Boot : Securing api endpoint with oauth2 while having mvc UI pages

java - Java中字符串加密的常量结果

java - OSGI Blueprint jaxrs 服务器端点配置 - 如何配置地址?

Spring Boot 在 SpringApplication.run 之前检查属性

java - Spring 安全: make a mysql authentication

java - Spring安全+LDAP。无法调试

java - 如何扫描图像文件夹并将其添加到图像数组

java - 使用 JLabel 和插入其中的图像设置背景

Spring JPA CrudRepository save(Entity) 在 id 字段中返回 0

spring - Intellij IDEA 是否支持@RooJpaRepository?