Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

SEC-1155: Potential NPEs in RoleVoter and RoleHierarchyVoter #1407

spring-issuemaster opened this Issue May 7, 2009 · 2 comments


None yet
1 participant

Pavel Tcholakov (Migrated from SEC-1155) said:

The implementations of RoleVoter and RoleHierarchyVoter can throw a NPE if called with a null authentication object. It may sometimes be desirable to call AccessDecisionManager.decide() with a null parameter, e.g. see my comment under SEC-884 for one such case where it can be used to implement the ifNotGranted feature correctly.

These problems can be fixed trivially as follows

In RoleVoter.java:

GrantedAuthority[] extractAuthorities(Authentication authentication) {
    return authentication != null ? authentication.getAuthorities() : new GrantedAuthority[]{};

In RoleHierarchyVoter.java:

GrantedAuthority[] extractAuthorities(Authentication authentication) {
    return roleHierarchy.getReachableGrantedAuthorities(super.extractAuthorities(authentication));

The latter method can do the null check itself rather than calling super, but this way there is less repetition although arguably it's less clear what is happening ;-)

Luke Taylor said:

As per the discussion in SEC-884, I've clarified in the Javadoc for AccessDecisionManager that the contract of the decide() method should not allow a null Authentication object. So anything calling it should check first.

@spring-issuemaster spring-issuemaster added this to the 3.0.0 M2 milestone Feb 5, 2016

This issue is related to #1136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment