Added accept method call to buildRequest in SecurityMockMvcRequestBuilders with default of MediaType.APPLICATION_FORM_URLENCODED
This commit is contained in:
parent
66858e22ad
commit
314828859e
|
@ -20,6 +20,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
|||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.security.web.csrf.CsrfToken;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
@ -118,10 +119,13 @@ public final class SecurityMockMvcRequestBuilders {
|
|||
private String username = "user";
|
||||
private String password = "password";
|
||||
private String loginProcessingUrl = "/login";
|
||||
private MediaType acceptMediaType = MediaType.APPLICATION_FORM_URLENCODED;
|
||||
|
||||
private RequestPostProcessor postProcessor = csrf();
|
||||
|
||||
public MockHttpServletRequest buildRequest(ServletContext servletContext) {
|
||||
MockHttpServletRequest request = post(loginProcessingUrl)
|
||||
.accept(acceptMediaType)
|
||||
.param(usernameParam, username).param(passwordParam, password)
|
||||
.buildRequest(servletContext);
|
||||
return postProcessor.postProcessRequest(request);
|
||||
|
@ -208,6 +212,18 @@ public final class SecurityMockMvcRequestBuilders {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a media type to to set as the Accept header in the request.
|
||||
*
|
||||
* @param acceptMediaType the {@link MediaType} to set the Accept header to.
|
||||
* Default is: MediaType.APPLICATION_FORM_URLENCODED
|
||||
* @return the {@link FormLoginRequestBuilder} for additional customizations
|
||||
*/
|
||||
public FormLoginRequestBuilder acceptMediaType(MediaType acceptMediaType) {
|
||||
this.acceptMediaType = acceptMediaType;
|
||||
return this;
|
||||
}
|
||||
|
||||
private FormLoginRequestBuilder() {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue