Skip to content

Commit 46e27aa

Browse files
jkuheljzheaux
authored andcommitted
Remove compiler warnings in spring-security-web
- fix compiler warnings in ServerOneTimeTokenAuthenticationConverter - Replace deprecated API calls to create a OneTimeTokenAuthenticationToken.unauthenticated with OneTimeTokenAuthenticationToken(String token) call - Update HttpMessageConverterAuthenticationSuccessHandler to replace deprecated MappingJackson2HttpMessageConverter with JacksonJsonHttpMessageConverter - Replace updated OneTimeTokenAuthenticationConverter to use non-deprecated OneTimeTokenAuthenticationToken constructor - update tests to remove use of deprecated methods - refactor JdbcTokenRepositoryImpl to remove extension of deprecated JdbcDaoSupport class - enable compile-warnings-error plugin Closes gh-18441 Signed-off-by: Joe Kuhel <4983938+jkuhel@users.noreply.github.com>
1 parent 441e0fc commit 46e27aa

6 files changed

Lines changed: 13 additions & 20 deletions

File tree

web/spring-security-web.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'io.spring.convention.spring-module'
33
id 'security-nullability'
4+
id 'compile-warnings-error'
45
id 'javadoc-warnings-error'
56
id 'test-compile-target-jdk25'
67
}

web/src/main/java/org/springframework/security/web/authentication/ott/OneTimeTokenAuthenticationConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class OneTimeTokenAuthenticationConverter implements AuthenticationConver
4646
this.logger.debug("No token found in request");
4747
return null;
4848
}
49-
return OneTimeTokenAuthenticationToken.unauthenticated(token);
49+
return new OneTimeTokenAuthenticationToken(token);
5050
}
5151

5252
}

