@WithMockUser kullanamıyorum, ne yaparsam yapay testte yetkili kullanıcı sağlamaz. Belki onun nedeniyle kaynak sunucu ama ..WIthMockUser işe yaramıyor
Yapılandırma:
@Configuration
@EnableResourceServer
class ResourceServerConfig extends ResourceServerConfigurerAdapter
...
@Override
public void configure(HttpSecurity http) throws Exception {
http
.anonymous().and().authorizeRequests().antMatchers("/**").hasRole("USER");
}
...
}
Ve Test sınıfı
@BeforeClass
public void setup(){
mockMvc = MockMvcBuilders
.webAppContextSetup(wac)
.apply(springSecurity())
.build();
}
@Test
@WithMockUser()
public void shouldAddValueToStore() throws Exception {
ResultActions response = mockMvc.perform(post("/bucket/key")
.content("value"));
...
}
ben 401 Access is denied (user is anonymous); redirecting to authentication entry point
almaya devam. Ben, mockMvc için with(user..)
geçen ek açıklama parametrelerinde, kullanıcı adları ayarlama ile çalıştı, hiçbir şey yardımcı olur. Onun bahar güvenliği 4.0.4.RELEASE.
@WithMockUser (kullanıcı adı = "ram", yetkiler = {"ROLE_XX", "ROLE_AA"}) veya kullanıcı adı ihmal edilebilir – Tiina