目前我试图找出Spring Security如何评估给定的URL,表达式和注释。到目前为止,它似乎总是首先检查来自security-context.xml
的条目。如果这是一个denyAll
它只会停止进一步处理请求。使用注释和全局拒绝Spring安全白名单的方法全部
也许我忘了设置一些配置选项,但在我的眼中,使用Spring Security的注释(如@Secured
,@PermitAll
等)无法构建漂亮的白名单。
我想要的基本上是注释@Controller
内的方法允许访问。例如:
@Controller
@RequestMapping("/test")
public MyController {
@RequestMapping("")
public void tryToGetSomething() {
// no security annotation -> denyAll
}
@RequestMapping("/public")
@PermitAll
public void tryToGetSomethingPublic() {
// this will always have access allowed
}
@RequestMapping("/admin")
@Secured({"ROLE_ADMIN"})
public void tryToGetSomethingReallyImportant() {
// this can only be accessed by admins
}
}
此方法的主要原因是:安全;-)
。编写代码时总是可以忘记一些注释。用这种方法这样的错误不会影响敏感数据的安全。
所以我的问题是:我该如何做到这一点?
看起来很有趣,我会检查一下。但首先我必须弄清楚,如何在Spring Security javaconfig中使用切入点。我会稍后再报告。 –
每一个都会变得这样吗? –
@BenjaminM:凹凸! – yjo