Skip to content

Commit 991dde5

Browse files
committed
Use contextPath in One-Time-Token default submit UI
1 parent ef31ae1 commit 991dde5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

web/src/main/java/org/springframework/security/web/authentication/ui/DefaultOneTimeTokenSubmitPageGeneratingFilter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
6666
private String generateHtml(HttpServletRequest request) {
6767
String token = request.getParameter("token");
6868
String tokenValue = StringUtils.hasText(token) ? token : "";
69+
String contextPath = request.getContextPath();
6970

7071
String hiddenInputs = this.resolveHiddenInputs.apply(request)
7172
.entrySet()
@@ -76,7 +77,7 @@ private String generateHtml(HttpServletRequest request) {
7677
return HtmlTemplates.fromTemplate(ONE_TIME_TOKEN_SUBMIT_PAGE_TEMPLATE)
7778
.withRawHtml("cssStyle", CssUtils.getCssStyleBlock().indent(4))
7879
.withValue("tokenValue", tokenValue)
79-
.withValue("loginProcessingUrl", this.loginProcessingUrl)
80+
.withValue("loginProcessingUrl", contextPath + this.loginProcessingUrl)
8081
.withRawHtml("hiddenInputs", hiddenInputs)
8182
.render();
8283
}

web/src/test/java/org/springframework/security/web/authentication/ui/DefaultOneTimeTokenSubmitPageGeneratingFilterTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ void setLoginProcessingUrlThenUseItForFormAction() throws Exception {
7777
assertThat(response).contains("<form class=\"login-form\" action=\"/login/another\" method=\"post\">");
7878
}
7979

80+
@Test
81+
void setContextThenGenerates() throws Exception {
82+
this.request.setContextPath("/context");
83+
this.filter.setLoginProcessingUrl("/login/another");
84+
this.filter.doFilterInternal(this.request, this.response, this.filterChain);
85+
String response = this.response.getContentAsString();
86+
assertThat(response).contains("<form class=\"login-form\" action=\"/context/login/another\" method=\"post\">");
87+
}
88+
8089
@Test
8190
void filterWhenTokenQueryParamUsesSpecialCharactersThenValueIsEscaped() throws Exception {
8291
this.request.setParameter("token", "this<>!@#\"");

0 commit comments

Comments
 (0)