From 744433bb4962673c781f719d2bfb30c8a6933007 Mon Sep 17 00:00:00 2001 From: smallbun <30397655+leshalv@users.noreply.github.com> Date: Sat, 20 Jan 2024 21:38:20 +0800 Subject: [PATCH 1/4] Optimize Saml2MetadataFilter --- .../saml2/provider/service/web/Saml2MetadataFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/Saml2MetadataFilter.java b/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/Saml2MetadataFilter.java index b195e4945a5..723acfeba76 100644 --- a/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/Saml2MetadataFilter.java +++ b/saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/Saml2MetadataFilter.java @@ -106,7 +106,7 @@ private void writeMetadataToResponse(HttpServletResponse response, Saml2Metadata response.setContentType(MediaType.APPLICATION_XML_VALUE); String format = "attachment; filename=\"%s\"; filename*=UTF-8''%s"; String fileName = metadata.getFileName(); - String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()); + String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8); response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format(format, fileName, encodedFileName)); response.setContentLength(metadata.getMetadata().getBytes(StandardCharsets.UTF_8).length); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); From 33d8fce315c24ff547c7b7480476fc326c11fac1 Mon Sep 17 00:00:00 2001 From: smallbun <2689170096@qq.com> Date: Sat, 1 Feb 2025 21:58:48 +0800 Subject: [PATCH 2/4] Add setRequestMatcher to PublicKeyCredentialCreationOptionsFilter --- .../PublicKeyCredentialCreationOptionsFilter.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web/src/main/java/org/springframework/security/web/webauthn/registration/PublicKeyCredentialCreationOptionsFilter.java b/web/src/main/java/org/springframework/security/web/webauthn/registration/PublicKeyCredentialCreationOptionsFilter.java index 0863925c8c8..de983f9587c 100644 --- a/web/src/main/java/org/springframework/security/web/webauthn/registration/PublicKeyCredentialCreationOptionsFilter.java +++ b/web/src/main/java/org/springframework/security/web/webauthn/registration/PublicKeyCredentialCreationOptionsFilter.java @@ -38,6 +38,7 @@ import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolderStrategy; +import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; import org.springframework.security.web.webauthn.api.PublicKeyCredentialCreationOptions; import org.springframework.security.web.webauthn.jackson.WebauthnJackson2Module; @@ -82,6 +83,15 @@ public PublicKeyCredentialCreationOptionsFilter(WebAuthnRelyingPartyOperations r this.rpOperations = rpOperations; } + /** + * Use the given {@link ServerWebExchangeMatcher} to match the request. + * @param matcher {@link ServerWebExchangeMatcher} + */ + public void setRequestMatcher(ServerWebExchangeMatcher matcher) { + Assert.notNull(matcher, "matcher cannot be null"); + this.matcher = matcher; + } + @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { From 056cf86f1797feec147d81aec117d0a110237479 Mon Sep 17 00:00:00 2001 From: smallbun <2689170096@qq.com> Date: Sat, 1 Feb 2025 22:07:19 +0800 Subject: [PATCH 3/4] Add setRequestMatcher to PublicKeyCredentialCreationOptionsFilter --- ...ublicKeyCredentialRequestOptionsFilter.java | 9 +++++++++ ...blicKeyCredentialCreationOptionsFilter.java | 10 +++++----- .../WebAuthnRegistrationFilter.java | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/web/src/main/java/org/springframework/security/web/webauthn/authentication/PublicKeyCredentialRequestOptionsFilter.java b/web/src/main/java/org/springframework/security/web/webauthn/authentication/PublicKeyCredentialRequestOptionsFilter.java index 877869b709a..e07dd283f61 100644 --- a/web/src/main/java/org/springframework/security/web/webauthn/authentication/PublicKeyCredentialRequestOptionsFilter.java +++ b/web/src/main/java/org/springframework/security/web/webauthn/authentication/PublicKeyCredentialRequestOptionsFilter.java @@ -75,6 +75,15 @@ public PublicKeyCredentialRequestOptionsFilter(WebAuthnRelyingPartyOperations rp this.rpOptions = rpOptions; } + /** + * Sets the {@link RequestMatcher} used to trigger this filter. + * @param requestMatcher the {@link RequestMatcher} to use + */ + public void setRequestMatcher(RequestMatcher requestMatcher) { + Assert.notNull(requestMatcher, "requestMatcher cannot be null"); + this.matcher = requestMatcher; + } + @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { diff --git a/web/src/main/java/org/springframework/security/web/webauthn/registration/PublicKeyCredentialCreationOptionsFilter.java b/web/src/main/java/org/springframework/security/web/webauthn/registration/PublicKeyCredentialCreationOptionsFilter.java index de983f9587c..1384c04f5ba 100644 --- a/web/src/main/java/org/springframework/security/web/webauthn/registration/PublicKeyCredentialCreationOptionsFilter.java +++ b/web/src/main/java/org/springframework/security/web/webauthn/registration/PublicKeyCredentialCreationOptionsFilter.java @@ -84,12 +84,12 @@ public PublicKeyCredentialCreationOptionsFilter(WebAuthnRelyingPartyOperations r } /** - * Use the given {@link ServerWebExchangeMatcher} to match the request. - * @param matcher {@link ServerWebExchangeMatcher} + * Sets the {@link RequestMatcher} used to trigger this filter. + * @param requestMatcher the {@link RequestMatcher} to use */ - public void setRequestMatcher(ServerWebExchangeMatcher matcher) { - Assert.notNull(matcher, "matcher cannot be null"); - this.matcher = matcher; + public void setRequestMatcher(RequestMatcher requestMatcher) { + Assert.notNull(requestMatcher, "requestMatcher cannot be null"); + this.matcher = requestMatcher; } @Override diff --git a/web/src/main/java/org/springframework/security/web/webauthn/registration/WebAuthnRegistrationFilter.java b/web/src/main/java/org/springframework/security/web/webauthn/registration/WebAuthnRegistrationFilter.java index d14e8559148..ead41b669b5 100644 --- a/web/src/main/java/org/springframework/security/web/webauthn/registration/WebAuthnRegistrationFilter.java +++ b/web/src/main/java/org/springframework/security/web/webauthn/registration/WebAuthnRegistrationFilter.java @@ -105,6 +105,24 @@ public WebAuthnRegistrationFilter(UserCredentialRepository userCredentials, this.rpOptions = rpOptions; } + /** + * Sets the {@link RequestMatcher} used to trigger this filter. + * @param registerCredentialMatcher the {@link RequestMatcher} to use + */ + public void setRegisterCredentialMatcher(RequestMatcher registerCredentialMatcher) { + Assert.notNull(registerCredentialMatcher, "registerCredentialMatcher cannot be null"); + this.registerCredentialMatcher = registerCredentialMatcher; + } + + /** + * Sets the {@link RequestMatcher} used to trigger this filter. + * @param removeCredentialMatcher the {@link RequestMatcher} to use + */ + public void setRemoveCredentialMatcher(RequestMatcher removeCredentialMatcher) { + Assert.notNull(removeCredentialMatcher, "removeCredentialMatcher cannot be null"); + this.removeCredentialMatcher = removeCredentialMatcher; + } + @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { From 7d9217dfce6efaae9ec198c2ceac3170eaacab00 Mon Sep 17 00:00:00 2001 From: smallbun <2689170096@qq.com> Date: Sat, 1 Feb 2025 22:19:22 +0800 Subject: [PATCH 4/4] Add setRequestMatcher to PublicKeyCredentialCreationOptionsFilter --- .../registration/PublicKeyCredentialCreationOptionsFilter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/web/src/main/java/org/springframework/security/web/webauthn/registration/PublicKeyCredentialCreationOptionsFilter.java b/web/src/main/java/org/springframework/security/web/webauthn/registration/PublicKeyCredentialCreationOptionsFilter.java index 1384c04f5ba..453246feb18 100644 --- a/web/src/main/java/org/springframework/security/web/webauthn/registration/PublicKeyCredentialCreationOptionsFilter.java +++ b/web/src/main/java/org/springframework/security/web/webauthn/registration/PublicKeyCredentialCreationOptionsFilter.java @@ -38,7 +38,6 @@ import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolderStrategy; -import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; import org.springframework.security.web.webauthn.api.PublicKeyCredentialCreationOptions; import org.springframework.security.web.webauthn.jackson.WebauthnJackson2Module;