From 991dde58fe9fe4561be0e3970aeb9bf9e29cc671 Mon Sep 17 00:00:00 2001 From: Daniel Garnier-Moiroux Date: Fri, 6 Sep 2024 11:23:29 +0200 Subject: [PATCH 1/4] Use contextPath in One-Time-Token default submit UI --- .../DefaultOneTimeTokenSubmitPageGeneratingFilter.java | 3 ++- ...faultOneTimeTokenSubmitPageGeneratingFilterTests.java | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/web/src/main/java/org/springframework/security/web/authentication/ui/DefaultOneTimeTokenSubmitPageGeneratingFilter.java b/web/src/main/java/org/springframework/security/web/authentication/ui/DefaultOneTimeTokenSubmitPageGeneratingFilter.java index 86681958ae0..cafa59bdd87 100644 --- a/web/src/main/java/org/springframework/security/web/authentication/ui/DefaultOneTimeTokenSubmitPageGeneratingFilter.java +++ b/web/src/main/java/org/springframework/security/web/authentication/ui/DefaultOneTimeTokenSubmitPageGeneratingFilter.java @@ -66,6 +66,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse private String generateHtml(HttpServletRequest request) { String token = request.getParameter("token"); String tokenValue = StringUtils.hasText(token) ? token : ""; + String contextPath = request.getContextPath(); String hiddenInputs = this.resolveHiddenInputs.apply(request) .entrySet() @@ -76,7 +77,7 @@ private String generateHtml(HttpServletRequest request) { return HtmlTemplates.fromTemplate(ONE_TIME_TOKEN_SUBMIT_PAGE_TEMPLATE) .withRawHtml("cssStyle", CssUtils.getCssStyleBlock().indent(4)) .withValue("tokenValue", tokenValue) - .withValue("loginProcessingUrl", this.loginProcessingUrl) + .withValue("loginProcessingUrl", contextPath + this.loginProcessingUrl) .withRawHtml("hiddenInputs", hiddenInputs) .render(); } diff --git a/web/src/test/java/org/springframework/security/web/authentication/ui/DefaultOneTimeTokenSubmitPageGeneratingFilterTests.java b/web/src/test/java/org/springframework/security/web/authentication/ui/DefaultOneTimeTokenSubmitPageGeneratingFilterTests.java index f92bfbedb44..07d1a2be3a3 100644 --- a/web/src/test/java/org/springframework/security/web/authentication/ui/DefaultOneTimeTokenSubmitPageGeneratingFilterTests.java +++ b/web/src/test/java/org/springframework/security/web/authentication/ui/DefaultOneTimeTokenSubmitPageGeneratingFilterTests.java @@ -77,6 +77,15 @@ void setLoginProcessingUrlThenUseItForFormAction() throws Exception { assertThat(response).contains("
"); } + @Test + void setContextThenGenerates() throws Exception { + this.request.setContextPath("/context"); + this.filter.setLoginProcessingUrl("/login/another"); + this.filter.doFilterInternal(this.request, this.response, this.filterChain); + String response = this.response.getContentAsString(); + assertThat(response).contains(""); + } + @Test void filterWhenTokenQueryParamUsesSpecialCharactersThenValueIsEscaped() throws Exception { this.request.setParameter("token", "this<>!@#\""); From 848873b3aa255d65bbcc7970610547b86d70b839 Mon Sep 17 00:00:00 2001 From: Daniel Garnier-Moiroux Date: Fri, 6 Sep 2024 11:24:52 +0200 Subject: [PATCH 2/4] Remove unused