mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-30 22:23:30 +00:00
SEC-3128: RoleVoter supports null Authentication
This commit is contained in:
parent
f232f5ef05
commit
56e41df964
@ -92,6 +92,9 @@ public class RoleVoter implements AccessDecisionVoter<Object> {
|
||||
}
|
||||
|
||||
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
|
||||
if(authentication == null) {
|
||||
return ACCESS_DENIED;
|
||||
}
|
||||
int result = ACCESS_ABSTAIN;
|
||||
Collection<? extends GrantedAuthority> authorities = extractAuthorities(authentication);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.springframework.security.access.vote;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.fest.assertions.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.access.AccessDecisionVoter;
|
||||
@ -21,4 +22,13 @@ public class RoleVoterTests {
|
||||
// Vote on attribute list that has two attributes A and C (i.e. only one matching)
|
||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED, voter.vote(userAB, this, SecurityConfig.createList("A","C")));
|
||||
}
|
||||
|
||||
// SEC-3128
|
||||
@Test
|
||||
public void nullAuthenticationDenies() {
|
||||
RoleVoter voter = new RoleVoter();
|
||||
voter.setRolePrefix("");
|
||||
Authentication notAuthenitcated = null;
|
||||
assertThat(voter.vote(notAuthenitcated, this, SecurityConfig.createList("A"))).isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user