Skip to content

Commit bb64e31

Browse files
committed
Switch to JSpecify annotations
Closes gh-17535 Signed-off-by: DingHao <[email protected]>
1 parent dadf4c0 commit bb64e31

File tree

10 files changed

+27
-36
lines changed

10 files changed

+27
-36
lines changed

web/src/main/java/org/springframework/security/web/DefaultSecurityFilterChain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 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.
@@ -25,14 +25,14 @@
2525
import org.apache.commons.logging.Log;
2626
import org.apache.commons.logging.LogFactory;
2727

28+
import org.jspecify.annotations.NonNull;
2829
import org.springframework.beans.BeansException;
2930
import org.springframework.beans.factory.BeanFactory;
3031
import org.springframework.beans.factory.BeanFactoryAware;
3132
import org.springframework.beans.factory.BeanNameAware;
3233
import org.springframework.beans.factory.config.BeanDefinition;
3334
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
3435
import org.springframework.core.log.LogMessage;
35-
import org.springframework.lang.NonNull;
3636
import org.springframework.security.web.util.matcher.RequestMatcher;
3737
import org.springframework.util.StringUtils;
3838

web/src/main/java/org/springframework/security/web/authentication/UsernamePasswordAuthenticationFilter.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import jakarta.servlet.http.HttpServletRequest;
2020
import jakarta.servlet.http.HttpServletResponse;
2121

