mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-23 10:43:30 +00:00
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 javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.security.web.csrf.CsrfToken;
|
import org.springframework.security.web.csrf.CsrfToken;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
@ -118,10 +119,13 @@ public final class SecurityMockMvcRequestBuilders {
|
|||||||
private String username = "user";
|
private String username = "user";
|
||||||
private String password = "password";
|
private String password = "password";
|
||||||
private String loginProcessingUrl = "/login";
|
private String loginProcessingUrl = "/login";
|
||||||
|
private MediaType acceptMediaType = MediaType.APPLICATION_FORM_URLENCODED;
|
||||||
|
|
||||||
private RequestPostProcessor postProcessor = csrf();
|
private RequestPostProcessor postProcessor = csrf();
|
||||||
|
|
||||||
public MockHttpServletRequest buildRequest(ServletContext servletContext) {
|
public MockHttpServletRequest buildRequest(ServletContext servletContext) {
|
||||||
MockHttpServletRequest request = post(loginProcessingUrl)
|
MockHttpServletRequest request = post(loginProcessingUrl)
|
||||||
|
.accept(acceptMediaType)
|
||||||
.param(usernameParam, username).param(passwordParam, password)
|
.param(usernameParam, username).param(passwordParam, password)
|
||||||
.buildRequest(servletContext);
|
.buildRequest(servletContext);
|
||||||
return postProcessor.postProcessRequest(request);
|
return postProcessor.postProcessRequest(request);
|
||||||
@ -208,6 +212,18 @@ public final class SecurityMockMvcRequestBuilders {
|
|||||||
return this;
|
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() {
|
private FormLoginRequestBuilder() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user