【发布时间】:2012-04-07 16:05:26
【问题描述】:
考虑这段代码:
import java.util.Collections;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.userdetails.User;
public class SecureStuff {
@PreAuthorize("#user.password == #oldPassword")
public static void changePassword(User user, String oldPassword, String newPassword){
System.out.print("Changing passwords ...");
}
public static void main(String[] args) {
User joe = new User("Joe", "HansWurst", true, true, true, true, Collections.EMPTY_LIST);
changePassword(joe, "HansWurst", "TeeWurst");
}
}
我在 STS(SpringSource 工具套件)中运行了代码,它按预期工作。 (它打印了"Changing passwords ..."。)
然后我将密码重命名为其他内容,希望方法调用现在失败。
我已经将<global-method-security pre-post-annotations="enabled"/> 行添加到我的applicationContext-security.xml 配置文件中。
我在这里错过了什么?
【问题讨论】:
标签: java annotations spring-security authorization