22+
import org.jspecify.annotations.Nullable;
2223
import org.springframework.http.HttpMethod;
23-
import org.springframework.lang.Nullable;
2424
import org.springframework.security.authentication.AuthenticationManager;
2525
import org.springframework.security.authentication.AuthenticationServiceException;
2626
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -100,8 +100,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
100100
* @return the password that will be presented in the <code>Authentication</code>
101101
* request token to the <code>AuthenticationManager</code>
102102
*/
103-
@Nullable
104-
protected String obtainPassword(HttpServletRequest request) {
103+
@Nullable protected String obtainPassword(HttpServletRequest request) {
105104
return request.getParameter(this.passwordParameter);
106105
}
107106

@@ -112,8 +111,7 @@ protected String obtainPassword(HttpServletRequest request) {
112111
* @return the username that will be presented in the <code>Authentication</code>
113112
* request token to the <code>AuthenticationManager</code>
114113
*/
115-
@Nullable
116-
protected String obtainUsername(HttpServletRequest request) {
114+
@Nullable protected String obtainUsername(HttpServletRequest request) {
117115
return request.getParameter(this.usernameParameter);
118116
}
119117

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

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

1919
import jakarta.servlet.http.HttpServletRequest;
2020

21-
import org.springframework.lang.Nullable;
21+
import org.jspecify.annotations.Nullable;
2222
import org.springframework.security.authentication.ott.GenerateOneTimeTokenRequest;
2323

2424
/**
@@ -35,7 +35,6 @@ public interface GenerateOneTimeTokenRequestResolver {
3535
* @param request {@link HttpServletRequest} to resolve
3636
* @return {@link GenerateOneTimeTokenRequest}
3737
*/
38-
@Nullable
39-
GenerateOneTimeTokenRequest resolve(HttpServletRequest request);
38+
@Nullable GenerateOneTimeTokenRequest resolve(HttpServletRequest request);
4039

4140
}

web/src/main/java/org/springframework/security/web/authentication/password/HaveIBeenPwnedRestApiPasswordChecker.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 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.
@@ -26,7 +26,7 @@
2626
import org.apache.commons.logging.Log;
2727
import org.apache.commons.logging.LogFactory;
2828

29-
import org.springframework.lang.NonNull;
29+
import org.jspecify.annotations.NonNull;
3030
import org.springframework.security.authentication.password.CompromisedPasswordChecker;
3131
import org.springframework.security.authentication.password.CompromisedPasswordDecision;
3232
import org.springframework.security.crypto.codec.Hex;
@@ -61,8 +61,7 @@ public HaveIBeenPwnedRestApiPasswordChecker() {
6161
}
6262

6363
@Override
64-
@NonNull
65-
public CompromisedPasswordDecision check(String password) {
64+
@NonNull public CompromisedPasswordDecision check(String password) {
6665
byte[] hash = this.sha1Digest.digest(password.getBytes(StandardCharsets.UTF_8));
6766
String encoded = new String(Hex.encode(hash)).toUpperCase(Locale.ROOT);
6867
String prefix = encoded.substring(0, PREFIX_LENGTH);

web/src/main/java/org/springframework/security/web/reactive/result/view/CsrfRequestDataValueProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 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.
@@ -20,7 +20,7 @@
2020
import java.util.Map;
2121
import java.util.regex.Pattern;
2222

23-
import org.springframework.lang.NonNull;
23+
import org.jspecify.annotations.NonNull;
2424
import org.springframework.security.web.server.csrf.CsrfToken;
2525
import org.springframework.web.reactive.result.view.RequestDataValueProcessor;
2626
import org.springframework.web.server.ServerWebExchange;

web/src/main/java/org/springframework/security/web/server/ObservationWebFilterChainDecorator.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 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.
@@ -28,7 +28,7 @@
2828
import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor;
2929
import reactor.core.publisher.Mono;
3030

31-
import org.springframework.lang.Nullable;
31+
import org.jspecify.annotations.Nullable;
3232
import org.springframework.util.Assert;
3333
import org.springframework.util.StringUtils;
3434
import org.springframework.web.server.ServerWebExchange;
@@ -108,11 +108,9 @@ static class ObservationWebFilterChain implements WebFilterChain {
108108

109109
private final WebHandler handler;
110110

111-
@Nullable
112-
private final ObservationWebFilter currentFilter;
111+
@Nullable private final ObservationWebFilter currentFilter;
113112

114-
@Nullable
115-
private final ObservationWebFilterChain chain;
113+
@Nullable private final ObservationWebFilterChain chain;
116114

117115
/**
118116
* Public constructor with the list of filters and the target handler to use.

web/src/main/java/org/springframework/security/web/server/authentication/ServerX509AuthenticationConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 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.
@@ -22,8 +22,8 @@
2222
import org.apache.commons.logging.LogFactory;
2323
import reactor.core.publisher.Mono;
2424

25+
import org.jspecify.annotations.NonNull;
2526
import org.springframework.http.server.reactive.SslInfo;
26-
import org.springframework.lang.NonNull;
2727
import org.springframework.security.core.Authentication;
2828
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
2929
import org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor;

web/src/main/java/org/springframework/security/web/server/authentication/SwitchUserWebFilter.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 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.
@@ -25,10 +25,10 @@
2525
import org.apache.commons.logging.LogFactory;
2626
import reactor.core.publisher.Mono;
2727

28+
import org.jspecify.annotations.NonNull;
29+
import org.jspecify.annotations.Nullable;
2830
import org.springframework.core.log.LogMessage;
2931
import org.springframework.http.HttpMethod;
30-
import org.springframework.lang.NonNull;
31-
import org.springframework.lang.Nullable;
3232
import org.springframework.security.authentication.AccountStatusUserDetailsChecker;
3333
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
3434
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -215,8 +215,7 @@ protected String getUsername(ServerWebExchange exchange) {
215215
return exchange.getRequest().getQueryParams().getFirst(SPRING_SECURITY_SWITCH_USERNAME_KEY);
216216
}
217217

218-
@NonNull
219-
private Mono<Authentication> attemptSwitchUser(Authentication currentAuthentication, String userName) {
218+
@NonNull private Mono<Authentication> attemptSwitchUser(Authentication currentAuthentication, String userName) {
220219
Assert.notNull(userName, "The userName can not be null.");
221220
this.logger.debug(LogMessage.format("Attempting to switch to user [%s]", userName));
222221
return this.userDetailsService.findByUsername(userName)
@@ -225,8 +224,7 @@ private Mono<Authentication> attemptSwitchUser(Authentication currentAuthenticat
225224
.map((userDetails) -> createSwitchUserToken(userDetails, currentAuthentication));
226225
}
227226

228-
@NonNull
229-
private Authentication attemptExitUser(Authentication currentAuthentication) {
227+
@NonNull private Authentication attemptExitUser(Authentication currentAuthentication) {
230228
Optional<Authentication> sourceAuthentication = extractSourceAuthentication(currentAuthentication);
231229
if (sourceAuthentication.isEmpty()) {
232230
this.logger.debug("Failed to find original user");

web/src/main/java/org/springframework/security/web/servlet/util/matcher/PathPatternRequestMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
import jakarta.servlet.http.HttpServletRequest;
2222

23+
import org.jspecify.annotations.Nullable;
2324
import org.springframework.http.HttpMethod;
2425
import org.springframework.http.server.PathContainer;
2526
import org.springframework.http.server.RequestPath;
26-
import org.springframework.lang.Nullable;
2727
import org.springframework.security.web.access.intercept.RequestAuthorizationContext;
2828
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
2929
import org.springframework.security.web.util.matcher.RequestMatcher;

web/src/main/java/org/springframework/security/web/util/matcher/DispatcherTypeRequestMatcher.java

Lines changed: 3 additions & 4 deletions
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.
@@ -19,8 +19,8 @@
1919
import jakarta.servlet.DispatcherType;
2020
import jakarta.servlet.http.HttpServletRequest;
2121

22+
import org.jspecify.annotations.Nullable;
2223
import org.springframework.http.HttpMethod;
23-
import org.springframework.lang.Nullable;
2424
import org.springframework.util.StringUtils;
2525

2626
/**
@@ -36,8 +36,7 @@ public class DispatcherTypeRequestMatcher implements RequestMatcher {
3636

3737
private final DispatcherType dispatcherType;
3838

39-
@Nullable
40-
private final HttpMethod httpMethod;
39+
@Nullable private final HttpMethod httpMethod;
4140

4241
/**
4342
* Creates an instance which matches requests with the provided {@link DispatcherType}

0 commit comments

Comments
 (0)