Skip to content

Commit 9908d96

Browse files
kwondh5217jzheaux
authored andcommitted
DeferredCsrfToken Implements Supplier
Closes gh-16870 Signed-off-by: Daeho Kwon <[email protected]>
1 parent 43ef426 commit 9908d96

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

Diff for: config/src/test/java/org/springframework/security/config/annotation/web/configurers/SessionManagementConfigurerServlet31Tests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -87,7 +87,7 @@ public void changeSessionIdThenPreserveParameters() throws Exception {
8787
HttpSessionCsrfTokenRepository repository = new HttpSessionCsrfTokenRepository();
8888
CsrfTokenRequestHandler handler = new XorCsrfTokenRequestAttributeHandler();
8989
DeferredCsrfToken deferredCsrfToken = repository.loadDeferredToken(request, this.response);
90-
handler.handle(request, this.response, deferredCsrfToken::get);
90+
handler.handle(request, this.response, deferredCsrfToken);
9191
CsrfToken token = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
9292
request.setParameter(token.getParameterName(), token.getToken());
9393
request.getSession().setAttribute("attribute1", "value1");

Diff for: test/src/main/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessors.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request)
524524
TestCsrfTokenRepository.enable(request);
525525
MockHttpServletResponse response = new MockHttpServletResponse();
526526
DeferredCsrfToken deferredCsrfToken = repository.loadDeferredToken(request, response);
527-
handler.handle(request, response, deferredCsrfToken::get);
527+
handler.handle(request, response, deferredCsrfToken);
528528
CsrfToken token = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
529529
String tokenValue = this.useInvalidToken ? INVALID_TOKEN_VALUE : token.getToken();
530530
if (this.asHeader) {

Diff for: test/src/test/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessorsCsrfTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public void csrfWhenUsedThenDoesNotImpactOriginalRepository() throws Exception {
164164
HttpSessionCsrfTokenRepository repo = new HttpSessionCsrfTokenRepository();
165165
CsrfTokenRequestHandler handler = new XorCsrfTokenRequestAttributeHandler();
166166
DeferredCsrfToken deferredCsrfToken = repo.loadDeferredToken(request, response);
167-
handler.handle(request, response, deferredCsrfToken::get);
167+
handler.handle(request, response, deferredCsrfToken);
168168
CsrfToken token = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
169169
MockHttpServletRequestBuilder requestWithCsrf = post("/")
170170
.param(token.getParameterName(), token.getToken())

Diff for: web/src/main/java/org/springframework/security/web/csrf/CsrfAuthenticationStrategy.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@ public void onAuthentication(Authentication authentication, HttpServletRequest r
6969
if (containsToken) {
7070
this.tokenRepository.saveToken(null, request, response);
7171
DeferredCsrfToken deferredCsrfToken = this.tokenRepository.loadDeferredToken(request, response);
72-
this.requestHandler.handle(request, response, deferredCsrfToken::get);
72+
this.requestHandler.handle(request, response, deferredCsrfToken);
7373
this.logger.debug("Replaced CSRF Token");
7474
}
7575
}

Diff for: web/src/main/java/org/springframework/security/web/csrf/CsrfFilter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -108,7 +108,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
108108
throws ServletException, IOException {
109109
DeferredCsrfToken deferredCsrfToken = this.tokenRepository.loadDeferredToken(request, response);
110110
request.setAttribute(DeferredCsrfToken.class.getName(), deferredCsrfToken);
111-
this.requestHandler.handle(request, response, deferredCsrfToken::get);
111+
this.requestHandler.handle(request, response, deferredCsrfToken);
112112
if (!this.requireCsrfProtectionMatcher.matches(request)) {
113113
if (this.logger.isTraceEnabled()) {
114114
this.logger.trace("Did not protect against CSRF since request did not match "

Diff for: web/src/main/java/org/springframework/security/web/csrf/DeferredCsrfToken.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,14 +16,17 @@
1616

1717
package org.springframework.security.web.csrf;
1818

19+
import java.util.function.Supplier;
20+
1921
/**
2022
* An interface that allows delayed access to a {@link CsrfToken} that may be generated.
2123
*
2224
* @author Rob Winch
2325
* @author Steve Riesenberg
26+
* @author Daeho Kwon
2427
* @since 5.8
2528
*/
26-
public interface DeferredCsrfToken {
29+
public interface DeferredCsrfToken extends Supplier<CsrfToken> {
2730

2831
/**
2932
* Gets the {@link CsrfToken}

0 commit comments

Comments
 (0)