2016-03-24 9 views
0

@WithMockUserを使用することはできません。私が何をしても、春のテストでは許可されたユーザーに提供しません。たぶんその理由はそのリソースサーバけど...WIthMockUser doesnt work

設定:

@Configuration 
@EnableResourceServer 
class ResourceServerConfig extends ResourceServerConfigurerAdapter 
... 
    @Override 
    public void configure(HttpSecurity http) throws Exception { 
    http 
      .anonymous().and().authorizeRequests().antMatchers("/**").hasRole("USER"); 
} 
... 
} 

とテストクラス

@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")); 
... 
} 

私は401 Access is denied (user is anonymous); redirecting to authentication entry pointを得続けます。私は、ユーザー名、アノテーションパラメータのロールを設定して、with(user..)をmockMvcに渡してみましたが、何も役立たない。その春のセキュリティ4.0.4.RELEASE。

+0

@WithMockUser(username = "ram"、authority = {"ROLE_XX"、 "ROLE_AA"})またはユーザー名は省略できます – Tiina

答えて

関連する問題