diff --git a/core/src/main/java/org/springframework/security/authentication/AuthenticationTrustResolver.java b/core/src/main/java/org/springframework/security/authentication/AuthenticationTrustResolver.java
index 48d8ab17dae..ceddacebb40 100644
--- a/core/src/main/java/org/springframework/security/authentication/AuthenticationTrustResolver.java
+++ b/core/src/main/java/org/springframework/security/authentication/AuthenticationTrustResolver.java
@@ -16,6 +16,8 @@
package org.springframework.security.authentication;
+import org.jspecify.annotations.Nullable;
+
import org.springframework.security.core.Authentication;
/**
@@ -37,7 +39,7 @@ public interface AuthenticationTrustResolver {
* @return true
the passed authentication token represented an anonymous
* principal, false
otherwise
*/
- boolean isAnonymous(Authentication authentication);
+ boolean isAnonymous(@Nullable Authentication authentication);
/**
* Indicates whether the passed Authentication
token represents user that
@@ -51,7 +53,7 @@ public interface AuthenticationTrustResolver {
* @return true
the passed authentication token represented a principal
* authenticated using a remember-me token, false
otherwise
*/
- boolean isRememberMe(Authentication authentication);
+ boolean isRememberMe(@Nullable Authentication authentication);
/**
* Indicates whether the passed Authentication
token represents a fully
@@ -66,7 +68,7 @@ public interface AuthenticationTrustResolver {
* {@link #isRememberMe(Authentication)}, false
otherwise
* @since 6.1
*/
- default boolean isFullyAuthenticated(Authentication authentication) {
+ default boolean isFullyAuthenticated(@Nullable Authentication authentication) {
return isAuthenticated(authentication) && !isRememberMe(authentication);
}
@@ -78,7 +80,7 @@ default boolean isFullyAuthenticated(Authentication authentication) {
* {@link Authentication#isAuthenticated()} is true.
* @since 6.1.7
*/
- default boolean isAuthenticated(Authentication authentication) {
+ default boolean isAuthenticated(@Nullable Authentication authentication) {
return authentication != null && authentication.isAuthenticated() && !isAnonymous(authentication);
}
diff --git a/core/src/main/java/org/springframework/security/authentication/AuthenticationTrustResolverImpl.java b/core/src/main/java/org/springframework/security/authentication/AuthenticationTrustResolverImpl.java
index a34645cde0b..556a96a3be5 100644
--- a/core/src/main/java/org/springframework/security/authentication/AuthenticationTrustResolverImpl.java
+++ b/core/src/main/java/org/springframework/security/authentication/AuthenticationTrustResolverImpl.java
@@ -16,6 +16,8 @@
package org.springframework.security.authentication;
+import org.jspecify.annotations.Nullable;
+
import org.springframework.security.core.Authentication;
/**
@@ -44,7 +46,7 @@ Class extends Authentication> getRememberMeClass() {
}
@Override
- public boolean isAnonymous(Authentication authentication) {
+ public boolean isAnonymous(@Nullable Authentication authentication) {
if ((this.anonymousClass == null) || (authentication == null)) {
return false;
}
@@ -52,7 +54,7 @@ public boolean isAnonymous(Authentication authentication) {
}
@Override
- public boolean isRememberMe(Authentication authentication) {
+ public boolean isRememberMe(@Nullable Authentication authentication) {
if ((this.rememberMeClass == null) || (authentication == null)) {
return false;
}