Support URI vars in formLogin and logout MockMvc requests
This commit is contained in:
committed by
Eleftheria Stein-Kousathana
parent
8722a4b0d0
commit
4f82be7e68
+29
@@ -23,6 +23,7 @@ import org.springframework.security.web.csrf.CsrfToken;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.RequestBuilder;
|
||||
import org.springframework.test.web.servlet.request.RequestPostProcessor;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
@@ -71,6 +72,8 @@ public final class SecurityMockMvcRequestBuilders {
|
||||
* Creates a logout request (including any necessary {@link CsrfToken}) to the
|
||||
* specified {@code logoutUrl}
|
||||
*
|
||||
* @param logoutUrl the logout request URL
|
||||
*
|
||||
* @return the LogoutRequestBuilder for additional customizations
|
||||
*/
|
||||
public static LogoutRequestBuilder logout(String logoutUrl) {
|
||||
@@ -106,6 +109,19 @@ public final class SecurityMockMvcRequestBuilders {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the logout URL to POST to.
|
||||
*
|
||||
* @param logoutUrl the logout URL to POST to.
|
||||
* @param uriVars the URI variables
|
||||
* @return the {@link LogoutRequestBuilder} for additional customizations
|
||||
*/
|
||||
public LogoutRequestBuilder logoutUrl(String logoutUrl, Object... uriVars) {
|
||||
this.logoutUrl = UriComponentsBuilder.fromPath(logoutUrl)
|
||||
.buildAndExpand(uriVars).encode().toString();
|
||||
return this;
|
||||
}
|
||||
|
||||
private LogoutRequestBuilder() {
|
||||
}
|
||||
}
|
||||
@@ -146,6 +162,19 @@ public final class SecurityMockMvcRequestBuilders {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the URL to POST to.
|
||||
*
|
||||
* @param loginProcessingUrl the URL to POST to
|
||||
* @param uriVars the URI variables
|
||||
* @return the {@link FormLoginRequestBuilder} for additional customizations
|
||||
*/
|
||||
public FormLoginRequestBuilder loginProcessingUrl(String loginProcessingUrl, Object... uriVars) {
|
||||
this.loginProcessingUrl = UriComponentsBuilder.fromPath(loginProcessingUrl)
|
||||
.buildAndExpand(uriVars).encode().toString();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The HTTP parameter to place the username. Default is "username".
|
||||
* @param usernameParameter the HTTP parameter to place the username. Default is
|
||||
|
||||
Reference in New Issue
Block a user