web/src/main/java/org/springframework/security/web/authentication/rememberme/JdbcTokenRepositoryImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* @author Luke Taylor
3636
* @since 2.0
3737
*/
38+
@SuppressWarnings("removal")
3839
public class JdbcTokenRepositoryImpl extends JdbcDaoSupport implements PersistentTokenRepository {
3940

4041
/** Default SQL for creating the database table to store the tokens */

web/src/main/java/org/springframework/security/web/server/authentication/ott/ServerOneTimeTokenAuthenticationConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public Mono<Authentication> convert(ServerWebExchange exchange) {
5151
if (isFormEncodedRequest(exchange.getRequest())) {
5252
return exchange.getFormData()
5353
.flatMap((data) -> Mono.justOrEmpty(data.getFirst(TOKEN)))
54-
.map((data) -> OneTimeTokenAuthenticationToken.unauthenticated(data));
54+
.map(OneTimeTokenAuthenticationToken::new);
5555
}
5656
String token = resolveTokenFromRequest(exchange.getRequest());
5757
if (!StringUtils.hasText(token)) {
5858
return Mono.empty();
5959
}
60-
return Mono.just(OneTimeTokenAuthenticationToken.unauthenticated(token));
60+
return Mono.just(new OneTimeTokenAuthenticationToken(token));
6161
}
6262

6363
private @Nullable String resolveTokenFromRequest(ServerHttpRequest request) {

web/src/test/java/org/springframework/security/web/authentication/DelegatingAuthenticationEntryPointTests.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.io.IOException;
2020
import java.util.Collections;
21-
import java.util.LinkedHashMap;
2221
import java.util.List;
2322

2423
import jakarta.servlet.ServletException;
@@ -52,16 +51,13 @@ public class DelegatingAuthenticationEntryPointTests {
5251

5352
private DelegatingAuthenticationEntryPoint daep;
5453

55-
private LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPoints;
56-
5754
private AuthenticationEntryPoint defaultEntryPoint;
5855

5956
private HttpServletRequest request = new MockHttpServletRequest();
6057

6158
@BeforeEach
6259
public void before() {
6360
this.defaultEntryPoint = mock(AuthenticationEntryPoint.class);
64-
this.entryPoints = new LinkedHashMap<>();
6561
}
6662

6763
@Test
@@ -70,9 +66,8 @@ public void testDefaultEntryPoint() throws Exception {
7066
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
7167
RequestMatcher firstRM = mock(RequestMatcher.class);
7268
given(firstRM.matches(this.request)).willReturn(false);
73-
this.entryPoints.put(firstRM, firstAEP);
74-
this.daep = new DelegatingAuthenticationEntryPoint(this.entryPoints);
75-
this.daep.setDefaultEntryPoint(this.defaultEntryPoint);
69+
this.daep = new DelegatingAuthenticationEntryPoint(this.defaultEntryPoint,
70+
new RequestMatcherEntry<>(firstRM, firstAEP));
7671
this.daep.commence(this.request, null, null);
7772
verify(this.defaultEntryPoint).commence(this.request, null, null);
7873
verify(firstAEP, never()).commence(this.request, null, null);
@@ -86,10 +81,8 @@ public void testFirstEntryPoint() throws Exception {
8681
AuthenticationEntryPoint secondAEP = mock(AuthenticationEntryPoint.class);
8782
RequestMatcher secondRM = mock(RequestMatcher.class);
8883
given(firstRM.matches(this.request)).willReturn(true);
89-
this.entryPoints.put(firstRM, firstAEP);
90-
this.entryPoints.put(secondRM, secondAEP);
91-
this.daep = new DelegatingAuthenticationEntryPoint(this.entryPoints);
92-
this.daep.setDefaultEntryPoint(this.defaultEntryPoint);
84+
this.daep = new DelegatingAuthenticationEntryPoint(this.defaultEntryPoint,
85+
new RequestMatcherEntry<>(firstRM, firstAEP), new RequestMatcherEntry<>(secondRM, secondAEP));
9386
this.daep.commence(this.request, null, null);
9487
verify(firstAEP).commence(this.request, null, null);
9588
verify(secondAEP, never()).commence(this.request, null, null);
@@ -106,10 +99,8 @@ public void testSecondEntryPoint() throws Exception {
10699
RequestMatcher secondRM = mock(RequestMatcher.class);
107100
given(firstRM.matches(this.request)).willReturn(false);
108101
given(secondRM.matches(this.request)).willReturn(true);
109-
this.entryPoints.put(firstRM, firstAEP);
110-
this.entryPoints.put(secondRM, secondAEP);
111-
this.daep = new DelegatingAuthenticationEntryPoint(this.entryPoints);
112-
this.daep.setDefaultEntryPoint(this.defaultEntryPoint);
102+
this.daep = new DelegatingAuthenticationEntryPoint(this.defaultEntryPoint,
103+
new RequestMatcherEntry<>(firstRM, firstAEP), new RequestMatcherEntry<>(secondRM, secondAEP));
113104
this.daep.commence(this.request, null, null);
114105
verify(secondAEP).commence(this.request, null, null);
115106
verify(firstAEP, never()).commence(this.request, null, null);

web/src/test/java/org/springframework/security/web/authentication/ott/OneTimeTokenAuthenticationFilterTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.springframework.mock.web.MockHttpServletResponse;
3232
import org.springframework.security.authentication.AuthenticationManager;
3333
import org.springframework.security.authentication.BadCredentialsException;
34-
import org.springframework.security.authentication.ott.OneTimeTokenAuthenticationToken;
34+
import org.springframework.security.authentication.ott.OneTimeTokenAuthentication;
3535
import org.springframework.security.core.authority.AuthorityUtils;
3636
import org.springframework.security.web.servlet.MockServletContext;
3737

@@ -120,7 +120,7 @@ void doFilterWhenInvalidTokenThenUnauthorized() throws ServletException, IOExcep
120120
@SuppressWarnings("removal")
121121
void doFilterWhenValidThenRedirectsToSavedRequest() throws ServletException, IOException {
122122
given(this.authenticationManager.authenticate(any()))
123-
.willReturn(OneTimeTokenAuthenticationToken.authenticated("username", AuthorityUtils.NO_AUTHORITIES));
123+
.willReturn(new OneTimeTokenAuthentication("username", AuthorityUtils.NO_AUTHORITIES));
124124
this.filter.doFilter(
125125
post("/login/ott").param("token", "some-token-value").buildRequest(new MockServletContext()),
126126
this.response, this.chain);

0 commit comments

Comments
 (0)