Spring:@PreAuthorize 是否优先于 @Cacheable?

标签 spring spring-mvc spring-security spring-cache

我有一个关于 Spring Security 和 Spring Caching 的问题。假设我有一个方法,并且我已经用 @PreAuthorize("condition") 和 @Cacheable(...) 注释了该方法,就像这样

@PreAuthorize("some authorization check")
@Cacheable(....)
public String calculate() {
  ....
}

@PreAuthorize ( http://docs.spring.io/spring-security/site/docs/3.0.x/reference/ns-config.html ) 是否优先于 @Cacheable ( http://docs.spring.io/spring/docs/3.1.0.M1/spring-framework-reference/html/cache.html )?即使已经计算并缓存了calculate() 函数的结果,框架是否保证将评估@PreAuthorize 安全检查?请记住,这个函数可以被用户 A 调用,然后是存储在缓存中的值,然后另一个用户(用户 B)执行需要再次调用此函数的操作?是否会评估 @PreAuthorize 条件?

从我在 Spring Documenation 中可以找到的内容来看,@PreAuthorize 和 @Cacheable 的建议顺序都定义为“Ordered.LOWEST_PRECEDENCE”,我相信这意味着它们的评估顺序是未定义的?

谢谢!

最佳答案

两者<security:global-method-security><cache:annotation-driven>启用 @PreAuthorize 的标签和 @Cacheable注释,有一个 order决定其 AOP 建议的执行优先级的属性。

如果你想确保安全检查总是在缓存检查“进入”之前发生,那么你应该通过设置 order 给它更高的优先级。归因于较低的值。

<security:global-method-security order="1">

关于Spring:@PreAuthorize 是否优先于 @Cacheable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21462213/

相关文章:

java - 将对象从下拉列表 (.jsp) 传递到 Controller

java - Xpath Xquery : unable to add <DOCTYPE! > 在 xml 中,而它存在于源 xml 文件中

java - 使用配置类时将@PreAuthorize 或@Secured 与 Jersey 一起使用

java - Spring Security 元注释

java - 为什么 AngularJS 应用程序不能在不同的服务器上使用 REST 服务?

java - Spring HttpMessageConverter 根据@ExceptionHandler响应内容类型

java - spring amqp 中的非分批消息

java - Max session 1 不适用于 spring boot

java - 为什么 Java SimpleDateFormat 在某些服务器上工作而在其他服务器上工作?

mysql - Spring Bcrypt 是无状态的,不需要安全随机数?