【发布时间】:2012-02-15 07:39:03
【问题描述】:
我有一个使用@Secured 注释的存储库方法。我正在尝试为此方法编写单元测试,但我的测试失败,因为我需要身份验证才能调用该方法。该方法本身恰好是 save() 方法。我调用该方法时得到的错误是:
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
我无法测试此方法,因为它需要身份验证,并且我无法保存用户进行身份验证(我正在使用 hsqldb),因为我需要调用此方法来保存。关于如何对使用 @secured 注释的方法进行单元测试或如何模拟身份验证的任何建议。
【问题讨论】: