Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>UPDATE</strong>: Spring Security 4 has added official <a href="http://docs.spring.io/spring-security/site/docs/4.0.x/reference/htmlsingle/#test" rel="nofollow">Test Support</a>. There is a section that describes <a href="http://docs.spring.io/spring-security/site/docs/4.0.x/reference/htmlsingle/#test-mockmvc" rel="nofollow">testing with MockMvc</a> in detail.</p> <p>It sounds as though you have not added the Spring Security Filter to your MockMvc. For example:</p> <pre><code>public class MyTests { @Autowired private FilterChainProxy springSecurityFilterChain; @Autowired private WebApplicationContext wac; private MockMvc mockMvc; @Before public void setup() { this.mockMvc = MockMvcBuilders.webApplicationContextSetup(this.wac) .addFilters(this.springSecurityFilterChain).build(); } @Test public void testLoginPostController() throws Exception { Account account = new AccountBuilder("test", "test", "test@gmail.com", Address.FAKE_EMPTY_ADDRESS4TESTS) .build(); this.mockMvc.perform(post("/j_spring_security_check").param("j_username", account.getUsername()).param("j_password", "test")) .andDo(print()) .andExpect(status().isMovedTemporarily()) .andExpect(view().name("redirect:/public/index.htm")); } } </code></pre> <p>The reason this is happening is because right now the MockMvc is only aware of your Spring MVC configuration and is not aware of any Filter (i.e. the FilterChainProxy). Since validation of the username and password (i.e. processing of /j_spring_security_check) occurs within FilterChainProxy before it is sent to Spring MVC and you have not included it you are getting a 404.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload