SEC-3128: RoleVoter supports null Authentication
This commit is contained in:
parent
6f1bb705ac
commit
be303b15d1
|
@ -95,6 +95,9 @@ public class RoleVoter implements AccessDecisionVoter<Object> {
|
||||||
|
|
||||||
public int vote(Authentication authentication, Object object,
|
public int vote(Authentication authentication, Object object,
|
||||||
Collection<ConfigAttribute> attributes) {
|
Collection<ConfigAttribute> attributes) {
|
||||||
|
if(authentication == null) {
|
||||||
|
return ACCESS_DENIED;
|
||||||
|
}
|
||||||
int result = ACCESS_ABSTAIN;
|
int result = ACCESS_ABSTAIN;
|
||||||
Collection<? extends GrantedAuthority> authorities = extractAuthorities(authentication);
|
Collection<? extends GrantedAuthority> authorities = extractAuthorities(authentication);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.springframework.security.access.vote;
|
package org.springframework.security.access.vote;
|
||||||
|
|
||||||
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -22,4 +23,13 @@ public class RoleVoterTests {
|
||||||
assertEquals(AccessDecisionVoter.ACCESS_GRANTED,
|
assertEquals(AccessDecisionVoter.ACCESS_GRANTED,
|
||||||
voter.vote(userAB, this, SecurityConfig.createList("A", "C")));
|
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…
Reference in New Issue