SEC-1550: Convert signatures to use Collection<? extends GrantedAuthority> where appropriate.

This commit is contained in:
Luke Taylor
2010-11-03 13:45:35 +00:00
parent 8d867e8b67
commit 1c8d28501c
37 changed files with 71 additions and 65 deletions

View File

@@ -121,7 +121,7 @@ public abstract class SecurityExpressionRoot {
private Set<String> getAuthoritySet() {
if (roles == null) {
roles = new HashSet<String>();
Collection<GrantedAuthority> userAuthorities = authentication.getAuthorities();
Collection<? extends GrantedAuthority> userAuthorities = authentication.getAuthorities();
if (roleHierarchy != null) {
userAuthorities = roleHierarchy.getReachableGrantedAuthorities(userAuthorities);

View File

@@ -11,7 +11,7 @@ import org.springframework.security.core.GrantedAuthority;
*/
public final class NullRoleHierarchy implements RoleHierarchy {
public Collection<GrantedAuthority> getReachableGrantedAuthorities(Collection<GrantedAuthority> authorities) {
public Collection<? extends GrantedAuthority> getReachableGrantedAuthorities(Collection<? extends GrantedAuthority> authorities) {
return authorities;
}

View File

@@ -40,6 +40,6 @@ public interface RoleHierarchy {
* @param authorities - List of the directly assigned authorities.
* @return List of all reachable authorities given the assigned authorities.
*/
public Collection<GrantedAuthority> getReachableGrantedAuthorities(Collection<GrantedAuthority> authorities);
public Collection<? extends GrantedAuthority> getReachableGrantedAuthorities(Collection<? extends GrantedAuthority> authorities);
}

View File

@@ -105,7 +105,7 @@ public class RoleHierarchyImpl implements RoleHierarchy {
buildRolesReachableInOneOrMoreStepsMap();
}
public Collection<GrantedAuthority> getReachableGrantedAuthorities(Collection<GrantedAuthority> authorities) {
public Collection<GrantedAuthority> getReachableGrantedAuthorities(Collection<? extends GrantedAuthority> authorities) {
if (authorities == null || authorities.isEmpty()) {
return AuthorityUtils.NO_AUTHORITIES;
}

View File

@@ -49,7 +49,7 @@ public class UserDetailsWrapper implements UserDetails {
return userDetails.isAccountNonLocked();
}
public Collection<GrantedAuthority> getAuthorities() {
public Collection<? extends GrantedAuthority> getAuthorities() {
return roleHierarchy.getReachableGrantedAuthorities(userDetails.getAuthorities());
}

View File

@@ -26,7 +26,7 @@ public class RoleHierarchyVoter extends RoleVoter {
* Calls the <tt>RoleHierarchy</tt> to obtain the complete set of user authorities.
*/
@Override
Collection<GrantedAuthority> extractAuthorities(Authentication authentication) {
Collection<? extends GrantedAuthority> extractAuthorities(Authentication authentication) {
return roleHierarchy.getReachableGrantedAuthorities(authentication.getAuthorities());
}
}

View File

@@ -93,7 +93,7 @@ public class RoleVoter implements AccessDecisionVoter {
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
int result = ACCESS_ABSTAIN;
Collection<GrantedAuthority> authorities = extractAuthorities(authentication);
Collection<? extends GrantedAuthority> authorities = extractAuthorities(authentication);
for (ConfigAttribute attribute : attributes) {
if (this.supports(attribute)) {
@@ -111,7 +111,7 @@ public class RoleVoter implements AccessDecisionVoter {
return result;
}
Collection<GrantedAuthority> extractAuthorities(Authentication authentication) {
Collection<? extends GrantedAuthority> extractAuthorities(Authentication authentication) {
return authentication.getAuthorities();
}
}

View File

@@ -30,7 +30,7 @@ public interface RemoteAuthenticationManager {
/**
* Attempts to authenticate the remote client using the presented username and password. If authentication
* is successful, an array of <code>GrantedAuthority[]</code> objects will be returned.
* is successful, a collection of {@code GrantedAuthority} objects will be returned.
* <p>
* In order to maximise remoting protocol compatibility, a design decision was taken to operate with minimal
* arguments and return only the minimal amount of information required for remote clients to enable/disable
@@ -44,6 +44,6 @@ public interface RemoteAuthenticationManager {
*
* @throws RemoteAuthenticationException if the authentication failed.
*/
Collection<GrantedAuthority> attemptAuthentication(String username, String password)
Collection<? extends GrantedAuthority> attemptAuthentication(String username, String password)
throws RemoteAuthenticationException;
}

View File

@@ -44,7 +44,7 @@ public class RemoteAuthenticationManagerImpl implements RemoteAuthenticationMana
Assert.notNull(this.authenticationManager, "authenticationManager is required");
}
public Collection<GrantedAuthority> attemptAuthentication(String username, String password)
public Collection<? extends GrantedAuthority> attemptAuthentication(String username, String password)
throws RemoteAuthenticationException {
UsernamePasswordAuthenticationToken request = new UsernamePasswordAuthenticationToken(username, password);

View File

@@ -58,7 +58,7 @@ public class RemoteAuthenticationProvider implements AuthenticationProvider, Ini
throws AuthenticationException {
String username = authentication.getPrincipal().toString();
String password = authentication.getCredentials().toString();
Collection<GrantedAuthority> authorities = remoteAuthenticationManager.attemptAuthentication(username, password);
Collection<? extends GrantedAuthority> authorities = remoteAuthenticationManager.attemptAuthentication(username, password);
return new UsernamePasswordAuthenticationToken(username, password, authorities);
}

View File

@@ -59,7 +59,7 @@ public interface Authentication extends Principal, Serializable {
* @return the authorities granted to the principal, or an empty collection if the token has not been authenticated.
* Never null.
*/
Collection<GrantedAuthority> getAuthorities();
Collection<? extends GrantedAuthority> getAuthorities();
/**
* The credentials that prove the principal is correct. This is usually a password, but could be anything

View File

@@ -35,7 +35,7 @@ public abstract class AuthorityUtils {
* Converts an array of GrantedAuthority objects to a Set.
* @return a Set of the Strings obtained from each call to GrantedAuthority.getAuthority()
*/
public static Set<String> authorityListToSet(Collection<GrantedAuthority> userAuthorities) {
public static Set<String> authorityListToSet(Collection<? extends GrantedAuthority> userAuthorities) {
Set<String> set = new HashSet<String>(userAuthorities.size());
for (GrantedAuthority authority: userAuthorities) {

View File

@@ -59,7 +59,7 @@ public interface UserDetails extends Serializable {
*
* @return the authorities, sorted by natural key (never <code>null</code>)
*/
Collection<GrantedAuthority> getAuthorities();
Collection<? extends GrantedAuthority> getAuthorities();
/**
* Returns the password used to authenticate the user. Cannot return <code>null</code>.

View File

@@ -493,7 +493,7 @@ public class JdbcUserDetailsManager extends JdbcDaoImpl implements UserDetailsMa
validateAuthorities(user.getAuthorities());
}
private void validateAuthorities(Collection<GrantedAuthority> authorities) {
private void validateAuthorities(Collection<? extends GrantedAuthority> authorities) {
Assert.notNull(authorities, "Authorities list must not be null");
for (GrantedAuthority authority : authorities) {

View File

@@ -27,7 +27,7 @@ class MutableUser implements MutableUserDetails {
this.password = password;
}
public Collection<GrantedAuthority> getAuthorities() {
public Collection<? extends GrantedAuthority> getAuthorities() {
return delegate.getAuthorities();
}

View File

@@ -46,7 +46,7 @@ public class SecurityExpressionRootTests {
SecurityExpressionRoot root = new SecurityExpressionRoot(JOE) {};
root.setRoleHierarchy(new RoleHierarchy() {
public Collection<GrantedAuthority> getReachableGrantedAuthorities(Collection<GrantedAuthority> authorities) {
public Collection<GrantedAuthority> getReachableGrantedAuthorities(Collection<? extends GrantedAuthority> authorities) {
return AuthorityUtils.createAuthorityList("C");
}
});

View File

@@ -28,7 +28,7 @@ import org.apache.commons.collections.CollectionUtils;
*/
public abstract class HierarchicalRolesTestHelper {
public static boolean containTheSameGrantedAuthorities(Collection<GrantedAuthority> authorities1, Collection<GrantedAuthority> authorities2) {
public static boolean containTheSameGrantedAuthorities(Collection<? extends GrantedAuthority> authorities1, Collection<? extends GrantedAuthority> authorities2) {
if (authorities1 == null && authorities2 == null) {
return true;
}
@@ -39,7 +39,7 @@ public abstract class HierarchicalRolesTestHelper {
return CollectionUtils.isEqualCollection(authorities1, authorities2);
}
public static boolean containTheSameGrantedAuthoritiesCompareByAuthorityString(Collection<GrantedAuthority> authorities1, Collection<GrantedAuthority> authorities2) {
public static boolean containTheSameGrantedAuthoritiesCompareByAuthorityString(Collection<? extends GrantedAuthority> authorities1, Collection<? extends GrantedAuthority> authorities2) {
if (authorities1 == null && authorities2 == null) {
return true;
}
@@ -50,7 +50,7 @@ public abstract class HierarchicalRolesTestHelper {
return CollectionUtils.isEqualCollection(toCollectionOfAuthorityStrings(authorities1), toCollectionOfAuthorityStrings(authorities2));
}
public static List<String> toCollectionOfAuthorityStrings(Collection<GrantedAuthority> authorities) {
public static List<String> toCollectionOfAuthorityStrings(Collection<? extends GrantedAuthority> authorities) {
if (authorities == null) {
return null;
}

View File

@@ -192,7 +192,7 @@ public class JaasAuthenticationProviderTests {
assertNotNull(jaasProvider.getLoginConfig());
assertNotNull(jaasProvider.getLoginContextName());
Collection<GrantedAuthority> list = auth.getAuthorities();
Collection<? extends GrantedAuthority> list = auth.getAuthorities();
assertTrue("GrantedAuthorities should contain ROLE_TEST1", list.contains(new GrantedAuthorityImpl("ROLE_TEST1")));
assertTrue("GrantedAuthorities should contain ROLE_TEST2", list.contains(new GrantedAuthorityImpl("ROLE_TEST2")));

View File

@@ -91,7 +91,7 @@ public class RemoteAuthenticationProviderTests extends TestCase {
this.grantAccess = grantAccess;
}
public Collection<GrantedAuthority> attemptAuthentication(String username, String password)
public Collection<? extends GrantedAuthority> attemptAuthentication(String username, String password)
throws RemoteAuthenticationException {
if (grantAccess) {
return AuthorityUtils.createAuthorityList("foo");