【发布时间】:2019-11-17 09:45:56
【问题描述】:
伙计们,我有一个自定义注释,旨在在 Spring 引导集成测试中模拟用户,这些测试由 Spring 安全保护。
/**
* Mock user for MVC authentication tests
*/
@Retention(RetentionPolicy.RUNTIME)
@WithSecurityContext(factory = WithMockMyAppUserSecurityContextFactory.class, setupBefore = TestExecutionEvent.TEST_METHOD)
public @interface WithMockMyAppUser {
long tokenExpMillis() default 36000L ;
String[] roles() default {"NONE"};
}
这是它的用法:
@WithMockMyAppUser(roles={"ADMIN"})
class AddressServiceTest {
...
}
我的问题是,是否有可能以某种方式使用 Spring 属性 @Value 来提供角色,而不仅仅是在这里硬编码 "ADMIN" 字符串 @WithMockMyAppUser(roles={"ADMIN"}) ?
【问题讨论】:
标签: java spring-boot spring-security spring-test