我想只允许特定用户访问他们的修改页面。Spring Web Security中的自定义方法
例如,我想用户3是唯一一个能够访问的URL:/用户/ 3 /编辑
对于这一点,我已经把我的SecurityConfiguration.java:
.authorizeRequests()
.antMatchers("/user/{id}/edit").access("@MyClass.checkId(#id)");
MyClass.java如下:
@Component
public class MyClass{
public boolean checkId(Long id) {
if(id == SecurityUtils.getCurrentUserId()){ //I have this configured and working
return true;
}
return false;
}
}
然而,当去到以下网址:用户/ 4 /编辑登录的用户3(这些例子),我似乎无法进入checkId方法,并没有什么发生了,我的页面加载其中的所有内容。
你有什么想法吗? antMatchers.access()是否要走?
谢谢你的时间!
谢谢你的回答,虽然这似乎是一个副本 - 这个答案的口吻:https://stackoverflow.com/a/6634438/5749754,一字不换,甚至没有提到它!不过谢谢你,至少我找到了我想找的东西...... –