Skip to content

Commit 5a7f12f

Browse files
Check for null Authentication
Closes gh-14715
1 parent c614422 commit 5a7f12f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

core/src/main/java/org/springframework/security/access/vote/AuthenticatedVoter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class AuthenticatedVoter implements AccessDecisionVoter<Object> {
5757
private AuthenticationTrustResolver authenticationTrustResolver = new AuthenticationTrustResolverImpl();
5858

5959
private boolean isFullyAuthenticated(Authentication authentication) {
60-
return (!this.authenticationTrustResolver.isAnonymous(authentication)
60+
return authentication != null && (!this.authenticationTrustResolver.isAnonymous(authentication)
6161
&& !this.authenticationTrustResolver.isRememberMe(authentication));
6262
}
6363

core/src/test/java/org/springframework/security/access/vote/AuthenticatedVoterTests.java

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void testAnonymousWorks() {
5959
assertThat(AccessDecisionVoter.ACCESS_GRANTED).isEqualTo(voter.vote(createAnonymous(), null, def));
6060
assertThat(AccessDecisionVoter.ACCESS_GRANTED).isEqualTo(voter.vote(createRememberMe(), null, def));
6161
assertThat(AccessDecisionVoter.ACCESS_GRANTED).isEqualTo(voter.vote(createFullyAuthenticated(), null, def));
62+
assertThat(AccessDecisionVoter.ACCESS_DENIED).isEqualTo(voter.vote(null, null, def));
6263
}
6364

6465
@Test
@@ -68,6 +69,7 @@ public void testFullyWorks() {
6869
assertThat(AccessDecisionVoter.ACCESS_DENIED).isEqualTo(voter.vote(createAnonymous(), null, def));
6970
assertThat(AccessDecisionVoter.ACCESS_DENIED).isEqualTo(voter.vote(createRememberMe(), null, def));
7071
assertThat(AccessDecisionVoter.ACCESS_GRANTED).isEqualTo(voter.vote(createFullyAuthenticated(), null, def));
72+
assertThat(AccessDecisionVoter.ACCESS_DENIED).isEqualTo(voter.vote(null, null, def));
7173
}
7274

7375
@Test
@@ -77,6 +79,7 @@ public void testRememberMeWorks() {
7779
assertThat(AccessDecisionVoter.ACCESS_DENIED).isEqualTo(voter.vote(createAnonymous(), null, def));
7880
assertThat(AccessDecisionVoter.ACCESS_GRANTED).isEqualTo(voter.vote(createRememberMe(), null, def));
7981
assertThat(AccessDecisionVoter.ACCESS_GRANTED).isEqualTo(voter.vote(createFullyAuthenticated(), null, def));
82+
assertThat(AccessDecisionVoter.ACCESS_DENIED).isEqualTo(voter.vote(null, null, def));
8083
}
8184

8285
@Test

0 commit comments

Comments
 (0)